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_{i=0}^{M} b_i z^{-i}}{\sum_{j=0}^{N} a_j z^{-j}} .\]

Examples

See the IIR filters example.

Constructors

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

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

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

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

Methods

filter(x: ndarray) ndarray

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

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

Returns the frequency response \(H(e^{j2 \pi f})\) of the IIR filter.

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

Returns the frequency response \(H(e^{j2 \pi f})\) of the IIR filter on a logarithmic frequency axis

impulse_response(N: int = 100) ndarray

Returns the impulse response \(h[n]\) of the IIR filter.

reset()

Streaming-mode only: Resets the filter state.

step_response(N: int = 100) ndarray

Returns the step response \(s[n]\) of the IIR filter.

Plotting

plot_all(sample_rate: float = 1.0, N_time: int = 100, ...)

Plots the zeros and poles, impulse response, step response, and frequency response of the IIR filter in a single figure.

plot_frequency_response(sample_rate: float = 1.0, ...)

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

plot_frequency_response_log(sample_rate: float = 1.0, ...)

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

plot_group_delay(sample_rate: float = 1.0, N: int = 1024)

Plots the group delay \(\tau_g(\omega)\) of the IIR filter.

plot_impulse_response(N: int = 100)

Plots the impulse response \(h[n]\) of the IIR filter.

plot_step_response(N: int = 100)

Plots the step response \(s[n]\) of the IIR filter.

plot_zeros_poles()

Plots the zeros and poles of the IIR filter.

Properties

property a_taps : ndarray

Returns the feedback filter taps, \(a_j\).

property b_taps : ndarray

Returns the feedforward filter taps, \(b_i\).

property gain : float

Returns the gain of the IIR filter.

property order : int

Returns the order of the IIR filter, \(N - 1\).

property poles : ndarray

Returns the poles of the IIR filter.

property streaming : bool

Returns whether the filter is in streaming mode.

property zeros : ndarray

Returns the zeros of the IIR filter.