class sdr.FarrowResampler

Implements a piecewise polynomial Farrow arbitrary resampler.

References

Examples

Create a sine wave with angular frequency \(\omega = 2 \pi / 5.179\). Interpolate the signal by \(r = \pi\) using Farrow piecewise polynomial Farrow resamplers.

In [1]: x = np.cos(2 * np.pi / 5.179 * np.arange(11))

In [2]: rate = np.pi

Create a linear Farrow piecewise polynomial interpolator.

In [3]: farrow1 = sdr.FarrowResampler(1)

In [4]: y1 = farrow1(x, rate)

In [5]: plt.figure(); \
   ...: sdr.plot.time_domain(x, sample_rate=1, marker="o", label="Input"); \
   ...: sdr.plot.time_domain(y1, sample_rate=rate, marker=".", label="Output"); \
   ...: plt.title("Linear Farrow Resampler");
   ...: 
../../_images/sdr_FarrowResampler_1.png

Create a quadratic Farrow piecewise polynomial interpolator.

In [6]: farrow2 = sdr.FarrowResampler(2)

In [7]: y2 = farrow2(x, rate)

In [8]: plt.figure(); \
   ...: sdr.plot.time_domain(x, sample_rate=1, marker="o", label="Input"); \
   ...: sdr.plot.time_domain(y2, sample_rate=rate, marker=".", label="Output"); \
   ...: plt.title("Quadratic Farrow Resampler");
   ...: 
../../_images/sdr_FarrowResampler_2.png

Create a cubic Farrow piecewise polynomial interpolator.

In [9]: farrow3 = sdr.FarrowResampler(3)

In [10]: y3 = farrow3(x, rate)

In [11]: plt.figure(); \
   ....: sdr.plot.time_domain(x, sample_rate=1, marker="o", label="Input"); \
   ....: sdr.plot.time_domain(y3, sample_rate=rate, marker=".", label="Output"); \
   ....: plt.title("Cubic Farrow Resampler");
   ....: 
../../_images/sdr_FarrowResampler_3.png

Create a quartic Farrow piecewise polynomial interpolator.

In [12]: farrow4 = sdr.FarrowResampler(4)

In [13]: y4 = farrow4(x, rate)

In [14]: plt.figure(); \
   ....: sdr.plot.time_domain(x, sample_rate=1, marker="o", label="Input"); \
   ....: sdr.plot.time_domain(y4, sample_rate=rate, marker=".", label="Output"); \
   ....: plt.title("Quartic Farrow Resampler");
   ....: 
../../_images/sdr_FarrowResampler_4.png

Compare the outputs of the Farrow resamplers with varying polynomial order.

In [15]: plt.figure(); \
   ....: sdr.plot.time_domain(x, sample_rate=1, marker="o", label="Input"); \
   ....: sdr.plot.time_domain(y1, sample_rate=rate, marker=".", label="Linear"); \
   ....: sdr.plot.time_domain(y2, sample_rate=rate, marker=".", label="Quadratic"); \
   ....: sdr.plot.time_domain(y3, sample_rate=rate, marker=".", label="Cubic"); \
   ....: sdr.plot.time_domain(y4, sample_rate=rate, marker=".", label="Quartic"); \
   ....: plt.xlim(1.5, 3.5); \
   ....: plt.ylim(-1.0, -0.2); \
   ....: plt.title("Comparison of Farrow Resamplers");
   ....: 
../../_images/sdr_FarrowResampler_5.png

Run a Farrow resampler with quartic polynomial order in streaming mode.

In [16]: x = np.cos(2 * np.pi / 5.179 * np.arange(40))

In [17]: farrow4 = sdr.FarrowResampler(4, streaming=True)

In [18]: y1 = farrow4(x[0:10], rate); \
   ....: y2 = farrow4(x[10:20], rate); \
   ....: y3 = farrow4(x[20:30], rate); \
   ....: y4 = farrow4(x[30:40], rate); \
   ....: y5 = farrow4.flush(rate); \
   ....: y = np.concatenate((y1, y2, y3, y4, y5))
   ....: 

In [19]: plt.figure(); \
   ....: sdr.plot.time_domain(x, sample_rate=1, marker="o", label="Input"); \
   ....: sdr.plot.time_domain(y, sample_rate=rate, offset=-farrow4.delay, marker=".", label="Quartic concatenated"); \
   ....: plt.title("Quartic Farrow Resampler Concatenated Outputs");
   ....: 
../../_images/sdr_FarrowResampler_6.png

See the Farrow arbitrary resampler example.

Constructors

FarrowResampler(order: int = 3, streaming: bool = False)

Creates a new Farrow arbitrary resampler.

Special methods

__call__(x: ArrayLike, rate: float) NDArray

Resamples the input signal \(x[n]\) by the given arbitrary rate \(r\).

Streaming mode only

reset(state: ArrayLike | None = None)

Resets the filter state and fractional sample index.

flush(rate: float) 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.

Properties

property order : int

The order of the piecewise polynomial.

property taps : NDArray

The Farrow filter taps.

property delay : int

The delay \(d\) of the Farrow FIR filters in samples.