class sdr.Differentiator(sdr.FIR)

Implements a differentiator FIR filter.

Notes

A discrete-time differentiator is a FIR filter with the transfer function

\[H(z) = 1 - z^{-1} .\]

FIR Differentiator Block Diagram
x[n] --+---------------@--> y[n]
       |               ^
       |   +------+    | -1
       +-->| z^-1 |----+
           +------+

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

In [3]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.time_domain(x, label="Input"); \
   ...: sdr.plot.time_domain(y, offset=-fir.delay, 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)
   ...: 

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

Plot the frequency response.

In [6]: plt.figure(figsize=(8, 4)); \
   ...: sdr.plot.magnitude_response(fir);
   ...: 
../../_images/sdr_Differentiator_3.png

Constructors

Differentiator(streaming: bool = False)

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

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.