FIR filter design using the window method.
From the given frequencies freq and corresponding gains gain, this function constructs an FIR filter with linear phase and (approximately) the given frequency response.
Parameters : | numtaps : int
freq : array-like, 1D
gain : array-like
nfreqs : int, optional
window : string or (string, float) or float, or None, optional
nyq : float
antisymmetric : bool
|
---|---|
Returns : | taps : ndarray
|
See also
Notes
From the given set of frequencies and gains, the desired response is constructed in the frequency domain. The inverse FFT is applied to the desired response to create the associated convolution kernel, and the first numtaps coefficients of this kernel, scaled by window, are returned.
The FIR filter will have linear phase. The type of filter is determined by the value of ‘numtaps` and antisymmetric flag. There are four possible combinations:
- odd numtaps, antisymmetric is False, type I filter is produced
- even numtaps, antisymmetric is False, type II filter is produced
- odd numtaps, antisymmetric is True, type III filter is produced
- even numtaps, antisymmetric is True, type IV filter is produced
Magnitude response of all but type I filters are subjects to following constraints:
- type II – zero at the Nyquist frequency
- type III – zero at zero and Nyquist frequencies
- type IV – zero at zero frequency
New in version 0.9.0.
References
[R79] | Oppenheim, A. V. and Schafer, R. W., “Discrete-Time Signal Processing”, Prentice-Hall, Englewood Cliffs, New Jersey (1989). (See, for example, Section 7.4.) |
[R80] | Smith, Steven W., “The Scientist and Engineer’s Guide to Digital Signal Processing”, Ch. 17. http://www.dspguide.com/ch17/1.htm |
Examples
A lowpass FIR filter with a response that is 1 on [0.0, 0.5], and that decreases linearly on [0.5, 1.0] from 1 to 0:
>>> taps = firwin2(150, [0.0, 0.5, 1.0], [1.0, 1.0, 0.0])
>>> print(taps[72:78])
[-0.02286961 -0.06362756 0.57310236 0.57310236 -0.06362756 -0.02286961]