def design(self, fs, fc, bandwidth, ripple_db=60.0):
"""
Designs a FIR filter that is a low-pass filter.
fs : sampling frequency (Hz)
fc : cut-off frequency (Hz)
bandwidth : transition bandwidth (Hz)s
"""
# Compute the order and Kaiser parameter for the FIR filter.
N, beta = signal.kaiserord(ripple_db, bandwidth / fs * 2)
# Use firwin with a Kaiser window to create a lowpass FIR filter.
fir = signal.firwin(N, fc / fs * 2, window=('kaiser', beta))
# the filter must be symmetric, in order to be zero-phase
assert np.all(np.abs(fir - fir[::-1]) < 1e-15)
self.fir = fir / np.sum(fir)
self.fs = fs
return self
评论列表
文章目录