class sdr.FractionalDelay(sdr.FIR)

Implements a fractional delay FIR filter.

Examples

Design \(\Delta n = 0.21719\) delay filters with various lengths. Examine the width and flatness of the frequency response passband.

In [1]: plt.figure(figsize=(8, 4));

In [2]: for length in [4, 8, 16, 32, 64, 128]:
   ...:     fir = sdr.FractionalDelay(length, 0.21719)
   ...:     sdr.plot.magnitude_response(fir, label=f"$L = {length}$")
   ...: 

In [3]: plt.legend(loc="lower left");
../../_images/sdr_FractionalDelay_1.png

Design filters with length \(L = 8\) and various fractional delays. Examine the effects on the magnitude response outside the passband as a function of the fractional delay. Note the symmetry about \(\Delta n = 0.5\) and that the out-of-band magnitude response is worst at \(\Delta n = 0.5\).

In [4]: plt.figure(figsize=(8, 4));

In [5]: for delay in np.arange(0.1, 1, 0.1):
   ...:     fir = sdr.FractionalDelay(8, delay)
   ...:     sdr.plot.magnitude_response(fir, label=f"$\Delta n = {delay:0.1f}$")
   ...: 

In [6]: plt.ylim(-10, 1); \
   ...: plt.legend(loc="lower left");
   ...: 
../../_images/sdr_FractionalDelay_2.png

Examine the effects on the group delay outside the passband as a function of the fractional delay. Note the symmetry about \(\Delta n = 0.5\). The out-of-band group delay is worst around \(\Delta n \approx 0.5\), however the group delay is perfectly flat at exactly \(\Delta n = 0.5\).

In [7]: plt.figure(figsize=(8, 4));

In [8]: for delay in np.arange(0.1, 1, 0.1):
   ...:     fir = sdr.FractionalDelay(8, delay)
   ...:     sdr.plot.group_delay(fir, label=f"$\Delta n = {delay:0.1f}$")
   ...: 

In [9]: plt.legend(loc="lower left");
../../_images/sdr_FractionalDelay_3.png

Constructors

FractionalDelay(length: int, delay: float)

Creates a fractional delay 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.