- class sdr.LeakyIntegrator(sdr.IIR)
Implements a leaky integrator IIR filter.
Notes
A discrete-time leaky integrator is an IIR filter that approximates an FIR moving average. The previous output is remembered with the leaky factor \(\alpha\) and the new input is scaled with \(1 - \alpha\).
The difference equation is
\[y[n] = \alpha \cdot y[n-1] + (1 - \alpha) \cdot x[n] .\]The transfer functions is
\[H(z) = \frac{1 - \alpha}{1 - \alpha z^{-1}} .\]1 - α x[n] ------->@---------------+--> y[n] ^ | α | +------+ | +---| z^-1 |<---+ +------+
Examples
Create an FIR moving average filter and an IIR leaky integrator filter.
In [1]: fir = sdr.MovingAverager(30) In [2]: iir = sdr.LeakyIntegrator(1 - 2 / 30)
Compare the step responses.
In [3]: plt.figure(); \ ...: sdr.plot.step_response(fir, N=100, label="Moving Averager"); \ ...: sdr.plot.step_response(iir, N=100, label="Leaky Integrator"); ...:
Compare the magnitude responses.
In [4]: plt.figure(); \ ...: sdr.plot.magnitude_response(fir, label="Moving Averager"); \ ...: sdr.plot.magnitude_response(iir, label="Leaky Integrator"); \ ...: plt.ylim(-35, 5); ...:
Compare the output of the two filters to a Gaussian random process.
In [5]: x = np.random.randn(1_000) + 2.0; \ ...: y_fir = fir(x); \ ...: y_iir = iir(x) ...: In [6]: plt.figure(); \ ...: sdr.plot.time_domain(y_fir, label="Moving Averager"); \ ...: sdr.plot.time_domain(y_iir, label="Leaky Integrator"); ...:
Constructors¶
-
LeakyIntegrator(alpha: float, streaming: bool =
False
) Creates a leaky integrator IIR filter.
- classmethod ZerosPoles(zeros: ArrayLike, poles, ...) Self
Creates an IIR filter from its zeros, poles, and gain.
Special methods¶
Streaming mode only¶
- reset()
Resets the filter state. Only useful when using 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.
-
step_response(N: int =
100
) NDArray Returns the step response \(s[n]\) of the IIR filter.
- frequency_response(...) tuple[ndarray[Any, dtype[float64]], ndarray[Any, dtype[complex128]]]
- frequency_response(freqs, ...) complex
- frequency_response(freqs, ...) ndarray[Any, dtype[complex128]]
Returns the frequency response \(H(\omega)\) of the IIR filter.
-
noise_bandwidth(sample_rate: float =
1.0
) float Returns the noise bandwidth \(B_n\) of the IIR filter.
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 zeros : NDArray
The zeros of the IIR filter.
- property poles : NDArray
The poles of the IIR filter.
-
LeakyIntegrator(alpha: float, streaming: bool =