class sdr.Differentiator(sdr.FIR)

Implements a differentiator FIR filter.

Notes

A discrete-time differentiator is an FIR filter with impulse response

\[h[n] = \frac{(-1)^n}{n} \cdot h_{win}[n], \quad -\frac{N}{2} \le n \le \frac{N}{2} .\]

The truncated impulse response is multiplied by the windowing function \(h_{win}[n]\).

References

  • Michael Rice, Digital Communications: A Discrete Time Approach, Section 3.3.3.

Examples

Create a differentiator FIR filter.

In [1]: fir = sdr.Differentiator()

Differentiate a Gaussian pulse.

In [2]: x = sdr.gaussian(0.3, 5, 10); \
   ...: y = fir(x, "same")
   ...: 

In [3]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.time_domain(x, label="Input"); \
   ...: sdr.plot.time_domain(y, label="Derivative"); \
   ...: plt.title("Discrete-time differentiation of a Gaussian pulse"); \
   ...: plt.tight_layout();
   ...: 
../../_images/sdr_Differentiator_1.png

Differentiate a raised cosine pulse.

In [4]: x = sdr.root_raised_cosine(0.1, 8, 10); \
   ...: y = fir(x, "same")
   ...: 

In [5]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.time_domain(x, label="Input"); \
   ...: sdr.plot.time_domain(y, label="Derivative"); \
   ...: plt.title("Discrete-time differentiation of a raised cosine pulse"); \
   ...: plt.tight_layout();
   ...: 
../../_images/sdr_Differentiator_2.png

Plot the frequency response across filter order.

In [6]: fir_2 = sdr.Differentiator(2); \
   ...: fir_6 = sdr.Differentiator(6); \
   ...: fir_10 = sdr.Differentiator(10); \
   ...: fir_20 = sdr.Differentiator(20); \
   ...: fir_40 = sdr.Differentiator(40); \
   ...: fir_80 = sdr.Differentiator(80)
   ...: 

In [7]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.magnitude_response(fir_2, y_axis="linear", label="N=2"); \
   ...: sdr.plot.magnitude_response(fir_6, y_axis="linear", label="N=6"); \
   ...: sdr.plot.magnitude_response(fir_10, y_axis="linear", label="N=10"); \
   ...: sdr.plot.magnitude_response(fir_20, y_axis="linear", label="N=20"); \
   ...: sdr.plot.magnitude_response(fir_40, y_axis="linear", label="N=40"); \
   ...: sdr.plot.magnitude_response(fir_80, y_axis="linear", label="N=80"); \
   ...: f = np.linspace(0, 0.5, 100); \
   ...: plt.plot(f, np.abs(2 * np.pi * f)**2, color="k", linestyle="--", label="Theory"); \
   ...: plt.legend(); \
   ...: plt.title("Magnitude response of differentiator FIR filters"); \
   ...: plt.tight_layout();
   ...: 
../../_images/sdr_Differentiator_3.png

Constructors

Differentiator(order: int = 20, ...)

Creates a differentiator FIR filter.

Special methods

__call__(x: ArrayLike, ...) → NDArray

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

__len__() → int

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

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[numpy.ndarray[Any, numpy.dtype[numpy.float64]], numpy.ndarray[Any, numpy.dtype[numpy.complex128]]]
frequency_response(freqs: float, ...) → complex
frequency_response(freqs, ...) → ndarray[Any, dtype[complex128]]

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

group_delay(...) → tuple[NDArray, NDArray]

Returns the group delay \(\tau_g(\omega)\) of the FIR filter.

phase_delay(...) → tuple[NDArray, NDArray]

Returns the phase delay \(\tau_{\phi}(\omega)\) of the FIR filter.

Properties

property taps : NDArray

The feedforward taps \(h[n]\) with length \(N + 1\).

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.