Skip to content

File Resampler_core.h

FileList > inc > Resampler > Resampler_core.h

Go to the source code of this file

Continuously-variable polyphase resampler, CF32 IQ. More...

  • #include "resamp/resamp_core.h"

Public Types

Type Name
typedef resamp_state_t Resampler_state_t

Public Functions

Type Name
Resampler_state_t * Resampler_create (double rate)
Create a Resampler with the built-in 4096×19 Kaiser bank. The bank provides ~60 dB alias rejection with 0.4/0.6 pass/stop normalised cutoffs. Pass rate >= 1.0 to interpolate (upsample); pass rate < 1.0 to decimate (downsample). For a custom bank use Resampler_create_custom() instead.
Resampler_state_t * Resampler_create_custom (size_t num_phases, size_t num_taps, const float * bank, double rate)
Create a Resampler with a user-supplied polyphase bank.
void Resampler_destroy (Resampler_state_t * state)
size_t Resampler_execute (Resampler_state_t * state, const float complex * x, size_t x_len, float complex * out)
Resample a block of CF32 samples at the fixed base rate. Uses the dual-mode polyphase engine: output-driven for rate >= 1 (interpolation), input-driven transposed-form for rate < 1 (decimation). State carries over between calls, so contiguous blocks produce the same result as one large block.
size_t Resampler_execute_ctrl (Resampler_state_t * state, const float complex * x, size_t x_len, const float complex * ctrl, size_t ctrl_len, float complex * out)
Resample with per-sample additive rate deviations. Effective rate for sample i is base_rate + real( ctrl[i] ). Uses a unified double-precision accumulator that handles both interpolation and decimation in a single code path — suitable for Doppler-shift simulation and fractional-sample timing correction. ctrl and x must have the same length.
size_t Resampler_execute_ctrl_max_out (Resampler_state_t * state)
size_t Resampler_execute_max_out (Resampler_state_t * state)
size_t Resampler_get_num_phases (const Resampler_state_t * state)
Number of polyphase branches in the filter bank. Always a power of two. The built-in bank has 4096 phases giving sub-sample timing resolution of 1/4096 of an input sample period.
size_t Resampler_get_num_taps (const Resampler_state_t * state)
Taps per polyphase branch. Total prototype filter length is num_phases * num_taps - 1. The built-in bank uses 19 taps per branch.
double Resampler_get_rate (const Resampler_state_t * state)
Get / set the output-to-input sample rate ratio. The setter recomputes the phase increment immediately; the delay line and phase accumulator are preserved so in-stream rate changes are glitch-free. Switching sign of (rate - 1) (i.e. crossing the boundary between interp and decim modes) requires a fresh create().
void Resampler_get_state (const Resampler_state_t * state, void * blob)
Serialize the resampler's phase + delay-line state into blob .
void Resampler_reset (Resampler_state_t * state)
Zero the delay line and phase accumulator. Rate and polyphase bank are preserved so the resampler can be resumed at the same ratio. Zeroing state eliminates transient artefacts when starting a new signal burst.
void Resampler_set_rate (Resampler_state_t * state, double rate)
int Resampler_set_state (Resampler_state_t * state, const void * blob)
Restore state from blob ; DP_OK, or DP_ERR_INVALID if rejected.
size_t Resampler_state_bytes (const Resampler_state_t * state)
Serialized-state byte size (forwarded to the resamp leaf).

Macros

Type Name
define RESAMPLER_MAX_OUT 65536

Detailed Description

Thin adapter over resamp_core (resamp_state_t). Exposes a Resampler-prefixed API so the generated ext.c compiles without changes.

Lifecycle:

Resampler_state_t *r = Resampler_create(0.5);
float complex out[4096];
size_t n = Resampler_execute(r, in, 1024, out);
Resampler_destroy(r);

Output buffer sizing: execute: allocate Resampler_execute_max_out() samples. execute_ctrl: same.

Public Types Documentation

typedef Resampler_state_t

typedef resamp_state_t Resampler_state_t;

Public Functions Documentation

function Resampler_create

Create a Resampler with the built-in 4096×19 Kaiser bank. The bank provides ~60 dB alias rejection with 0.4/0.6 pass/stop normalised cutoffs. Pass rate >= 1.0 to interpolate (upsample); pass rate < 1.0 to decimate (downsample). For a custom bank use Resampler_create_custom() instead.

Resampler_state_t * Resampler_create (
    double rate
) 

Parameters:

  • rate Output-to-input sample rate ratio (any positive float). Values >= 1.0 interpolate; values < 1.0 decimate.

Returns:

Non-NULL on success, NULL on OOM.

>>> from doppler.resample import Resampler
>>> import numpy as np
>>> r = Resampler(rate=2.0)
>>> r.num_phases, r.num_taps
(4096, 19)
>>> r.rate
2.0

function Resampler_create_custom

Create a Resampler with a user-supplied polyphase bank.

Resampler_state_t * Resampler_create_custom (
    size_t num_phases,
    size_t num_taps,
    const float * bank,
    double rate
) 

Parameters:

  • num_phases Number of polyphase branches (must be power of two).
  • num_taps Taps per branch.
  • bank Row-major float32 array, shape num_phases × num_taps.
  • rate Initial resample ratio.

Returns:

Non-NULL on success, NULL on invalid args or OOM.


function Resampler_destroy

void Resampler_destroy (
    Resampler_state_t * state
) 

Free all resources. NULL is a no-op.


function Resampler_execute

Resample a block of CF32 samples at the fixed base rate. Uses the dual-mode polyphase engine: output-driven for rate >= 1 (interpolation), input-driven transposed-form for rate < 1 (decimation). State carries over between calls, so contiguous blocks produce the same result as one large block.

size_t Resampler_execute (
    Resampler_state_t * state,
    const float complex * x,
    size_t x_len,
    float complex * out
) 

Parameters:

  • state Pointer to a valid Resampler_state_t.
  • x CF32 input samples.
  • x_len Number of input samples.
  • out Output buffer; must hold at least RESAMPLER_MAX_OUT samples.

Returns:

CF32 output array; length is approximately x_len * rate.

>>> from doppler.resample import Resampler
>>> import numpy as np
>>> r = Resampler(rate=2.0)
>>> y = r.execute(np.zeros(128, dtype=np.complex64))
>>> y.shape, y.dtype
((256,), dtype('complex64'))

function Resampler_execute_ctrl

Resample with per-sample additive rate deviations. Effective rate for sample i is base_rate + real( ctrl[i] ). Uses a unified double-precision accumulator that handles both interpolation and decimation in a single code path — suitable for Doppler-shift simulation and fractional-sample timing correction. ctrl and x must have the same length.

size_t Resampler_execute_ctrl (
    Resampler_state_t * state,
    const float complex * x,
    size_t x_len,
    const float complex * ctrl,
    size_t ctrl_len,
    float complex * out
) 

Parameters:

  • state Pointer to a valid Resampler_state_t.
  • x CF32 input samples.
  • x_len Number of input samples.
  • ctrl CF32 array, same length as x; only the real part is used as a per-sample rate addend.
  • ctrl_len Number of control samples; must equal x_len.
  • out Output buffer; must hold at least RESAMPLER_MAX_OUT samples.

Returns:

CF32 output array; length depends on accumulated rate deviations.

>>> from doppler.resample import Resampler
>>> import numpy as np
>>> r = Resampler(rate=1.0)
>>> x = np.zeros(64, dtype=np.complex64)
>>> ctrl = np.zeros(64, dtype=np.complex64)
>>> y = r.execute_ctrl(x, ctrl)
>>> y.shape, y.dtype
((64,), dtype('complex64'))

function Resampler_execute_ctrl_max_out

size_t Resampler_execute_ctrl_max_out (
    Resampler_state_t * state
) 

Always returns RESAMPLER_MAX_OUT.


function Resampler_execute_max_out

size_t Resampler_execute_max_out (
    Resampler_state_t * state
) 

Always returns RESAMPLER_MAX_OUT.


function Resampler_get_num_phases

Number of polyphase branches in the filter bank. Always a power of two. The built-in bank has 4096 phases giving sub-sample timing resolution of 1/4096 of an input sample period.

size_t Resampler_get_num_phases (
    const Resampler_state_t * state
) 

>>> from doppler.resample import Resampler
>>> Resampler(rate=1.0).num_phases
4096

function Resampler_get_num_taps

Taps per polyphase branch. Total prototype filter length is num_phases * num_taps - 1. The built-in bank uses 19 taps per branch.

size_t Resampler_get_num_taps (
    const Resampler_state_t * state
) 

>>> from doppler.resample import Resampler
>>> Resampler(rate=1.0).num_taps
19

function Resampler_get_rate

Get / set the output-to-input sample rate ratio. The setter recomputes the phase increment immediately; the delay line and phase accumulator are preserved so in-stream rate changes are glitch-free. Switching sign of (rate - 1) (i.e. crossing the boundary between interp and decim modes) requires a fresh create().

double Resampler_get_rate (
    const Resampler_state_t * state
) 

>>> from doppler.resample import Resampler
>>> r = Resampler(rate=0.5)
>>> r.rate
0.5
>>> r.rate = 1.5
>>> r.rate
1.5

function Resampler_get_state

Serialize the resampler's phase + delay-line state into blob .

void Resampler_get_state (
    const Resampler_state_t * state,
    void * blob
) 


function Resampler_reset

Zero the delay line and phase accumulator. Rate and polyphase bank are preserved so the resampler can be resumed at the same ratio. Zeroing state eliminates transient artefacts when starting a new signal burst.

void Resampler_reset (
    Resampler_state_t * state
) 

>>> from doppler.resample import Resampler
>>> import numpy as np
>>> r = Resampler(rate=2.0)
>>> _ = r.execute(np.ones(64, dtype=np.complex64))
>>> r.reset()
>>> r.rate
2.0

function Resampler_set_rate

void Resampler_set_rate (
    Resampler_state_t * state,
    double rate
) 

function Resampler_set_state

Restore state from blob ; DP_OK, or DP_ERR_INVALID if rejected.

int Resampler_set_state (
    Resampler_state_t * state,
    const void * blob
) 


function Resampler_state_bytes

Serialized-state byte size (forwarded to the resamp leaf).

size_t Resampler_state_bytes (
    const Resampler_state_t * state
) 


Macro Definition Documentation

define RESAMPLER_MAX_OUT

#define RESAMPLER_MAX_OUT `65536`


The documentation for this class was generated from the following file native/inc/Resampler/Resampler_core.h