Skip to content

File RateConverter_core.h

FileList > doppler > RateConverter > RateConverter_core.h

Go to the source code of this file

Optimal-speed rate conversion cascade. More...

  • #include "doppler/clib_common.h"
  • #include "doppler/dp_state.h"
  • #include "doppler/dp_complex.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include "doppler/resamp/resamp_core.h"
  • #include "doppler/fir/fir_core.h"
  • #include "doppler/agc/agc_core.h"
  • #include "doppler/dp_tlm/dp_tlm_core.h"

Classes

Type Name
struct dp_RateConverter_state_t
Cascade state owns all sub-stage C objects.

Public Types

Type Name
enum rc_pulse_t
Matched-filter pulse selection for the terminal stage.
enum rc_stage_t

Public Functions

Type Name
double dp_RateConverter_agc_gain_db (const dp_RateConverter_state_t * s)
Gain the pre-terminal AGC last applied, in dB; 0.0 when off.
double dp_RateConverter_agc_ref_db (const dp_RateConverter_state_t * s)
The pre-terminal AGC's reference level, in dB.
size_t dp_RateConverter_bank_shape_value (const dp_RateConverter_state_t * s, size_t i)
Element i of the bank shape: 0 -> num_phases, 1 -> num_taps.
size_t dp_RateConverter_convert (double rate, int compensate, const float _Complex * in, size_t n_in, float _Complex * out, size_t max_out)
One-shot rate conversion — no persistent state required.
dp_RateConverter_state_t * dp_RateConverter_create (double rate, int compensate)
Create a rate converter for the given output/input rate ratio. Selects the cheapest cascade of CIC, HalfbandDecimator, and/or polyphase Resampler stages at construction time (see file header for the selection table). Setting compensate=1 appends a closed-form Molnar-Vucic CIC droop-compensating FIR after any CIC stage, which improves passband flatness at the cost of one extra FIR stage.
dp_RateConverter_state_t * dp_RateConverter_create_matched (double rate, int compensate, int pulse, double beta, size_t span, double pulse_sps, size_t num_phases)
Create a rate converter whose terminal stage IS a matched filter, on the sampled arms.
dp_RateConverter_state_t * dp_RateConverter_create_matched_scaled (double rate, int compensate, int pulse, double beta, size_t span, double pulse_sps, size_t num_phases, int arms)
Create a rate converter whose terminal stage IS a matched filter, choosing which arms the bank is built from.
void dp_RateConverter_destroy (dp_RateConverter_state_t * s)
Free all resources: every sub-stage, the AGC, and the state itself.
int dp_RateConverter_enable_agc (dp_RateConverter_state_t * s, double bn_sym, double alpha)
Level the stream feeding the terminal (matched) stage.
size_t dp_RateConverter_execute (dp_RateConverter_state_t * s, const float _Complex * in, size_t n_in, float _Complex * out, size_t max_out)
Convert a block of CF32 samples through the cascade. Passes input through each stage in order, ping-ponging between two intermediate buffers. State persists between calls, so contiguous calls on sequential blocks give the same result as one large call. Output length is approximately n_in * rate.
size_t dp_RateConverter_execute_ctrl (dp_RateConverter_state_t * s, const float _Complex * x, size_t n_in, double ctrl, float _Complex * out, size_t max_out)
Convert a block, steering the cascade's fractional stage by ctrl .
size_t dp_RateConverter_execute_ctrl_max_out (dp_RateConverter_state_t * s)
Output-capacity hint for the block control form.
size_t dp_RateConverter_execute_ctrl_push (dp_RateConverter_state_t * s, float _Complex x, double ctrl, float _Complex * out, size_t max_out)
Push ONE input sample; emit whatever outputs it completes.
size_t dp_RateConverter_execute_ctrl_push_max_out (dp_RateConverter_state_t * s)
Output bound for ONE pushed input.
size_t dp_RateConverter_execute_ctrl_push_pair (dp_RateConverter_state_t * s, float _Complex x, double ctrl, float _Complex * out, float _Complex * dout, uint32_t * arm, double * cu, size_t max_out, float _Complex * pre_out, int * n_pre)
dp_RateConverter_execute_ctrl_push_tap() , also returning each output's derivative-bank value, its arm and the factor to the unit-noise arm: what the derivative-bank detector reads.
size_t dp_RateConverter_execute_ctrl_push_tap (dp_RateConverter_state_t * s, float _Complex x, double ctrl, float _Complex * out, size_t max_out, float _Complex * pre_out, int * n_pre)
dp_RateConverter_execute_ctrl_push() , also emitting the PRE-TERMINAL sample — the cascade's output after every integer stage and after the AGC, but before the terminal matched filter.
size_t dp_RateConverter_execute_max_out (dp_RateConverter_state_t * s)
Upper bound on execute output for a standard 65536-sample block.
double dp_RateConverter_gain (const dp_RateConverter_state_t * s)
The cascade's response to a constant input, from its stages' own coefficients — computed, never measured.
double dp_RateConverter_get_bank_sps (const dp_RateConverter_state_t * s)
Samples per symbol on the terminal stage's grid — the rate the pre-terminal tap runs at.
uint32_t dp_RateConverter_get_cic_headroom_bits (const dp_RateConverter_state_t * s)
The headroom this converter gives its CIC stages, in bits.
uint32_t dp_RateConverter_get_cic_precision (const dp_RateConverter_state_t * s)
The precision this converter gives its CIC stages.
bool dp_RateConverter_get_clipped (const dp_RateConverter_state_t * s)
Has any planned CIC stage clipped its input since the last reset?
double dp_RateConverter_get_count_lag (const dp_RateConverter_state_t * s)
How far the output COUNT can trail the rate, in INPUT samples: after m inputs a fresh converter has emitted at least(m - lag) * rate outputs, whatever the call sizes.
double dp_RateConverter_get_data_eye (const dp_RateConverter_state_t * s)
Where the unit-noise arms' output power on random data, averaged over the arms and over the phases each arm covers, peaks, in symbols past the instant dp_RateConverter_get_group_delay() names: the eye a derivative detector is built around.
double dp_RateConverter_get_full_scale (const dp_RateConverter_state_t * s)
The input bound of this plan: a component at or beyond it is clipped.
double dp_RateConverter_get_group_delay (const dp_RateConverter_state_t * s)
The converter's group delay, in its INPUT samples: where in the input timeline an output sample's content sits.
double dp_RateConverter_get_memory (const dp_RateConverter_state_t * s)
The converter's memory, in its INPUT samples: how many inputs after create or reset until an output depends on nothing but the input.
bool dp_RateConverter_get_narrow_pulse (const dp_RateConverter_state_t * s)
Is this converter's rectangular matched filter degenerately narrow?
double dp_RateConverter_get_rate (const dp_RateConverter_state_t * s)
Get / set the output-to-input sample rate ratio. The setter rebuilds the entire cascade (new stage selection, new sub-objects) and resets all filter memories — equivalent to destroying and recreating with the new rate. A rate that is not finite and > 0 is refused and leaves the converter as it was.
void dp_RateConverter_get_state (const dp_RateConverter_state_t * s, void * blob)
Serialize s's active-stage state intoblob .
double dp_RateConverter_get_step (const dp_RateConverter_state_t * s)
The input step of this plan: a component smaller than it reads zero.
int dp_RateConverter_has_derivative (const dp_RateConverter_state_t * s)
Whether the converter carries the derivative bank the paired call reads: its tables were built (a matched converter's on an optimum kind) and attached to a fractional terminal stage.
size_t dp_RateConverter_num_bank_shape (const dp_RateConverter_state_t * s)
Terminal polyphase bank shape (backs the bank_shape property).
size_t dp_RateConverter_num_stages (const dp_RateConverter_state_t * s)
Number of planned cascade stages (backs the stages property).
void dp_RateConverter_reset (dp_RateConverter_state_t * s)
Zero all sub-stage filter memories. Rate, stage count, and stage types are preserved. Processing from a reset state produces the same output as a freshly created converter fed the same input. Use between signal bursts to suppress transient artefacts from prior filter memory. An enabled AGC is reset too (back to unity gain with its detector at the reference), and the clip flag read by dp_RateConverter_get_clipped() is cleared with the CIC stages.
int dp_RateConverter_response (const dp_RateConverter_state_t * s, uint64_t k0, size_t n, double * h, int64_t * newest)
What each of a run of outputs is, as a filter on the input: the plan's response, from the stages' definitions.
size_t dp_RateConverter_response_len (const dp_RateConverter_state_t * s)
Taps dp_RateConverter_response() writes for one output.
int dp_RateConverter_set_cic_headroom_bits (dp_RateConverter_state_t * s, uint32_t bits)
Set the headroom of every CIC stage this converter plans, and reset the converter.
int dp_RateConverter_set_cic_precision (dp_RateConverter_state_t * s, uint32_t precision)
Choose the input word of every CIC stage this converter plans, with that word's headroom, and reset the converter.
void dp_RateConverter_set_rate (dp_RateConverter_state_t * s, double rate)
Change the rate; rebuilds the cascade and resets all filter state. A matched cascade keeps its pulse and an enabled AGC survives (its reference is re-derived for the new terminal bank). The change is all or nothing: the new cascade (and AGC) is built first and committed only once it exists, so a refused rate or a failed rebuild leaves the converter exactly as it was same rate, same stages, same filter memory. That includes the AGC: one that cannot be rebuilt for the new bank refuses the whole change, where it used to be dropped and the rate taken anyway.
int dp_RateConverter_set_state (dp_RateConverter_state_t * s, const void * blob)
Restore active-stage state from blob (same rate).
int dp_RateConverter_set_telemetry (dp_RateConverter_state_t * s, dp_tlm_t * tlm, const char * prefix, uint32_t decim)
Attach (or detach) a telemetry context on the pre-terminal AGC.
int dp_RateConverter_stage_label (dp_RateConverter_state_t * s, int i, char * buf, size_t len)
Write a human-readable label for stage i into buf.
const char * dp_RateConverter_stages_value (const dp_RateConverter_state_t * s, size_t i)
Label of stage i , e.g. "CIC(8)+FIR" or "Resampler(0.923,rrc)".
size_t dp_RateConverter_state_bytes (const dp_RateConverter_state_t * s)
Bytes dp_RateConverter_get_state() writes fors (envelope + rate + stages + the AGC's sub-blob when enabled).

Macros

Type Name
define RC_ARM_SAMPLED 0
define RC_ARM_SYMBOL 1
define RC_ARM_UNIT_NOISE 2
define RC_MAX_STAGES 3
define RC_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('R', 'C', 'V', 'T')
define RC_STATE_VERSION 4u

Detailed Description

Selects the cheapest cascade of CIC, HalfbandDecimator, and/or polyphase Resampler stages for a given output/input sample rate ratio at creation time. All sub-stage C objects are owned by the state struct.

Stage selection (D = 1/rate):

rate >= 1.0 or D < 2 [Resampler(rate)] D ~= 2^1 [HalfbandDecimator] D ~= 2^2 [HalfbandDecimator, HalfbandDecimator] D ~= 2^n, n>=3, D<=CIC_R_MAX [CIC(D)] D ~= 2^n, D > CIC_R_MAX [CIC(CIC_R_MAX), Resampler(R/D)] D >= 8, non-power-of-2 [CIC(R*), Resampler correction] R* = nearest power-of-2 to D, capped otherwise (2 <= D < 8, non-int) [Resampler(rate)]

A single CIC stage is capped at CIC_R_MAX (2048) — see cic_core.h for the accumulator budget that sets it. The cap costs no rate: whatever the capped CIC leaves is handed to a Resampler stage, so the cascade still delivers the D it was asked for. That was not always true — gating the residual on the matched-terminal flag alone meant a capped plan silently decimated by R and claimed D (see the CHANGELOG for the measurement).

INPUT AMPLITUDE IS BOUNDED whenever the plan contains a CIC stage — that is, any decimation by 8 or more: |Re| and |Im| under dp_RateConverter_get_full_scale(), CIC_PAPR_WIDE (12 dB above unity) as built, clipped at and beyond that, before any filtering. The headroom is there so a waveform's PEAKS have somewhere to sit above its unit average, and it and the word under it are settings (dp_RateConverter_set_cic_precision(), dp_RateConverter_set_cic_headroom_ bits()); see cic_core.h. stages is how you tell: a plan naming CIC(...) is not scale-free, every other plan is. This is the one property of this object a caller cannot infer from an output that is finite and looks plausible — an overdriven RRC-BPSK waveform matched-filters to -25 dB EVM where the same waveform well inside the bound reaches -50 dB.

Lifecycle:

dp_RateConverter_state_t *rc = dp_RateConverter_create(0.1, 0);
// rc->n_stages == 2: CIC(8) then Resampler(0.8)
float _Complex out[512];
size_t n = dp_RateConverter_execute(rc, in, 4096, out, 512);
dp_RateConverter_destroy(rc);

Public Types Documentation

enum rc_pulse_t

Matched-filter pulse selection for the terminal stage.

enum rc_pulse_t {
    RC_PULSE_IANDD = 0,
    RC_PULSE_RRC = 1,
    RC_PULSE_NONE = 2
};

A cascade whose terminal stage carries a pulse-shaped bank instead of the default Kaiser anti-alias bank IS the matched filter — the same dot product does the rate conversion and the matched filtering, and its arm is the fractional timing delay a downstream loop steers. Values 0/1 match MPSK_RX_PULSE_IANDD/_RRC so one vocabulary covers the family.


enum rc_stage_t

enum rc_stage_t {
    RC_STAGE_HB = 0,
    RC_STAGE_CIC = 1,
    RC_STAGE_RESAMP = 2
};

Stage type tags.


Public Functions Documentation

function dp_RateConverter_agc_gain_db

Gain the pre-terminal AGC last applied, in dB; 0.0 when off.

double dp_RateConverter_agc_gain_db (
    const dp_RateConverter_state_t * s
) 

The cascade's time-varying gain, kept deliberately separate from dp_RateConverter_gain(): that function reports the response computed from the stages' own COEFFICIENTS, and an AGC has none. A caller asking "what did this cascade do to my amplitude" with the AGC on wants both, and they multiply.

Parameters:

Returns:

Last applied AGC gain in dB; 0.0 when the AGC is not enabled.


function dp_RateConverter_agc_ref_db

The pre-terminal AGC's reference level, in dB.

double dp_RateConverter_agc_ref_db (
    const dp_RateConverter_state_t * s
) 

10*log10(bank_e0 / bank_sps) — the average power a unit-amplitude symbol stream has where the AGC sits, derived from the terminal bank's own pulse energy. Defined for any MATCHED cascade whether or not the AGC is enabled, because it describes the bank rather than the loop; 0.0 for a plain one.

Parameters:

Returns:

Reference power in dB (relative to unit power per sample).


function dp_RateConverter_bank_shape_value

Element i of the bank shape: 0 -> num_phases, 1 -> num_taps.

size_t dp_RateConverter_bank_shape_value (
    const dp_RateConverter_state_t * s,
    size_t i
) 

Meaningful only when dp_RateConverter_num_bank_shape() returns 2; when it returns 0 (the cascade ends in an integer decimator) there is no bank and this returns 0 rather than reading a stage that is not a Resampler.

Parameters:

  • s Pointer to a valid dp_RateConverter_state_t.
  • i 0 for the number of polyphase arms, any other value for the number of taps per arm.

Returns:

The requested dimension of the terminal bank, or 0 when there is none.


function dp_RateConverter_convert

One-shot rate conversion — no persistent state required.

size_t dp_RateConverter_convert (
    double rate,
    int compensate,
    const float _Complex * in,
    size_t n_in,
    float _Complex * out,
    size_t max_out
) 

Creates a temporary converter, converts n_in samples, destroys it. Equivalent to:

dp_RateConverter_state_t *rc = dp_RateConverter_create(rate, compensate);
size_t n = dp_RateConverter_execute(rc, in, n_in, out, max_out);
dp_RateConverter_destroy(rc);

Use dp_RateConverter_create() directly when processing multiple blocks at the same rate — the one-shot form resets filter memory on every call.

Parameters:

  • rate Output-to-input sample rate ratio.
  • compensate Non-zero to enable CIC droop compensation.
  • in CF32 input samples.
  • n_in Number of input samples.
  • out Output buffer.
  • max_out Output buffer capacity in samples.

Returns:

Number of output samples written; 0 if rate is outside dp_resamp_rate_ok(), on OOM, or if n_in == 0.


function dp_RateConverter_create

Create a rate converter for the given output/input rate ratio. Selects the cheapest cascade of CIC, HalfbandDecimator, and/or polyphase Resampler stages at construction time (see file header for the selection table). Setting compensate=1 appends a closed-form Molnar-Vucic CIC droop-compensating FIR after any CIC stage, which improves passband flatness at the cost of one extra FIR stage.

dp_RateConverter_state_t * dp_RateConverter_create (
    double rate,
    int compensate
) 

Parameters:

  • rate Output-to-input sample rate ratio: finite and > 0 (dp_resamp_rate_ok()).
  • compensate Non-zero to append a CIC passband-droop compensating FIR after any CIC stage.

Returns:

Non-NULL on success, owned by the caller and released with dp_RateConverter_destroy(); NULL if rate is outside dp_resamp_rate_ok() (NaN included), if no cascade can be planned for rate, or on OOM.

>>> from doppler.resample import RateConverter
>>> rc = RateConverter(rate=0.5, compensate=0)
>>> rc.rate
0.5

function dp_RateConverter_create_matched

Create a rate converter whose terminal stage IS a matched filter, on the sampled arms.

dp_RateConverter_state_t * dp_RateConverter_create_matched (
    double rate,
    int compensate,
    int pulse,
    double beta,
    size_t span,
    double pulse_sps,
    size_t num_phases
) 

dp_RateConverter_create_matched_scaled() with RC_ARM_SAMPLED, the arms Gardner and the DTTL read; that function documents the cascade, the parameters and the other arm kinds.

Parameters:

Returns:

As dp_RateConverter_create_matched_scaled().


function dp_RateConverter_create_matched_scaled

Create a rate converter whose terminal stage IS a matched filter, choosing which arms the bank is built from.

dp_RateConverter_state_t * dp_RateConverter_create_matched_scaled (
    double rate,
    int compensate,
    int pulse,
    double beta,
    size_t span,
    double pulse_sps,
    size_t num_phases,
    int arms
) 

Plans the same cheap cascade as dp_RateConverter_create(), then puts a pulse-shaped polyphase bank on the terminal stage instead of the default Kaiser one. The cascade therefore does rate conversion and matched filtering in a single dot product, and that stage's polyphase arm is the fractional timing delay — which is what makes dp_RateConverter_execute_ctrl() a timing control port rather than just a Doppler knob.

Three things this does that plain create() cannot:

  • The terminal fractional stage always exists. The ordinary planner drops it for an exact power-of-two decimation, and again when the correction lands within 1e-6 of 1.0 — so rate = 2/64 plans a bare CIC(32) with nothing steerable at the end. Here the terminal stage is simultaneously the matched filter and the timing element, so it is appended (at rate 1.0 if there is no rate left to correct).
  • The bank is sized by the POST-decimation rate. Matched-filtering at the input rate costs taps proportional to the input samples per symbol (4225 taps/arm at 256 samples/symbol — 17 MB of bank); after the integer stages have done the bulk decimation it is ~2*span*pulse_sps taps, constant in the input rate.
  • CIC droop folds into the bank, exactly rather than approximately: the Molnar-Vucic compensator (ciccompmf) runs at the decimated rate, which IS the terminal stage's tap grid, so the fold is a per-arm convolution and costs no extra stage. compensate therefore adds no FIR on this path.

Measured on RRC-BPSK (beta 0.35, span 8, two outputs per symbol), best-case timing phase, noiseless: a halfband cascade reaches -60 dB EVM; a CIC cascade reaches -50 dB with compensate = 1 and only -22 dB without, so on this path compensation is not a refinement — it is 28 dB, for six extra taps per arm and no extra pass over the data. Folded or appended agree to within 0.6 dB, i.e. the fold gives up nothing to a separate comp FIR.

Note:

Keep the INPUT inside dp_RateConverter_get_full_scale() whenever the plan contains a CIC stage — see the file header. The clip is silent, and it costs 25 dB of the EVM quoted above for reasons that have nothing to do with the matched filter.

Parameters:

  • rate Output-to-input sample rate ratio (finite and > 0, dp_resamp_rate_ok()). Rate-agnostic: this object never learns about symbols — a caller wanting m samples per symbol asks for rate = m/sps.
  • compensate Non-zero to correct CIC passband droop (folded into the bank here, not appended as a stage).
  • pulse RC_PULSE_RRC / RC_PULSE_IANDD. RC_PULSE_NONE is invalid here — use dp_RateConverter_create() for a plain conversion. The RRC's arms are the pulse sampled at each arm's fraction of an input interval. The rectangle's are an integral over exactly one symbol: interior taps weigh 1 and each edge tap weighs the share of its own input interval that lies inside the symbol, so the output follows the sampling instant continuously and a constant input returns the constant on any grid. That is RC_ARM_SAMPLED; see arms.
  • beta RRC roll-off in [0, 1] (ignored for the rectangle).
  • span One-sided RRC span in symbols (ignored for the rectangle, whose support is always exactly one symbol).
  • pulse_sps The pulse's period measured in output samples (2 = two samples per symbol out). This is a shape parameter, not a rate-planning one: a matched filter has a symbol duration, and the planner still knows nothing of symbols.
  • num_phases Terminal-stage arms; a power of two from 2 to RESAMP_MAX_PHASES (2^32), the most the terminal resampler's 32-bit phase word can address. Sets the fractional timing resolution to 1/num_phases of an output period.
  • arms RC_ARM_SAMPLED (what dp_RateConverter_create_matched() builds) samples the pulse at each arm's lag. RC_ARM_SYMBOL and RC_ARM_UNIT_NOISE give the rectangle the optimum arm for each edge position, h = R^-1 q from the plan's own response, with the tables ml_c and ml_dh beside the bank: RC_ARM_SYMBOL has every arm return the symbol, and RC_ARM_UNIT_NOISE has every arm pass white input noise at unit power. The optimum arm's eye is its designed position (Cauchy-Schwarz on the unit-noise output), and the group delay reads it there; a detector that reads a derivative needs these arms, and Gardner and the DTTL read the sampled ones (docs/design/ratesync-timing.md, 9.1). The root-raised cosine's arms are its sampled ones under every kind; RC_ARM_SYMBOL and RC_ARM_UNIT_NOISE put ml_c and ml_dh beside them, the same for both.

Returns:

Non-NULL on success; NULL on a bad parameter (a larger num_phases is refused before its bank is built), an arms that is none of the three, or OOM.

White noise of unit power through unit-noise arms, with nothing ahead of the bank, comes out at unit power:

>>> import numpy as np
>>> from doppler.resample import MatchedRateConverter
>>> rng = np.random.default_rng(1)
>>> b = 2 * rng.integers(0, 2, (2, 1 << 16)) - 1
>>> x = ((b[0] + 1j * b[1]) / np.sqrt(2)).astype(np.complex64)
>>> mf = MatchedRateConverter(0.99, compensate=0, pulse="iandd",
...                           pulse_sps=4, arms="unit_noise")
>>> y = mf.execute(x)
>>> round(float(np.mean(np.abs(y[64:]) ** 2)), 2)
1.0

function dp_RateConverter_destroy

Free all resources: every sub-stage, the AGC, and the state itself.

void dp_RateConverter_destroy (
    dp_RateConverter_state_t * s
) 

Parameters:

  • s Converter to free; NULL is a no-op.

function dp_RateConverter_enable_agc

Level the stream feeding the terminal (matched) stage.

int dp_RateConverter_enable_agc (
    dp_RateConverter_state_t * s,
    double bn_sym,
    double alpha
) 

Wedges an AGC into the cascade immediately BEFORE the terminal polyphase stage — after every integer decimation, ahead of the matched filter and the timing element. Off until this is called, and off is what both constructors build, so a plain cascade is untouched and dp_RateConverter_gain() still reads exactly 1.0.

** **

The consumer is a timing-error detector. A TED's raw output is the timing error multiplied by three things it did not choose — the signal amplitude, the transition density, and the detector's own slope — and only the last is the detector's to divide out (dp_symsync_ted_slope(), which is computed at construct FOR A UNIT-AMPLITUDE SYMBOL STREAM). Amplitude enters as A^2 for Gardner and A^1 for DTTL, so a 4x level error is a 16x loop-gain error. Levelling it is this object's job because this object owns the bank that sets what "unit amplitude" means.

The tap is pre-terminal rather than post because the terminal stage's OUTPUT rate is the one a timing loop is actively steering, and an AGC whose bandwidth is quoted in cycles per sample of a stream another loop is stretching is coupled to that loop. The pre-terminal rate is fixed.

** **

The AGC sets average POWER; the TED wants unit symbol AMPLITUDE. The bridge is the pulse's own energy on its own tap grid — bank_e0 = sum h(t)^2, the quantity the bank is already normalised by — so for i.i.d. unit-power symbols at bank_sps samples per symbol the pre-terminal average power is bank_e0 / bank_sps and that is the reference. No caller supplies a level; read it back with dp_RateConverter_agc_ref_db().

Note:

On an optimum bank (RC_ARM_SYMBOL, RC_ARM_UNIT_NOISE) each arm is normalized by its own q'R^-1 q, not by bank_e0. The reference is still the pre-terminal level of unit-amplitude symbols, so an RC_ARM_SYMBOL bank returns unit symbols; an RC_ARM_UNIT_NOISE bank returns them at sqrt(q'R^-1 q) for the arm, its unit-noise output.

Note:

This levels signal PLUS noise, so at finite Es/N0 the symbols land slightly low — about 0.95x amplitude at 10 dB Es/N0, i.e. 0.91x Gardner loop gain. That is a fact of the measurement, not an error to estimate away: an AGC that tried to exclude noise would be estimating the very quantity the receiver is trying to measure.

** **

bn_sym is in cycles per SYMBOL, matching every other loop bandwidth in this family, and is converted to the AGC's own per-sample units with the one number that describes its position (bn_sym / bank_sps). It must stay well below the bandwidth of every loop downstream — an AGC divides out the amplitude those loops' discriminators are built around, so one running near a loop's bandwidth corrects the excursions that loop is itself producing. See mpsk_rx_agc_bn() for the ratio a composing receiver uses.

The loop starts at unity gain and walks to the level; there is no seed and no sample is treated specially at the start. A seed is a STEP in gain, and one taken off a signal that has not arrived is a shock the loops downstream cannot absorb see rc_agc_tap() for the measurement that settled this. So bn_sym also sets how fast a level error is corrected, and a very slow AGC leaves the early symbols under- or over-driven for a loop time constant.

Parameters:

  • s Must be non-NULL, and must be a MATCHED cascade (dp_RateConverter_create_matched()) — a plain one has no pulse and therefore no reference to derive.
  • bn_sym AGC loop noise bandwidth in cycles/symbol; > 0.
  • alpha Power-detector EMA coefficient, in (0, 1].

Returns:

DP_OK, or DP_ERR_INVALID for a plain cascade or a bad parameter (the converter is left exactly as it was, AGC still off).

dp_RateConverter_state_t *rc =
    dp_RateConverter_create_matched (2.0 / 8.0, 1, RC_PULSE_RRC, 0.35, 8,
                                  2.0, 1024);
dp_RateConverter_enable_agc (rc, 1e-4, 0.01);
printf ("%.2f dB\n", dp_RateConverter_agc_ref_db (rc));
dp_RateConverter_destroy (rc);

function dp_RateConverter_execute

Convert a block of CF32 samples through the cascade. Passes input through each stage in order, ping-ponging between two intermediate buffers. State persists between calls, so contiguous calls on sequential blocks give the same result as one large call. Output length is approximately n_in * rate.

size_t dp_RateConverter_execute (
    dp_RateConverter_state_t * s,
    const float _Complex * in,
    size_t n_in,
    float _Complex * out,
    size_t max_out
) 

Parameters:

  • s Pointer to a valid dp_RateConverter_state_t.
  • in CF32 input block.
  • n_in Number of input samples.
  • out Output buffer; must hold at least max_out samples.
  • max_out Capacity of out in samples.

Returns:

CF32 output array; length is approximately n_in * rate.

>>> from doppler.resample import RateConverter
>>> import numpy as np
>>> rc = RateConverter(rate=0.5, compensate=0)
>>> y = rc.execute(np.zeros(1024, dtype=np.complex64))
>>> y.shape, y.dtype
((512,), dtype('complex64'))

function dp_RateConverter_execute_ctrl

Convert a block, steering the cascade's fractional stage by ctrl .

size_t dp_RateConverter_execute_ctrl (
    dp_RateConverter_state_t * s,
    const float _Complex * x,
    size_t n_in,
    double ctrl,
    float _Complex * out,
    size_t max_out
) 

The control-port form of dp_RateConverter_execute(): the fixed integer stages (HalfbandDecimator / CIC) run unchanged, and the scalar rate deviation ctrl is forwarded to the terminal polyphase Resampler stage's accumulator (via dp_resamp_execute_ctrl_push) — so its effective rate becomes stage_rate + ctrl for this call. This exposes the fractional tail's control port that dp_RateConverter_execute() hides: a timing/rate-tracking loop can decimate a high input rate cheaply through the HB/CIC stages and then arbitrary-rate + strobe-align in the last stage, updating ctrl per block.

ctrl is referenced to the terminal stage's (post-decimation) rate, not the overall rate. It is meaningful only when the cascade actually ends in a Resampler stage; a pure integer HB/CIC cascade has no fractional stage to steer, so this falls through to dp_RateConverter_execute() (ctrl ignored).

Parameters:

  • s Pointer to a valid dp_RateConverter_state_t.
  • x CF32 input block.
  • n_in Number of input samples.
  • ctrl Rate deviation added to the terminal Resampler stage's rate.
  • out Output buffer; must hold at least max_out samples.
  • max_out Capacity of out in samples.

Returns:

CF32 output array; length tracks the accumulated effective rate.

>>> from doppler.resample import RateConverter
>>> import numpy as np
>>> rc = RateConverter(rate=0.8, compensate=0)  # -> Resampler(0.8)
>>> x = np.ones(1000, dtype=np.complex64)
>>> rc.execute_ctrl(x, 0.0).shape[0]    # base rate: 1000 -> 800
800
>>> rc2 = RateConverter(rate=0.8, compensate=0)
>>> rc2.execute_ctrl(x, 0.05).shape[0]  # +ctrl speeds the tail up
851

function dp_RateConverter_execute_ctrl_max_out

Output-capacity hint for the block control form.

size_t dp_RateConverter_execute_ctrl_max_out (
    dp_RateConverter_state_t * s
) 

Unlike dp_RateConverter_execute_max_out() this always returns 0, which tells the binding to size the output buffer from the input block instead.

Parameters:

Returns:


function dp_RateConverter_execute_ctrl_push

Push ONE input sample; emit whatever outputs it completes.

size_t dp_RateConverter_execute_ctrl_push (
    dp_RateConverter_state_t * s,
    float _Complex x,
    double ctrl,
    float _Complex * out,
    size_t max_out
) 

The per-input streaming form of dp_RateConverter_execute_ctrl(), and the only form a closed loop can use: a block call must know its whole ctrl history up front, whereas a timing loop computes each correction from the outputs already emitted. Feeding a stream one sample at a time through this reproduces dp_RateConverter_execute_ctrl() on the same block bit-for-bit when ctrl is held constant (the cascade is block-boundary invariant), so the cheap block form stays correct for open-loop use.

The integer HB/CIC stages consume the sample and emit at most one intermediate sample each; the terminal Resampler stage then emits 0 outputs (a decimator between strobes — the common case), 1, or several (an interpolator). A cascade with no terminal Resampler ignores ctrl.

Parameters:

  • s Pointer to a valid dp_RateConverter_state_t.
  • x One CF32 input sample.
  • ctrl Rate deviation added to the terminal stage's rate for this input (referenced to the terminal, post-decimation rate).
  • out Output buffer for any emitted samples.
  • max_out Capacity of out (emission stops at this bound).

Returns:

CF32 array of the outputs completed by this input (0, 1, or more).

>>> from doppler.resample import RateConverter
>>> import numpy as np
>>> rc = RateConverter(rate=0.8, compensate=0)  # -> Resampler(0.8)
>>> x = (np.arange(10, dtype=np.float32) + 1).astype(np.complex64)
>>> # a decimator emits 0 between strobes, 1 on a strobe:
>>> [rc.execute_ctrl_push(complex(v), 0.0).shape[0] for v in x]
[1, 1, 1, 1, 0, 1, 1, 1, 1, 0]

function dp_RateConverter_execute_ctrl_push_max_out

Output bound for ONE pushed input.

size_t dp_RateConverter_execute_ctrl_push_max_out (
    dp_RateConverter_state_t * s
) 

Computed as (size_t)max(rate, 1.0) + 2, which is at least ceil(rate) + 1. Non-zero because the push form has no input block to size from.

Parameters:

Returns:

Output capacity, in samples, for one dp_RateConverter_execute_ctrl_push() call.


function dp_RateConverter_execute_ctrl_push_pair

dp_RateConverter_execute_ctrl_push_tap() , also returning each output's derivative-bank value, its arm and the factor to the unit-noise arm: what the derivative-bank detector reads.

size_t dp_RateConverter_execute_ctrl_push_pair (
    dp_RateConverter_state_t * s,
    float _Complex x,
    double ctrl,
    float _Complex * out,
    float _Complex * dout,
    uint32_t * arm,
    double * cu,
    size_t max_out,
    float _Complex * pre_out,
    int * n_pre
) 

The derivative-bank detector (docs/design/ratesync-timing.md, §2 and §9.1) forms Re{ conj(c_u y) dy }. y is this converter's output, the symbol on a bank built RC_ARM_SYMBOL, so the unit-noise arm the detector reads is c_u y, with dy the derivative of that unit-noise arm (the table ml_dh, attached to the terminal stage at build). This returns all three for every output, so a detector holds no table of its own:

  • out[j], bit for bit the tap call's output;
  • dout[j], the terminal stage's second bank at the same arm over the same delay line (dp_resamp_execute_ctrl_push_pair());
  • arm[j], that arm's index;
  • cu[j], the factor from out[j] to the unit-noise arm: ml_c at the arm, which the build stores as exactly that factor. The rectangle's is c_u on a converter built RC_ARM_SYMBOL and 1 on one built RC_ARM_UNIT_NOISE, whose bank already is the unit-noise arm; the root-raised cosine's bank is the sampled one under either, so its factor is 1 / sqrt(b' R b) under both.

A converter with no derivative table (dp_RateConverter_has_derivative() is 0: the sampled arms, no pulse, or a plan with no fractional tail) writes 0 to dout and cu, so a detector that reads them anyway sees no error. A detector checks the predicate when it is built; this per-sample call cannot refuse without dropping the input.

Parameters:

Returns:

Number of outputs written.


function dp_RateConverter_execute_ctrl_push_tap

dp_RateConverter_execute_ctrl_push() , also emitting the PRE-TERMINAL sample — the cascade's output after every integer stage and after the AGC, but before the terminal matched filter.

size_t dp_RateConverter_execute_ctrl_push_tap (
    dp_RateConverter_state_t * s,
    float _Complex x,
    double ctrl,
    float _Complex * out,
    size_t max_out,
    float _Complex * pre_out,
    int * n_pre
) 

This is the tap a non-data-aided carrier discriminator wants, and it is the reason this variant exists (see docs/design/mpsk.md §3.3). It is already band-limited by the cascade's own decimation filters and already levelled by the AGC that sits on this exact node, yet it is ahead of the matched filter — so reading it needs no symbol timing, and it carries none of the matched filter's group delay or its between-symbol ISI.

The rate is bank_sps samples per symbol, a planner outcome: read it with dp_RateConverter_get_bank_sps() rather than assuming it. A consumer wanting a fixed clock decimates this stream itself.

A non-terminal stage swallows inputs between its decimation strobes, so n_pre is 0 on those calls — exactly as the return value is.

Parameters:

  • s Must be non-NULL.
  • x One input sample.
  • ctrl Fractional-rate control for the terminal stage.
  • out Terminal outputs.
  • max_out Capacity of out.
  • pre_out Receives the pre-terminal sample; may be NULL.
  • n_pre Receives 1 if pre_out was written, else 0; may be NULL.

Returns:

Number of terminal outputs written, as the non-tap form.


function dp_RateConverter_execute_max_out

Upper bound on execute output for a standard 65536-sample block.

size_t dp_RateConverter_execute_max_out (
    dp_RateConverter_state_t * s
) 

Returns (size_t)(65536 * max(rate, 1.0)) + 2. The Python extension uses this to pre-allocate the output buffer on the first execute call.

Parameters:

Returns:

Output capacity in samples.


function dp_RateConverter_gain

The cascade's response to a constant input, from its stages' own coefficients — computed, never measured.

double dp_RateConverter_gain (
    const dp_RateConverter_state_t * s
) 

Each stage answers for itself (dp_hbdecim_dc_gain(), dp_cic_dc_gain() times dp_fir_dc_gain() for a compensated CIC, dp_resamp_dc_gain()) and this is their product. So the number tracks whatever the stages actually hold: if a filter's normalisation drifts, this moves with it, and a gate comparing it against a measured DC probe catches the drift from either side.

A plain cascade is unity — a rate conversion that adds gain of its own is a defect, and dp_RateConverter_create() returns 1.0 here at every rate.

A matched cascade is not, and should not be. Its terminal stage is a matched filter, which is deliberately not flat; the invariant that holds there is at the SYMBOL level (a symbol of amplitude A in, amplitude A out), not at DC. This function still reports that cascade's true DC gain, which is the pulse's sum(h)/sum(h^2).

Parameters:

  • s State. Must be non-NULL.

Returns:

The DC gain of the whole cascade.

dp_RateConverter_state_t *rc = dp_RateConverter_create (1.0 / 12.0, 1);
printf ("%.4f\n", dp_RateConverter_gain (rc));   // 1.0000
dp_RateConverter_destroy (rc);

function dp_RateConverter_get_bank_sps

Samples per symbol on the terminal stage's grid — the rate the pre-terminal tap runs at.

double dp_RateConverter_get_bank_sps (
    const dp_RateConverter_state_t * s
) 

A planner outcome, not a constant: bank_sps = pulse_sps / resamp_rate for whatever integer decimation the plan chose, so it depends on the caller's rate ratio. Reported for the same reason RateConverter::stages is — a caller who can read back what was planned can check it.

Parameters:

Returns:

Samples per symbol at the terminal stage's input; 0.0 for a plain cascade (dp_RateConverter_create()), which has no pulse.


function dp_RateConverter_get_cic_headroom_bits

The headroom this converter gives its CIC stages, in bits.

uint32_t dp_RateConverter_get_cic_headroom_bits (
    const dp_RateConverter_state_t * s
) 

Parameters:

Returns:

Bits of the CIC's input word above unit amplitude.


function dp_RateConverter_get_cic_precision

The precision this converter gives its CIC stages.

uint32_t dp_RateConverter_get_cic_precision (
    const dp_RateConverter_state_t * s
) 

Parameters:

Returns:

CIC_PRECISION_16, CIC_PRECISION_32 or CIC_PRECISION_64.


function dp_RateConverter_get_clipped

Has any planned CIC stage clipped its input since the last reset?

bool dp_RateConverter_get_clipped (
    const dp_RateConverter_state_t * s
) 

The cascade inherits cic_core's input bound, dp_RateConverter_get_full_ scale(), whenever the plan contains a CIC — any decimation by 8 or more — and the clip does not show up in the samples: the output stays finite and plausible, merely distorted. This is the only reliable way to find out, and it is free (the boundary comparisons run on every sample regardless).

Sticky, cleared by dp_RateConverter_reset(). Always 0 for a cascade with no CIC stage, which is the honest answer: those plans are scale-free.

Parameters:

Returns:

1 if any CIC stage has clipped, else 0.


function dp_RateConverter_get_count_lag

How far the output COUNT can trail the rate, in INPUT samples: after m inputs a fresh converter has emitted at least(m - lag) * rate outputs, whatever the call sizes.

double dp_RateConverter_get_count_lag (
    const dp_RateConverter_state_t * s
) 

Not the group delay the signal's but when outputs appear: a decimator emits from its first input, so its outputs are about one output late in number, not a filter's length. Each stage's worst lag, in its input samples, scaled to the converter's input by the rate the stages before it apply (a late stage hands every later one its input late by as much):

  • halfband: 1 output m is formed as input 2m + 1 arrives;
  • CIC(R): R - 1 output k as input kR + R - 1 arrives; the droop compensator runs one output per input and adds none;
  • Resampler: 1 / rate decimating (each output is emitted as its interval closes, so the count is floor(m * rate)); 0 interpolating, and 0 for a matched cascade's terminal at any rate (its push path emits every output the newest input reaches with it).

Computed from the plan, never measured; test_RateConverter_core.c feeds one sample a call at rates that build every plan and holds the measured worst lag to it: never above it, and on a plain decimating cascade within a hundredth of an output (the bound is reached). What it is for: a caller that waits on the output count a block of N outputs and must bound how much input it will have taken by then (AsyncDsssReceiver sizes its hand-over ring from it).

Parameters:

  • s State. Must be non-NULL.

Returns:

The worst count lag, in input samples (>= 0).

dp_RateConverter_state_t *rc = dp_RateConverter_create (0.5, 0);
printf ("%.1f\n", dp_RateConverter_get_count_lag (rc));   // 1.0
dp_RateConverter_destroy (rc);

function dp_RateConverter_get_data_eye

Where the unit-noise arms' output power on random data, averaged over the arms and over the phases each arm covers, peaks, in symbols past the instant dp_RateConverter_get_group_delay() names: the eye a derivative detector is built around.

double dp_RateConverter_get_data_eye (
    const dp_RateConverter_state_t * s
) 

The eye's instant, in input samples after a symbol's center, is get_group_delay() + data_eye * S, S the input samples a symbol (pulse_sps / rate); positive is later. The power is |c_u y|², the unit-noise arm's, as a function of where the symbol falls, with the arms held fixed. On each arm, dy is a central difference quotient, per symbol of timing, of the unit-noise arm about its designed place, with each side scaled to unit noise. Where the derivative-bank detector's mean error, over the arms a steered loop visits, is zero is not computed here, and it can differ from this offset (#3509). No closed loop is run here.

Computed from the tables the converter holds, with no signal run: the argmax over delta of sum_arms sum_n (c_a h_a q_{n - delta})^2,h_athe arm,c_aits factor to unit noise gain andqthe symbol as the stages ahead of the bank deliver it, over every neighbornthe arm's window reaches, then referred to the group delay's instant. The arms are picked by truncating the phase: the identity is for a stream whose phase visits them evenly, as a steered loop's does. An unsteered stream whose terminal rate is exactly one stays on arm 0 and reads0.5 / (num_phases * bank_sps)` symbol less.

Use the sum. Where outputs land exactly on an arm boundary (33.65 input samples a symbol at one output a symbol, say) the group delay and this offset each depend on the build's rounding, in opposite directions (#3480); the eye's instant, get_group_delay() + data_eye * S, does not.

The value depends on num_phases, which sets the arms and how far a truncated phase falls past one: at 16 input samples a symbol and two outputs, the rectangle reads 0.0002 on 1024 arms and 0.0039 on 64. For the root-raised cosine it is not near zero: the group delay names the centroid of the arms' taps, which sits up to 0.026 symbol from the pulse's center (span 4). Its cost grows with the arms and the stages ahead of the bank (tens of milliseconds, about 0.7 s at 4096 samples a symbol on 4096 arms): read it once, when a detector is built, not on the data path.

Parameters:

  • s Must be non-NULL.

Returns:

The offset in symbols; NaN for a converter with no derivative table (dp_RateConverter_has_derivative() is 0), and when memory is refused.

dp_RateConverter_state_t *rc = dp_RateConverter_create_matched_scaled (
    2.0 / 16.0, 1, RC_PULSE_IANDD, 0.0, 1, 2.0, 1024, RC_ARM_UNIT_NOISE);
// two outputs a symbol behind a CIC: the data eye is the designed place
printf ("%d\n", fabs (dp_RateConverter_get_data_eye (rc)) < 0.001);  // 1
dp_RateConverter_destroy (rc);

function dp_RateConverter_get_full_scale

The input bound of this plan: a component at or beyond it is clipped.

double dp_RateConverter_get_full_scale (
    const dp_RateConverter_state_t * s
) 

Parameters:

Returns:

The CIC stage's full scale (dp_cic_get_full_scale()); infinity for a plan with no CIC stage, which is scale-free.


function dp_RateConverter_get_group_delay

The converter's group delay, in its INPUT samples: where in the input timeline an output sample's content sits.

double dp_RateConverter_get_group_delay (
    const dp_RateConverter_state_t * s
) 

Output k of a fresh stream that nothing steers carries the input at index k / rate - group_delay. The signal's delay, where get_count_lag() is the output count's: a caller putting the output against the input's own timeline a test that knows where a chip was transmitted and asks where it was received, or one converter's timing carried to another on the same input subtracts this.

It is the sum of each stage's own delay, in that stage's input samples, divided by the rate the stages before it have applied:

  • a halfband: dp_hbdecim_get_group_delay();
  • a CIC: dp_cic_get_group_delay(), and with its droop compensator the compensator's center, (taps - 1) / 2 CIC outputs;
  • a Resampler on a plain plan: dp_resamp_get_execute_delay();
  • a matched plan's terminal stage: one input (an output is formed before the sample offered with it loads) plus where the bank's content sits behind the newest loaded sample. That is read from the bank's taps as built each arm's centroid plus the arm's own lag, averaged over the arms a stream at this rate visits so the pulse, a truncated tail, the rectangle's interval-averaged edge taps and a folded droop compensator are all in it without a case for each. The arms of a real bank differ a little, so single outputs sit either side of the figure: by 0.02 of a terminal-stage input for a root-raised cosine of span 8 at 4 samples a symbol.

Every plan answers. On a matched plan the figure is execute()'s with no control applied; a loop steering the terminal stage moves the timing by what it has accumulated, which is that loop's to report.

Parameters:

  • s State. Must be non-NULL.

Returns:

The group delay in input samples.

dp_RateConverter_state_t *rc = dp_RateConverter_create (0.25, 0);
// two halfbands of 19 taps: 18 + 18 / 0.5
printf ("%.1f\n", dp_RateConverter_get_group_delay (rc));  // 54.0
dp_RateConverter_destroy (rc);


function dp_RateConverter_get_memory

The converter's memory, in its INPUT samples: how many inputs after create or reset until an output depends on nothing but the input.

double dp_RateConverter_get_memory (
    const dp_RateConverter_state_t * s
) 

Before that, an output still carries what the delay lines held at the start: zeros for the filters, and for a CIC the registers' own startup values, which come out as a burst near full scale (doppler#3365). A caller that measures the output (a power, an estimate, a level) starts after ceil (memory * rate) + 1 outputs.

It is the sum of each stage's own memory, in that stage's input samples, divided by the rate the stages before it have applied (a stage's input is clean only once the stages ahead of it are):

  • a halfband of N taps: 2 N - 1, the reach of its two delay lines;
  • a CIC of ratio R: CIC_N * (R - 1) + 1, the length of its response, and with its droop compensator that filter's (taps - 1) * R more;
  • a Resampler: its taps plus the one input an output is formed ahead of; on a plain plan that decimates, where the registers run at the output rate, that many OUTPUTS.

Parameters:

  • s State. Must be non-NULL.

Returns:

The memory in input samples.

dp_RateConverter_state_t *rc = dp_RateConverter_create (0.25, 0);
// two halfbands of 19 taps: 37 + 37 / 0.5
printf ("%.1f\n", dp_RateConverter_get_memory (rc));  // 111.0
dp_RateConverter_destroy (rc);


function dp_RateConverter_get_narrow_pulse

Is this converter's rectangular matched filter degenerately narrow?

bool dp_RateConverter_get_narrow_pulse (
    const dp_RateConverter_state_t * s
) 

True only for a matched cascade built with RC_PULSE_IANDD and pulse_sps < 4: the rectangle is exactly one symbol wide, so its matched filter is a 2-3 tap sum there. It works — it just barely opens the eye (measured on the timing loop this feeds, a lock statistic of -0.34 at two samples per symbol against +0.95 at four). The RRC spans many symbols and is never affected. Construction also raises a UserWarning.

Parameters:

Returns:

True for a narrow rectangular matched cascade; always false for a plain cascade (dp_RateConverter_create()) and for RRC.


function dp_RateConverter_get_rate

Get / set the output-to-input sample rate ratio. The setter rebuilds the entire cascade (new stage selection, new sub-objects) and resets all filter memories — equivalent to destroying and recreating with the new rate. A rate that is not finite and > 0 is refused and leaves the converter as it was.

double dp_RateConverter_get_rate (
    const dp_RateConverter_state_t * s
) 

>>> from doppler.resample import RateConverter
>>> rc = RateConverter(rate=0.5, compensate=0)
>>> rc.rate
0.5
>>> rc.rate = 2.0
>>> rc.rate
2.0

Parameters:

Returns:

Current output/input sample rate ratio.


function dp_RateConverter_get_state

Serialize s's active-stage state intoblob .

void dp_RateConverter_get_state (
    const dp_RateConverter_state_t * s,
    void * blob
) 

Parameters:


function dp_RateConverter_get_step

The input step of this plan: a component smaller than it reads zero.

double dp_RateConverter_get_step (
    const dp_RateConverter_state_t * s
) 

Parameters:

Returns:

The CIC stage's step (dp_cic_get_step()); 0 for a plan with no CIC stage.


function dp_RateConverter_has_derivative

Whether the converter carries the derivative bank the paired call reads: its tables were built (a matched converter's on an optimum kind) and attached to a fractional terminal stage.

int dp_RateConverter_has_derivative (
    const dp_RateConverter_state_t * s
) 

What a derivative-bank detector checks when it is built, and refuses to build on when 0.

Parameters:

  • s Must be non-NULL.

Returns:

1 or 0.


function dp_RateConverter_num_bank_shape

Terminal polyphase bank shape (backs the bank_shape property).

size_t dp_RateConverter_num_bank_shape (
    const dp_RateConverter_state_t * s
) 

The shape is the 2-element sequence (num_phases, num_taps) of the terminal Resampler stage's bank, and empty when the cascade ends in an integer decimator (HB / CIC), which has no polyphase bank.

Parameters:

Returns:

2 when the cascade ends in a Resampler stage, else 0.


function dp_RateConverter_num_stages

Number of planned cascade stages (backs the stages property).

size_t dp_RateConverter_num_stages (
    const dp_RateConverter_state_t * s
) 

Parameters:

Returns:

Active stage count, 1 to RC_MAX_STAGES. A failed dp_RateConverter_set_rate() leaves the old cascade in place, so it is never 0 on a live converter.


function dp_RateConverter_reset

Zero all sub-stage filter memories. Rate, stage count, and stage types are preserved. Processing from a reset state produces the same output as a freshly created converter fed the same input. Use between signal bursts to suppress transient artefacts from prior filter memory. An enabled AGC is reset too (back to unity gain with its detector at the reference), and the clip flag read by dp_RateConverter_get_clipped() is cleared with the CIC stages.

void dp_RateConverter_reset (
    dp_RateConverter_state_t * s
) 

Parameters:

>>> from doppler.resample import RateConverter
>>> rc = RateConverter(rate=0.5, compensate=0)
>>> rc.reset()
>>> rc.rate
0.5

function dp_RateConverter_response

What each of a run of outputs is, as a filter on the input: the plan's response, from the stages' definitions.

int dp_RateConverter_response (
    const dp_RateConverter_state_t * s,
    uint64_t k0,
    size_t n,
    double * h,
    int64_t * newest
) 

Output k of an unsteered stream from a fresh converter is and this writes h_k and newest_k for k = k0 .. k0 + n - 1. Nothing is run through the converter: the taps are the halfbands' coefficients, the CIC's CIC_N boxcars of R inputs, a droop compensator's taps and the terminal bank's arm, composed at the input's rate, and newest_k follows the instants each stage forms an output at and the terminal stage's own accumulator arithmetic. Each output has its own filter because each reads its own arm of the bank; at a whole decimation they are all one.

It is the linear response at the gains the stages have. It leaves out what is not linear or not there by default: a CIC's step and its clip (dp_RateConverter_get_step(), dp_RateConverter_get_full_scale()), single-precision rounding, and a pre-terminal AGC's gain (dp_RateConverter_enable_agc()).

What it is for: the noise at the output. White input noise of variance s2 comes out with covariance s2 * sum_j h_i[j] h_k[j + newest_k - newest_i] between outputs i and k, which is what a threshold on a statistic of the output is derived from.

Held by test_RateConverter_core.c (test_response): on eleven plans the outputs of a random input are the response's sums over that input.

Parameters:

Returns:

DP_OK; DP_ERR_INVALID for a plan with no matched terminal stage, or DP_ERR_MEMORY (nothing is written either way).

// the rectangle at 8 samples a symbol, to 4: a halfband, then the bank
dp_RateConverter_state_t *rc =
    dp_RateConverter_create_matched (4.0 / 8.0, 1, RC_PULSE_IANDD, 0.35, 8,
                                  4.0, 1024);
double  h[64];   // dp_RateConverter_response_len (rc) is 48
int64_t newest;
dp_RateConverter_response (rc, 100, 1, h, &newest);
printf ("%zu %lld\n", dp_RateConverter_response_len (rc),
        (long long)newest);   // 48 199
dp_RateConverter_destroy (rc);


function dp_RateConverter_response_len

Taps dp_RateConverter_response() writes for one output.

size_t dp_RateConverter_response_len (
    const dp_RateConverter_state_t * s
) 

Parameters:

  • s Must be non-NULL.

Returns:

The length of a matched plan's response at the converter's input rate; 0 for a plan with no matched terminal stage, which has no response here, and when memory is refused.


function dp_RateConverter_set_cic_headroom_bits

Set the headroom of every CIC stage this converter plans, and reset the converter.

int dp_RateConverter_set_cic_headroom_bits (
    dp_RateConverter_state_t * s,
    uint32_t bits
) 

dp_cic_set_headroom_bits() on each CIC stage, now and after any re-plan: full scale becomes 2^bits and the step doubles with each bit. dp_RateConverter_set_cic_precision() puts it back to the precision's own.

Parameters:

Returns:

DP_OK, or DP_ERR_INVALID with nothing changed.


function dp_RateConverter_set_cic_precision

Choose the input word of every CIC stage this converter plans, with that word's headroom, and reset the converter.

int dp_RateConverter_set_cic_precision (
    dp_RateConverter_state_t * s,
    uint32_t precision
) 

dp_cic_set_precision() on each CIC stage, now and after any re-plan (dp_RateConverter_set_rate()): CIC_PRECISION_16 is a 16-bit word at full scale CIC_PAPR_16, CIC_PRECISION_32 a 32-bit word and CIC_PRECISION_64, what a converter is built with, the widest the stage's registers have left, both at full scale CIC_PAPR_WIDE. A plan with no CIC stage keeps the setting for a re-plan that has one.

Parameters:

Returns:

DP_OK, or DP_ERR_INVALID with nothing changed.

>>> from doppler.resample import RateConverter
>>> rc = RateConverter(rate=1 / 64)
>>> rc.stages, rc.cic_precision, rc.full_scale
(['CIC(64)'], 64, 4.0)
>>> rc.cic_precision = 16
>>> rc.full_scale, rc.step
(2.0, 6.103515625e-05)
>>> RateConverter(rate=0.5).full_scale     # no CIC: no bound
inf


function dp_RateConverter_set_rate

Change the rate; rebuilds the cascade and resets all filter state. A matched cascade keeps its pulse and an enabled AGC survives (its reference is re-derived for the new terminal bank). The change is all or nothing: the new cascade (and AGC) is built first and committed only once it exists, so a refused rate or a failed rebuild leaves the converter exactly as it was same rate, same stages, same filter memory. That includes the AGC: one that cannot be rebuilt for the new bank refuses the whole change, where it used to be dropped and the rate taken anyway.

void dp_RateConverter_set_rate (
    dp_RateConverter_state_t * s,
    double rate
) 

The call returns nothing, so a caller that must know whether it took reads dp_RateConverter_get_rate() back. It becomes an int status, raised as ValueError from Python (error = "ValueError" on the property), once just-makeit#2406 is fixed: today a refusing property setter is documented under a synthetic C name on the MatchedRateConverter view, which the doc-face-parity gate rejects.

Parameters:


function dp_RateConverter_set_state

Restore active-stage state from blob (same rate).

int dp_RateConverter_set_state (
    dp_RateConverter_state_t * s,
    const void * blob
) 

Parameters:

  • s Converter with the same plan (rate, compensate, pulse, AGC on/off) as the one that wrote blob.
  • blob Blob from dp_RateConverter_get_state().

Returns:

DP_OK, or DP_ERR_INVALID if the blob's envelope or any stage's (or the AGC's) part rejects, or if the blob was taken at a rate other than s's (the rate is a reject key, checked before any stage is touched). Stages restore in order, so a later stage's refusal leaves the earlier ones restored until doppler#2104's transaction lands. Within a stage, a CIC stage restores its CIC before its compensator FIR, so a FIR refusal leaves the CIC restored; every other stage changes nothing it refuses.


function dp_RateConverter_set_telemetry

Attach (or detach) a telemetry context on the pre-terminal AGC.

int dp_RateConverter_set_telemetry (
    dp_RateConverter_state_t * s,
    dp_tlm_t * tlm,
    const char * prefix,
    uint32_t decim
) 

The cascade has no loop of its own to report — the stages are fixed filters — so this forwards to the one child that does: the pre-terminal AGC, under prefix verbatim. It registers that child's probes ("<prefix>.gain_db" and "<prefix>.level_db"; see dp_agc_set_telemetry()) and nothing else, which is why the prefix is not extended with a component name — there is no second thing here to disambiguate it from.

A composing object forwards its own prefix down: an mpsk_receiver attached as "rx" passes "rx.agc", and the receiver's gain trajectory joins its carrier and timing probes on one context.

With the AGC off (a plain cascade, or a matched one where dp_RateConverter_enable_agc() was never called) there is nothing to instrument and this is a successful no-op — DP_OK with no probes registered. That is deliberate: whether the AGC exists is the composing receiver's construction-time choice (agc = 0), and a caller attaching telemetry should not have to know which way that went to avoid an error.

The attachment is remembered as a REQUEST, so it survives the AGC being rebuilt by a rate change and is applied to an AGC enabled after the fact. One consequence of that: an attach made before the AGC exists reports DP_OK here, and if the probe table has filled by the time the AGC is built the probes are dropped without failing the build — signal processing does not fail because observation could not be set up. Attach after construction (which is what every composing object here does) and the return value covers it; otherwise check the context's probe names.

Setup path, never hot: call before the producer thread starts; the context is borrowed and must outlive the attachment (SPSC rules in dp_tlm/dp_tlm_core.h). Passing NULL detaches.

Parameters:

  • s Must be non-NULL.
  • tlm Telemetry context to attach, or NULL to detach.
  • prefix Probe-name prefix, e.g. "agc" or "rx.agc".
  • decim Emit every decim-th gain update; >= 1.

Returns:

DP_OK — including when no AGC is enabled — or DP_ERR_INVALID when the probe table cannot take the AGC's probes (the attach fails whole; the AGC stays detached), or when "<prefix>.gain_db" / "<prefix>.level_db" would not fit a probe name (checked before the request is recorded). A NULL prefix with a non-NULL tlm is treated as "agc".

dp_RateConverter_state_t *rc =
    dp_RateConverter_create_matched (2.0 / 8.0, 1, RC_PULSE_RRC, 0.35, 8,
                                  2.0, 1024);
dp_RateConverter_enable_agc (rc, 1e-4, 0.01);
dp_tlm_t *tlm = dp_tlm_create (1 << 12);
dp_RateConverter_set_telemetry (rc, tlm, "agc", 1);
dp_RateConverter_destroy (rc);
dp_tlm_destroy (tlm);

function dp_RateConverter_stage_label

Write a human-readable label for stage i into buf.

int dp_RateConverter_stage_label (
    dp_RateConverter_state_t * s,
    int i,
    char * buf,
    size_t len
) 

Examples: "HalfbandDecimator", "CIC(8)", "CIC(8)+FIR", "Resampler(0.8)".

Parameters:

  • s Must be non-NULL.
  • i Stage index in [0, s->n_stages).
  • buf Output buffer.
  • len Capacity of buf in bytes.

Returns:

1 on success, 0 if i is out of range.


function dp_RateConverter_stages_value

Label of stage i , e.g. "CIC(8)+FIR" or "Resampler(0.923,rrc)".

const char * dp_RateConverter_stages_value (
    const dp_RateConverter_state_t * s,
    size_t i
) 

Points at a per-thread scratch buffer valid until this thread's next call — the binding converts it to a Python string immediately. NULL if i is out of range.

Parameters:

Returns:

Borrowed pointer to a NUL-terminated label (do not free), or NULL.


function dp_RateConverter_state_bytes

Bytes dp_RateConverter_get_state() writes fors (envelope + rate + stages + the AGC's sub-blob when enabled).

size_t dp_RateConverter_state_bytes (
    const dp_RateConverter_state_t * s
) 

Depends on the current plan, so it changes with dp_RateConverter_set_rate() and dp_RateConverter_enable_agc().

Parameters:

Returns:

Blob size in bytes.


Macro Definition Documentation

define RC_ARM_SAMPLED

#define RC_ARM_SAMPLED `0`

The pulse sampled at each arm's lag: what dp_RateConverter_create_matched() builds, and what Gardner and the DTTL read (docs/design/ratesync-timing.md, 9.1). No ml_c or ml_dh.


define RC_ARM_SYMBOL

#define RC_ARM_SYMBOL `1`

The rectangle's optimum arm for each edge position, scaled to return the symbol: a unit symbol at the arm's designed position comes back as 1.


define RC_ARM_UNIT_NOISE

#define RC_ARM_UNIT_NOISE `2`

The rectangle's optimum arms scaled to unit noise gain, so |y|^2 peaks at the true timing (docs/design/ratesync-timing.md, "The arm's scale is part of the detector").


define RC_MAX_STAGES

#define RC_MAX_STAGES `3`

Maximum number of visible cascade stages.


define RC_STATE_MAGIC

#define RC_STATE_MAGIC `DP_FOURCC ('R', 'C', 'V', 'T')`

State-blob magic: FOURCC 'RCVT'.


define RC_STATE_VERSION

#define RC_STATE_VERSION `4u`

State-blob layout version; 2 adds the optional pre-terminal AGC part, 3 the rate reject key, 4 the word its CIC stages are given.



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