scipy 1.8.0 Pypi GitHub Homepage
Other Docs
NotesParametersReturnsBackRef
firwin2(numtaps, freq, gain, nfreqs=None, window='hamming', nyq=None, antisymmetric=False, fs=None)

From the given frequencies :None:None:`freq` and corresponding gains :None:None:`gain`, this function constructs an FIR filter with linear phase and (approximately) the given frequency response.

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 :None:None:`numtaps` coefficients of this kernel, scaled by :None:None:`window`, are returned.

The FIR filter will have linear phase. The type of filter is determined by the value of 'numtaps` and :None:None:`antisymmetric` flag. There are four possible combinations:

Magnitude response of all but type I filters are subjects to following constraints:

versionadded

Parameters

numtaps : int

The number of taps in the FIR filter. :None:None:`numtaps` must be less than :None:None:`nfreqs`.

freq : array_like, 1-D

The frequency sampling points. Typically 0.0 to 1.0 with 1.0 being Nyquist. The Nyquist frequency is half :None:None:`fs`. The values in :None:None:`freq` must be nondecreasing. A value can be repeated once to implement a discontinuity. The first value in :None:None:`freq` must be 0, and the last value must be fs/2 . Values 0 and fs/2 must not be repeated.

gain : array_like

The filter gains at the frequency sampling points. Certain constraints to gain values, depending on the filter type, are applied, see Notes for details.

nfreqs : int, optional

The size of the interpolation mesh used to construct the filter. For most efficient behavior, this should be a power of 2 plus 1 (e.g, 129, 257, etc). The default is one more than the smallest power of 2 that is not less than :None:None:`numtaps`. :None:None:`nfreqs` must be greater than :None:None:`numtaps`.

window : string or (string, float) or float, or None, optional

Window function to use. Default is "hamming". See scipy.signal.get_window for the complete list of possible values. If None, no window function is applied.

nyq : float, optional

Deprecated. Use `fs` instead. This is the Nyquist frequency. Each frequency in :None:None:`freq` must be between 0 and :None:None:`nyq`. Default is 1.

antisymmetric : bool, optional

Whether resulting impulse response is symmetric/antisymmetric. See Notes for more details.

fs : float, optional

The sampling frequency of the signal. Each frequency in :None:None:`cutoff` must be between 0 and fs/2 . Default is 2.

Returns

taps : ndarray

The filter coefficients of the FIR filter, as a 1-D array of length :None:None:`numtaps`.

FIR filter design using the window method.

See Also

firls
firwin
minimum_phase
remez

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:

>>> from scipy import signal
... taps = signal.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]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

scipy.signal._fir_filter_design.firwin scipy.signal._fir_filter_design.firwin2 scipy.signal._fir_filter_design.remez scipy.signal._fir_filter_design.minimum_phase scipy.signal._signaltools._freq_domain_conv scipy.signal._signaltools.fftconvolve scipy.signal._signaltools.choose_conv_method scipy.signal._fir_filter_design.firls scipy.signal._signaltools.convolve scipy.signal._signaltools.correlate2d scipy.signal._signaltools.convolve2d scipy.signal._fir_filter_design.kaiserord scipy.signal._signaltools.oaconvolve scipy.signal._signaltools.correlate

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /scipy/signal/_fir_filter_design.py#487
type: <class 'function'>
Commit: