Skip to content

File farrow_core.h

FileList > doppler > farrow > farrow_core.h

Go to the source code of this file

Farrow fractional-delay interpolator — linear / parabolic / cubic. More...

  • #include "doppler/clib_common.h"
  • #include "doppler/jm_perf.h"
  • #include "doppler/dp_state.h"
  • #include "doppler/dp_complex.h"

Classes

Type Name
struct dp_farrow_state_t
Farrow interpolator state (4-tap delay line + order).

Public Types

Type Name
enum farrow__core_8h_1a06fc87d81c62e9abb8790b6e5713c55b
Interpolator order, passed to dp_farrow_create() /farrow_init() .

Public Functions

Type Name
dp_farrow_state_t * dp_farrow_create (int order)
Create a Farrow interpolator.
size_t dp_farrow_delay (dp_farrow_state_t * state, const float _Complex * x, size_t x_len, double mu, float _Complex * out, size_t max_out)
Apply a constant fractional delay of mu samples to a CF32 block.
size_t dp_farrow_delay_max_out (dp_farrow_state_t * state)
Output capacity hint for dp_farrow_delay() .
void dp_farrow_destroy (dp_farrow_state_t * state)
Destroy a Farrow interpolator.
size_t dp_farrow_get_group_delay (const dp_farrow_state_t * state)
Group delay of the interpolator, in samples.
void dp_farrow_get_state (const dp_farrow_state_t * state, void * blob)
Serialize the whole state struct (delay line and order).
void dp_farrow_reset (dp_farrow_state_t * state)
Clear the interpolator delay line; keep the order.
int dp_farrow_set_state (dp_farrow_state_t * state, const void * blob)
Restore the whole state struct (delay line and order) from blob .
size_t dp_farrow_state_bytes (const dp_farrow_state_t * state)
Size in bytes of the blob dp_farrow_get_state() writes.
JM_FORCEINLINE int dp_farrow_state_ok (const dp_farrow_state_t * s)
A Farrow state a blob may carry: one of the three orders.
JM_FORCEINLINE JM_HOT float _Complex farrow_eval (const dp_farrow_state_t * s, float mu)
Interpolate at fractional offset mu ∈[0,1) betweend[1] andd[2] .
JM_FORCEINLINE void farrow_init (dp_farrow_state_t * s, int order)
Initialise in place: set order, clear the delay line.
JM_FORCEINLINE JM_HOT void farrow_push (dp_farrow_state_t * s, float _Complex x)
Push one input sample into the delay line (oldest drops out).

Macros

Type Name
define FARROW_GROUP_DELAY 2u
Group delay in samples, identical for every order.
define FARROW_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('F', 'R', 'R', 'W')
Envelope magic ("FRRW") identifying a Farrow state blob.
define FARROW_STATE_VERSION 1u
Layout version of the Farrow state blob.

Detailed Description

A selectable-order Lagrange interpolator in Farrow (Horner-in-µ) form — the lean alternative to a full polyphase resampler when all you need is a fractional-delay tap for a timing loop. All three orders share one 4-tap delay line and interpolate at the SAME point — between the two middle taps — so the group delay is 2 samples regardless of order, which keeps a driving symbol-timing loop order-agnostic. Push input samples with farrow_push(); evaluate the output at a fractional offset µ ∈ [0,1) with farrow_eval(). The fractional offset is meant to come from an integer timing NCO (the post-wrap accumulator value), so the timing stays drift-free while only the interpolation itself is floating point.

order: 0 = linear (2-tap Lagrange), 1 = parabolic (4-tap symmetric piecewise-parabolic Farrow, α = 0.5), 2 = cubic (4-tap cubic Lagrange). All three are symmetric about the interpolation point, so the phase (delay) response is linear — no timing bias. Linear and cubic are exact for degree 1 and 3 polynomials; the piecewise-parabolic trades exactness for a flatter magnitude response than linear at no delay cost.

Lifecycle: dp_farrow_create -> (push / eval / reset)* -> dp_farrow_destroy, or embed by value with farrow_init().

dp_farrow_state_t f;
farrow_init(&f, FARROW_CUBIC);
for (size_t i = 0; i < n; i++) farrow_push(&f, x[i]);
float _Complex y = farrow_eval(&f, 0.3f);   // x interpolated 0.3 past tap[1]

Public Types Documentation

enum farrow__core_8h_1a06fc87d81c62e9abb8790b6e5713c55b

Interpolator order, passed to dp_farrow_create() /farrow_init() .

enum farrow__core_8h_1a06fc87d81c62e9abb8790b6e5713c55b {
    FARROW_LINEAR = 0,
    FARROW_PARABOLIC = 1,
    FARROW_CUBIC = 2
};


Public Functions Documentation

function dp_farrow_create

Create a Farrow interpolator.

dp_farrow_state_t * dp_farrow_create (
    int order
) 

Parameters:

  • order 0 = linear, 1 = parabolic, 2 = cubic; any other value is refused. Python takes the string "linear", "parabolic" or "cubic" (default "cubic").

Returns:

Heap-allocated state with a zeroed delay line, or NULL on an unknown order or allocation failure.

Note:

Caller must call dp_farrow_destroy() when done.


function dp_farrow_delay

Apply a constant fractional delay of mu samples to a CF32 block.

size_t dp_farrow_delay (
    dp_farrow_state_t * state,
    const float _Complex * x,
    size_t x_len,
    double mu,
    float _Complex * out,
    size_t max_out
) 

Pushes each input sample through the delay line and evaluates the interpolator at the same fixed offset, so the whole block is delayed by a constant, non-integer amount. Output sample i is the input interpolated at i - group_delay + mu, i.e. the stream shifted later by group_delay - mu samples; the first group_delay outputs are the delay-line filling transient and should be discarded. Because the offset is held constant this is the open-loop use of the interpolator — a timing loop instead steers mu per sample via farrow_push()/farrow_eval().

Parameters:

  • state Pointer to a valid dp_farrow_state_t.
  • x CF32 input samples.
  • x_len Number of input samples.
  • mu Fractional delay in samples; the offset in [0,1) into the interpolation interval (values outside extrapolate).
  • out Output buffer; one output per input sample.
  • max_out Capacity of out in samples. Processing stops once it is full: inputs past it are not pushed.

Returns:

Number of samples written to out, min(x_len, max_out); from Python, the CF32 output array (same length as x), each sample delayed by group_delay - mu.

>>> from doppler.resample import Farrow
>>> import numpy as np
>>> f = Farrow(order="cubic")
>>> x = np.arange(8, dtype=np.complex64)   # a ramp: exact interp
>>> y = f.delay(x, 0.5)                  # delay group_delay - 0.5
>>> [round(float(v.real), 4) for v in y]  # first 2 are transient
[0.0, -0.0625, 0.4375, 1.5, 2.5, 3.5, 4.5, 5.5]

function dp_farrow_delay_max_out

Output capacity hint for dp_farrow_delay() .

size_t dp_farrow_delay_max_out (
    dp_farrow_state_t * state
) 

delay() emits exactly one output per input sample, so the caller sizes out to the input length; this returns the "caller sizes it" sentinel.

Parameters:

  • state Unused; may be any value.

Returns:

Always 0.


function dp_farrow_destroy

Destroy a Farrow interpolator.

void dp_farrow_destroy (
    dp_farrow_state_t * state
) 

Parameters:

  • state May be NULL.

function dp_farrow_get_group_delay

Group delay of the interpolator, in samples.

size_t dp_farrow_get_group_delay (
    const dp_farrow_state_t * state
) 

The same for every order, since all three interpolate between the two middle taps.

Parameters:

  • state Unused; may be any value.

Returns:

FARROW_GROUP_DELAY (2).


function dp_farrow_get_state

Serialize the whole state struct (delay line and order).

void dp_farrow_get_state (
    const dp_farrow_state_t * state,
    void * blob
) 

Parameters:


function dp_farrow_reset

Clear the interpolator delay line; keep the order.

void dp_farrow_reset (
    dp_farrow_state_t * state
) 

Zeroes the 4-tap delay line so the next block starts from a filling transient again, exactly as a freshly created interpolator would. The order (linear / parabolic / cubic) is preserved, so the same object can be reused across independent bursts without rebuilding the polynomial. Call it between unrelated signal segments to stop the tail of one leaking into the head of the next.

Parameters:

  • state Must be non-NULL.
>>> from doppler.resample import Farrow
>>> import numpy as np
>>> f = Farrow(order="cubic")
>>> _ = f.delay(np.ones(8, dtype=np.complex64), 0.25)  # leaves state
>>> f.reset()                                 # back to pristine
>>> x = np.arange(8, dtype=np.complex64)
>>> f.delay(x, 0.5)[3:].real.tolist()   # steady part: ramp - 1.5
[1.5, 2.5, 3.5, 4.5, 5.5]

function dp_farrow_set_state

Restore the whole state struct (delay line and order) from blob .

int dp_farrow_set_state (
    dp_farrow_state_t * state,
    const void * blob
) 

The envelope is validated first; on rejection state is unchanged.

Parameters:

Returns:

DP_OK, or DP_ERR_INVALID if the magic, version, endianness or size in the envelope does not match.


function dp_farrow_state_bytes

Size in bytes of the blob dp_farrow_get_state() writes.

size_t dp_farrow_state_bytes (
    const dp_farrow_state_t * state
) 

Parameters:

  • state Must be non-NULL (the size does not depend on it).

Returns:

sizeof(dp_state_hdr_t) + sizeof(dp_farrow_state_t).


function dp_farrow_state_ok

A Farrow state a blob may carry: one of the three orders.

JM_FORCEINLINE int dp_farrow_state_ok (
    const dp_farrow_state_t * s
) 

dp_farrow_create() refuses any other order, so a blob carrying one is forged, not a state (#2142). farrow_eval() would read it as cubic. Every set_state that carries a Farrow, by itself or embedded, refuses it.

Parameters:

  • s Decoded Farrow state. Must be non-NULL.

Returns:

Non-zero when order is FARROW_LINEAR, _PARABOLIC or _CUBIC.


function farrow_eval

Interpolate at fractional offset mu ∈[0,1) betweend[1] andd[2] .

JM_FORCEINLINE  JM_HOT float _Complex farrow_eval (
    const dp_farrow_state_t * s,
    float mu
) 

Horner-in-µ evaluation of the order's Lagrange polynomial. µ = 0 returns d[1] (= input at i - 2); µ → 1 returns d[2].

Parameters:

  • s State. Must be non-NULL.
  • mu Fractional offset in [0,1); values outside extrapolate.

Returns:

The interpolated sample. An order other than linear or parabolic is evaluated as cubic.


function farrow_init

Initialise in place: set order, clear the delay line.

JM_FORCEINLINE void farrow_init (
    dp_farrow_state_t * s,
    int order
) 

Parameters:

  • s State to initialise (e.g. embedded by value). Must be non-NULL.
  • order FARROW_LINEAR, FARROW_PARABOLIC or FARROW_CUBIC. Not refused here (dp_farrow_create() is the checked door): farrow_eval() reads any other value as cubic, so init stores exactly that. The state then carries an order dp_farrow_state_ok() accepts, and a round trip of a stream built from an out-of-range order does not fail on restore.

function farrow_push

Push one input sample into the delay line (oldest drops out).

JM_FORCEINLINE  JM_HOT void farrow_push (
    dp_farrow_state_t * s,
    float _Complex x
) 

Parameters:

  • s State. Must be non-NULL.
  • x New input sample; becomes d[3].

Macro Definition Documentation

define FARROW_GROUP_DELAY

Group delay in samples, identical for every order.

#define FARROW_GROUP_DELAY `2u`

All orders interpolate between tap d[1] and d[2]; d[3] is the newest sample, so the interpolation point (at mu = 0) lags the newest input by FARROW_GROUP_DELAY samples.


define FARROW_STATE_MAGIC

Envelope magic ("FRRW") identifying a Farrow state blob.

#define FARROW_STATE_MAGIC `DP_FOURCC ('F', 'R', 'R', 'W')`


define FARROW_STATE_VERSION

Layout version of the Farrow state blob.

#define FARROW_STATE_VERSION `1u`



The documentation for this class was generated from the following file native/inc/doppler/farrow/farrow_core.h