scipy 1.8.0 Pypi GitHub Homepage
Other Docs
ParametersRaisesReturnsBackRef
firwin(numtaps, cutoff, width=None, window='hamming', pass_zero=True, scale=True, nyq=None, fs=None)

This function computes the coefficients of a finite impulse response filter. The filter will have linear phase; it will be Type I if :None:None:`numtaps` is odd and Type II if :None:None:`numtaps` is even.

Type II filters always have zero response at the Nyquist frequency, so a ValueError exception is raised if firwin is called with :None:None:`numtaps` even and having a passband whose right end is at the Nyquist frequency.

Parameters

numtaps : int

Length of the filter (number of coefficients, i.e. the filter order + 1). :None:None:`numtaps` must be odd if a passband includes the Nyquist frequency.

cutoff : float or 1-D array_like

Cutoff frequency of filter (expressed in the same units as :None:None:`fs`) OR an array of cutoff frequencies (that is, band edges). In the latter case, the frequencies in :None:None:`cutoff` should be positive and monotonically increasing between 0 and :None:None:`fs/2`. The values 0 and :None:None:`fs/2` must not be included in :None:None:`cutoff`.

width : float or None, optional

If :None:None:`width` is not None, then assume it is the approximate width of the transition region (expressed in the same units as :None:None:`fs`) for use in Kaiser FIR filter design. In this case, the :None:None:`window` argument is ignored.

window : string or tuple of string and parameter values, optional

Desired window to use. See scipy.signal.get_window for a list of windows and required parameters.

pass_zero : {True, False, 'bandpass', 'lowpass', 'highpass', 'bandstop'}, optional

If True, the gain at the frequency 0 (i.e., the "DC gain") is 1. If False, the DC gain is 0. Can also be a string argument for the desired filter type (equivalent to btype in IIR design functions).

versionadded

Support for string arguments.

scale : bool, optional

Set to True to scale the coefficients so that the frequency response is exactly unity at a certain frequency. That frequency is either:

  • 0 (DC) if the first passband starts at 0 (i.e. pass_zero is True)

  • :None:None:`fs/2` (the Nyquist frequency) if the first passband ends at :None:None:`fs/2` (i.e the filter is a single band highpass filter); center of first passband otherwise

nyq : float, optional

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

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.

Raises

ValueError

If any value in :None:None:`cutoff` is less than or equal to 0 or greater than or equal to fs/2 , if the values in :None:None:`cutoff` are not strictly monotonically increasing, or if :None:None:`numtaps` is even but a passband includes the Nyquist frequency.

Returns

h : (numtaps,) ndarray

Coefficients of length :None:None:`numtaps` FIR filter.

FIR filter design using the window method.

See Also

firls
firwin2
minimum_phase
remez

Examples

Low-pass from 0 to f:

>>> from scipy import signal
... numtaps = 3
... f = 0.1
... signal.firwin(numtaps, f) array([ 0.06799017, 0.86401967, 0.06799017])

Use a specific window function:

>>> signal.firwin(numtaps, f, window='nuttall')
array([  3.56607041e-04,   9.99286786e-01,   3.56607041e-04])

High-pass ('stop' from 0 to f):

>>> signal.firwin(numtaps, f, pass_zero=False)
array([-0.00859313,  0.98281375, -0.00859313])

Band-pass:

>>> f1, f2 = 0.1, 0.2
... signal.firwin(numtaps, [f1, f2], pass_zero=False) array([ 0.06301614, 0.88770441, 0.06301614])

Band-stop:

>>> signal.firwin(numtaps, [f1, f2])
array([-0.00801395,  1.0160279 , -0.00801395])

Multi-band (passbands are [0, f1], [f2, f3] and [f4, 1]):

>>> f3, f4 = 0.3, 0.4
... signal.firwin(numtaps, [f1, f2, f3, f4]) array([-0.01376344, 1.02752689, -0.01376344])

Multi-band (passbands are [f1, f2] and [f3,f4]):

>>> signal.firwin(numtaps, [f1, f2, f3, f4], pass_zero=False)
array([ 0.04890915,  0.91284326,  0.04890915])
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.resample_poly scipy.signal._fir_filter_design.firls scipy.signal._fir_filter_design.kaiserord scipy.signal._filter_design.gammatone scipy.signal._filter_design.freqz scipy.signal._signaltools.oaconvolve

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#262
type: <class 'function'>
Commit: