bundles / scipy latest / scipy / signal / _filter_design / iirfilter
function
scipy.signal._filter_design:iirfilter
Signature
def iirfilter ( N , Wn , rp = None , rs = None , btype = band , analog = False , ftype = butter , output = ba , fs = None ) Summary
IIR digital and analog filter design given order and critical points.
Extended Summary
Design an Nth-order digital or analog filter and return the filter coefficients.
Parameters
N: intThe order of the filter.
Wn: array_likeA scalar or length-2 sequence giving the critical frequencies.
For digital filters,
Wnare in the same units asfs. By default,fsis 2 half-cycles/sample, so these are normalized from 0 to 1, where 1 is the Nyquist frequency. (Wnis thus in half-cycles / sample.)For analog filters,
Wnis an angular frequency (e.g., rad/s).When Wn is a length-2 sequence,
Wn[0]must be less thanWn[1].rp: float, optionalFor Chebyshev and elliptic filters, provides the maximum ripple in the passband. (dB)
rs: float, optionalFor Chebyshev and elliptic filters, provides the minimum attenuation in the stop band. (dB)
btype: {'bandpass', 'lowpass', 'highpass', 'bandstop'}, optionalThe type of filter. Default is 'bandpass'.
analog: bool, optionalWhen True, return an analog filter, otherwise a digital filter is returned.
ftype: str, optionalThe type of IIR filter to design:
Butterworth'butter'
Chebyshev I'cheby1'
Chebyshev II'cheby2'
Cauer/elliptic: 'ellip'
Bessel/Thomson: 'bessel'
output: {'ba', 'zpk', 'sos'}, optionalFilter form of the output:
second-order sections (recommended): 'sos'
numerator/denominator (default)'ba'
pole-zero'zpk'
In general the second-order sections ('sos') form is recommended because inferring the coefficients for the numerator/denominator form ('ba') suffers from numerical instabilities. For reasons of backward compatibility the default form is the numerator/denominator form ('ba'), where the 'b' and the 'a' in 'ba' refer to the commonly used names of the coefficients used.
Note: Using the second-order sections form ('sos') is sometimes associated with additional computational costs: for data-intense use cases it is therefore recommended to also investigate the numerator/denominator form ('ba').
fs: float, optionalThe sampling frequency of the digital system.
Returns
b, a: ndarray, ndarrayNumerator (b) and denominator (a) polynomials of the IIR filter. Only returned if
output='ba'.z, p, k: ndarray, ndarray, floatZeros, poles, and system gain of the IIR filter transfer function. Only returned if
output='zpk'.sos: ndarraySecond-order sections representation of the IIR filter. Only returned if
output='sos'.
Notes
The 'sos' output parameter was added in 0.16.0.
The current behavior is for ndarray outputs to have 64 bit precision (float64 or complex128) regardless of the dtype of Wn but outputs may respect the dtype of Wn in a future version.
Array API Standard Support
iirfilter has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ⚠️ no JIT ⛔ Dask ⚠️ computes graph n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
Examples
Generate a 17th-order Chebyshev II analog bandpass filter from 50 Hz to 200 Hz and plot the frequency response:import numpy as np from scipy import signal import matplotlib.pyplot as plt✓
b, a = signal.iirfilter(17, [2*np.pi*50, 2*np.pi*200], rs=60, btype='band', analog=True, ftype='cheby2') w, h = signal.freqs(b, a, 1000) fig = plt.figure() ax = fig.add_subplot(1, 1, 1)✓
ax.semilogx(w / (2*np.pi), 20 * np.log10(np.maximum(abs(h), 1e-5))) ax.set_title('Chebyshev Type II bandpass frequency response') ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Amplitude [dB]') ax.axis((10, 1000, -100, 10))✗
ax.grid(which='both', axis='both') plt.show()✓

sos = signal.iirfilter(17, [50, 200], rs=60, btype='band', analog=False, ftype='cheby2', fs=2000, output='sos') w, h = signal.freqz_sos(sos, 2000, fs=2000) fig = plt.figure() ax = fig.add_subplot(1, 1, 1)✓
ax.semilogx(w, 20 * np.log10(np.maximum(abs(h), 1e-5))) ax.set_title('Chebyshev Type II bandpass frequency response') ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Amplitude [dB]') ax.axis((10, 1000, -100, 10))✗
ax.grid(which='both', axis='both') plt.show()✓

See also
Aliases
-
scipy.signal.iirfilter