class sdr.FIR

Implements a finite impulse response (FIR) filter.

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

Notes

A FIR filter is defined by its feedforward coefficients \(h_i\).

\[y[n] = \sum_{i=0}^{N} h_i x[n-i] .\]

The transfer function of the filter is

\[H(z) = \sum\limits_{i=0}^{N} h_i z^{-i} .\]

Examples

See the FIR filters example.

Constructors

FIR(h: ArrayLike, streaming: bool = False)

Creates a FIR filter with feedforward coefficients \(h_i\).

Special methods

__call__(x: ArrayLike, ...) NDArray

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

__len__() int

Returns the filter length \(N + 1\).

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.

flush() NDArray

Flushes the filter state by passing zeros through the filter. Only useful when using streaming mode.

property streaming : bool

Indicates whether the filter is in streaming mode.

property state : NDArray

The filter state consisting of the previous \(N\) inputs.

Methods

impulse_response(N: int | None = None) NDArray

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

step_response(N: int | None = None) NDArray

Returns the step response \(s[n]\) of the FIR 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 FIR filter.

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

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

Properties

property taps : NDArray

The feedforward taps \(h_i\) for \(i = 0,...,N\).

property order : int

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

property delay : int

The delay of the FIR filter \(d = \lfloor \frac{N + 1}{2} \rfloor\) in samples.