class sdr.IIR

Implements an infinite impulse response (IIR) filter.

This class is a wrapper for the scipy.signal.lfilter() function. It supports one-time filtering and streamed filtering.

Notes

An IIR filter is defined by its feedforward coefficients \(b_i\) and feedback coefficients \(a_j\). These coefficients define the difference equation

\[y[n] = \frac{1}{a_0} \left( \sum_{i=0}^{M} b_i x[n-i] - \sum_{j=1}^{N} a_j y[n-j] \right) .\]

The transfer function of the filter is

\[H(z) = \frac{\sum\limits_{i=0}^{M} b_i z^{-i}}{\sum\limits_{j=0}^{N} a_j z^{-j}} .\]

Examples

See the IIR filters example.

Constructors

IIR(b: ArrayLike, a: ArrayLike, streaming: bool = False)

Creates an IIR filter with feedforward coefficients \(b_i\) and feedback coefficients \(a_j\).

classmethod ZerosPoles(zeros: ArrayLike, poles, ...) Self

Creates an IIR filter from its zeros, poles, and gain.

Special methods

__call__(x: ArrayLike) NDArray

Filters the input signal \(x[n]\) with the IIR filter.

String representation

__repr__() str

Returns a code-styled string representation of the object.

__str__() str

Returns a human-readable string representation of the object.

Streaming mode only

reset()

Resets the filter state. Only useful when using streaming mode.

property streaming : bool

Indicates whether the filter is in streaming mode.

property state : NDArray

The filter state.

Methods

impulse_response(N: int = 100) NDArray

Returns the impulse response \(h[n]\) of the IIR filter. The impulse response \(h[n]\) is the filter output when the input is an impulse \(\delta[n]\).

step_response(N: int = 100) NDArray

Returns the step response \(s[n]\) of the IIR filter. The step response \(s[n]\) is the filter output when the input is a unit step \(u[n]\).

frequency_response(...) tuple[NDArray, NDArray]

Returns the frequency response \(H(\omega)\) of the IIR filter.

frequency_response_log(...) tuple[NDArray, NDArray]

Returns the frequency response \(H(\omega)\) of the IIR filter on a logarithmic frequency axis.

Properties

property b_taps : NDArray

The feedforward taps \(b_i\) for \(i = 0,...,M\).

property a_taps : NDArray

The feedback taps \(a_j\) for \(j = 0,...,N\).

property order : int

The order of the IIR filter \(N\).

property zeros : NDArray

The zeros of the IIR filter.

property poles : NDArray

The poles of the IIR filter.

property gain : float

The gain of the IIR filter.