class sdr.Integrator(sdr.IIR)

Implements an integrator IIR filter.

Notes

A discrete-time integrator is an IIR filter that continuously accumulates the input signal. Accordingly, it has infinite gain at DC.

The backward integrator is defined by:

\[y[n] = y[n-1] + x[n-1]\]
\[H(z) = \frac{z^{-1}}{1 - z^{-1}}\]

The trapezoidal integrator is defined by:

\[y[n] = y[n-1] + \frac{1}{2}x[n] + \frac{1}{2}x[n-1]\]
\[H(z) = \frac{1}{2} \frac{1 + z^{-1}}{1 - z^{-1}}\]

The forward integrator is defined by:

\[y[n] = y[n-1] + x[n]\]
\[H(z) = \frac{1}{1 - z^{-1}}\]

Examples

Create integrating IIR filters.

In [1]: iir_back = sdr.Integrator("backward"); \
   ...: iir_trap = sdr.Integrator("trapezoidal"); \
   ...: iir_forw = sdr.Integrator("forward")
   ...: 

Integrate a Gaussian pulse.

In [2]: x = sdr.gaussian(0.3, 5, 10); \
   ...: y_back = iir_back(x); \
   ...: y_trap = iir_trap(x); \
   ...: y_forw = iir_forw(x)
   ...: 

In [3]: plt.figure(); \
   ...: sdr.plot.time_domain(x, label="Input"); \
   ...: sdr.plot.time_domain(y_back, label="Integral (backward)"); \
   ...: sdr.plot.time_domain(y_trap, label="Integral (trapezoidal)"); \
   ...: sdr.plot.time_domain(y_forw, label="Integral (forward)"); \
   ...: plt.title("Discrete-time integration of a Gaussian pulse");
   ...: 
../../_images/sdr_Integrator_1.png

Integrate a raised cosine pulse.

In [4]: x = sdr.root_raised_cosine(0.1, 8, 10); \
   ...: y_back = iir_back(x); \
   ...: y_trap = iir_trap(x); \
   ...: y_forw = iir_forw(x)
   ...: 

In [5]: plt.figure(); \
   ...: sdr.plot.time_domain(x, label="Input"); \
   ...: sdr.plot.time_domain(y_back, label="Integral (backward)"); \
   ...: sdr.plot.time_domain(y_trap, label="Integral (trapezoidal)"); \
   ...: sdr.plot.time_domain(y_forw, label="Integral (forward)"); \
   ...: plt.title("Discrete-time integration of a raised cosine pulse");
   ...: 
../../_images/sdr_Integrator_2.png

Plot the frequency responses and compare them to theory.

In [6]: f = np.linspace(0, 0.5, 100)

In [7]: H_theory = 1/(2 * np.pi * f)
In [8]: plt.figure(); \
   ...: sdr.plot.magnitude_response(iir_back, label="Backward"); \
   ...: sdr.plot.magnitude_response(iir_trap, label="Trapezoidal"); \
   ...: sdr.plot.magnitude_response(iir_forw, label="Forward"); \
   ...: plt.plot(f, sdr.db(np.abs(H_theory)**2), color="k", linestyle="--", label="Theory"); \
   ...: plt.legend(); \
   ...: plt.title("Magnitude response of integrating IIR filters");
   ...: 
../../_images/sdr_Integrator_3.png

Constructors

Integrator(...)

Creates an integrating IIR filter.

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.

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.

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 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.