class sdr.Differentiator(sdr.FIR)

Implements a differentiator FIR filter.

Notes

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

h[n]=(1)nnhwin[n],N2nN2.

The truncated impulse response is multiplied by the windowing function hwin[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(); \
   ...: sdr.plot.time_domain(x, label="Input"); \
   ...: sdr.plot.time_domain(y, label="Derivative"); \
   ...: plt.title("Discrete-time differentiation of a Gaussian pulse");
   ...: 
../../_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(); \
   ...: sdr.plot.time_domain(x, label="Input"); \
   ...: sdr.plot.time_domain(y, label="Derivative"); \
   ...: plt.title("Discrete-time differentiation of a raised cosine pulse");
   ...: 
../../_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(); \
   ...: 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");
   ...: 
../../_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.

step_response(n: int | None = None) NDArray

Returns the step response s[n] of the FIR filter.

frequency_response(...) tuple[ndarray[tuple[int, ...], dtype[float64]], ndarray[tuple[int, ...], dtype[complex128]]]
frequency_response(freqs: float, ...) complex
frequency_response(...) ndarray[tuple[int, ...], dtype[complex128]]

Returns the frequency response H(ω) of the FIR filter.

group_delay(...) tuple[TypeAliasForwardRef('~numpy.typing.NDArray'), TypeAliasForwardRef('~numpy.typing.NDArray')]

Returns the group delay τg(ω) of the FIR filter.

phase_delay(...) tuple[TypeAliasForwardRef('~numpy.typing.NDArray'), TypeAliasForwardRef('~numpy.typing.NDArray')]

Returns the phase delay τϕ(ω) of the FIR filter.

noise_bandwidth(sample_rate: float = 1.0) float

Returns the noise bandwidth Bn 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=N+12 in samples.