Skip to content

File ddc_core.h

FileList > ddc > ddc_core.h

Go to the source code of this file

Digital Down-Converter — composes LO + RateConverter cascade. More...

  • #include "doppler/dp_complex.h"
  • #include <stdbool.h>
  • #include <stddef.h>
  • #include <stdint.h>
  • #include "doppler/lo/lo_core.h"
  • #include "doppler/RateConverter/RateConverter_core.h"
  • #include "doppler/resamp/resamp_core.h"
  • #include "doppler/hbdecim/hbdecim_core.h"
  • #include "doppler/cic/cic_core.h"
  • #include "doppler/fir/fir_core.h"
  • #include "doppler/resample/resample_core.h"
  • #include "doppler/agc/agc_core.h"
  • #include "doppler/dp_tlm/dp_tlm_core.h"

Classes

Type Name
struct ddc_extra_t
DDC-specific blob header, written after the envelope and before the LO and RateConverter child blobs.
struct ddc_state
Ddc state — an LO and the cascade it feeds.

Public Types

Type Name
typedef struct ddc_state dp_ddc_state_t
Ddc state — an LO and the cascade it feeds.

Public Functions

Type Name
dp_ddc_state_t * dp_ddc_create (double norm_freq, double rate)
Create a complex-input Digital Down-Converter. Allocates internal state for the LO and RateConverter cascade. The RateConverter selects the cheapest multi-stage decimation chain (CIC + optional halfband + polyphase resampler) for the given rate.
dp_ddc_state_t * dp_ddc_create_matched (double norm_freq, double rate, int pulse, double beta, size_t span, double pulse_sps, size_t num_phases)
Create a DDC whose cascade's terminal stage IS a matched filter.
dp_ddc_state_t * dp_ddc_create_matched_scaled (double norm_freq, double rate, int pulse, double beta, size_t span, double pulse_sps, size_t num_phases, int arms)
dp_ddc_create_matched() , with the terminal stage's arm kind chosen.
void dp_ddc_destroy (dp_ddc_state_t * state)
Free all resources held by a DDC instance. Releases the RateConverter and LO substructures, then the struct itself. Passing NULL is a no-op.
size_t dp_ddc_execute (dp_ddc_state_t * state, const float _Complex * x, size_t x_len, float _Complex * out, size_t max_out)
Mix and resample a block of CF32 samples. Multiplies each input sample by the current LO phasor (advancing the NCO phase per sample), then feeds the mixed block into the RateConverter. The resampler maintains history across calls, so arbitrary block sizes produce contiguous output with no edge artefacts. Output length ≈ x_len * rate (varies by ±1 due to polyphase indexing).
size_t dp_ddc_execute_ctrl (dp_ddc_state_t * state, const float _Complex * x, size_t x_len, double rate_ctrl, double freq_ctrl, float _Complex * out, size_t max_out)
Mix and resample a block, steering both control ports.
size_t dp_ddc_execute_ctrl_max_out (dp_ddc_state_t * state, size_t x_len)
Maximum output samples one execute_ctrl() of x_len inputs can produce.
size_t dp_ddc_execute_ctrl_push (dp_ddc_state_t * state, float _Complex x, double rate_ctrl, double freq_ctrl, float _Complex * out, size_t max_out)
Push ONE input sample; emit whatever outputs it completes.
size_t dp_ddc_execute_ctrl_push_max_out (dp_ddc_state_t * state)
Output-buffer capacity for one execute_ctrl_push() call.
size_t dp_ddc_execute_ctrl_push_pair (dp_ddc_state_t * s, float _Complex x, double rate_ctrl, double freq_ctrl, float _Complex * out, float _Complex * dout, uint32_t * arm, double * cu, size_t max_out, float _Complex * lo_out, int * n_lo, float _Complex * pre_out, int * n_pre)
dp_ddc_execute_ctrl_push_tap2() , also returning each output's derivative-bank value, its arm and the factor to the unit-noise arm.
size_t dp_ddc_execute_ctrl_push_tap (dp_ddc_state_t * state, float _Complex x, double rate_ctrl, double freq_ctrl, float _Complex * out, size_t max_out, float _Complex * lo_out, int * n_lo)
dp_ddc_execute_ctrl_push() that also hands back the post-LO sample.
size_t dp_ddc_execute_ctrl_push_tap2 (dp_ddc_state_t * state, float _Complex x, double rate_ctrl, double freq_ctrl, float _Complex * out, size_t max_out, float _Complex * lo_out, int * n_lo, float _Complex * pre_out, int * n_pre)
dp_ddc_execute_ctrl_push_tap() , plus the PRE-TERMINAL tap.
size_t dp_ddc_execute_max_out (dp_ddc_state_t * state, size_t x_len)
Maximum output samples one execute() of x_len inputs can produce.
double dp_ddc_get_bank_sps (const dp_ddc_state_t * state)
Samples per symbol of the pre-terminal tap; a planner outcome.
bool dp_ddc_get_clipped (const dp_ddc_state_t * state)
Has the cascade's CIC clipped its input since the last reset?
bool dp_ddc_get_narrow_pulse (const dp_ddc_state_t * state)
Is this object's rectangular matched filter degenerately narrow?
double dp_ddc_get_norm_freq (const dp_ddc_state_t * state)
Return the current LO normalised frequency (cycles/sample).
double dp_ddc_get_rate (const dp_ddc_state_t * state)
Return the configured output/input rate ratio (read-only). The rate is fixed at create time; change it by destroying and recreating the DDC with the new value.
void dp_ddc_get_state (const dp_ddc_state_t * state, void * blob)
Serialize state's LO + RateConverter state intoblob .
int dp_ddc_has_derivative (const dp_ddc_state_t * s)
Whether the cascade carries the derivative bank dp_ddc_execute_ctrl_push_pair() reads.
void dp_ddc_reset (dp_ddc_state_t * state)
Zero LO phase and resampler history. After reset, the next execute call produces the same output as the first execute after create — useful for reproducible block-by-block processing or looped test fixtures. Also clears the cascade's sticky CIC clip flag (see dp_ddc_get_clipped() ). The configured norm_freq and rate are kept.
size_t dp_ddc_run (dp_ddc_state_t * state, const void * state_in, void * state_out, const float _Complex * in, size_t n_in, float _Complex * out, size_t max_out)
Pure run: (state_in, input) -> (state_out, output) ; either blob may be NULL (NULL in = current; NULL out = discard).
void dp_ddc_set_norm_freq (dp_ddc_state_t * state, double val)
Retune the LO without resetting phase or resampler history. Updates the NCO phase increment atomically so the carrier shift changes seamlessly across block boundaries. The resampler history and LO phase accumulator are left intact, avoiding the transient that a full reset would cause.
int dp_ddc_set_state (dp_ddc_state_t * state, const void * blob)
Restore LO + RateConverter state from blob .
int dp_ddc_set_telemetry (dp_ddc_state_t * state, dp_tlm_t * tlm, const char * prefix, uint32_t decim)
Attach (or detach) a telemetry context on the cascade's AGC.
size_t dp_ddc_state_bytes (const dp_ddc_state_t * state)
Byte size of state's blob (envelope + extra + lo + rc).

Macros

Type Name
define DDC_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('D', 'D', 'C', '\_')
Blob magic for a DDC state blob ("DDC_").
define DDC_STATE_VERSION 1u
Blob layout version for a DDC state blob.

Detailed Description

Two types:

Ddc — LO mix → RateConverter (the plain flavor) MatchedDDC — the same, with the pulse on the cascade's terminal stage

Streaming: any block size per execute call. The real-input twin lives in ddcr/ddcr_core.h (halfband R2C → LO mix → RateConverter); it is the same chain behind a real-to-complex front end.

RateConverter selects the cheapest cascade (CIC + optional halfband + polyphase resampler) for the requested rate at create time. This makes large-ratio decimation (e.g., 100:1) significantly cheaper than a single polyphase stage.

Ddc signal chain

CF32 in (fs_in)  →  LO mix  →  RateConverter  →  CF32 out (fs_out)

norm_freq: NCO normalised frequency (cycles/sample at fs_in). Set to -f_carrier to shift a carrier at f_carrier to DC.

Pulse and the two control ports

Both this type and its real-input twin have a matched flavor (dp_ddc_create_matched / dp_ddcr_create_matched), which is passed straight through to the cascade: the terminal stage carries a matched-filter bank instead of the default Kaiser one, so the chain mixes, decimates and matched-filters in the same dot products it was already doing (see dp_RateConverter_create_matched()).

That makes a DDC steerable on two ports, which are duals of each other:

freq_ctrl ──> LO phase accumulator      (carrier, at the INPUT rate)
rate_ctrl ──> terminal stage accumulator (timing, at the OUTPUT rate)

Both are per-input deviations added on top of the configured centre value for that sample only, so a tracking loop supplies its full filter output every time and the DDC holds no loop state. A receiver therefore closes a carrier loop and a timing loop with the same loop_filter, one per port — the object itself contains no loop.

The LO sits at the input rate (the intermediate rate fs_in/2 for DdcR), which is where predetection de-rotation belongs: the carrier is wiped off before any filter narrows the band around it.

Retuning vs. rebuilding

  • Retune (centre-frequency change): call dp_ddc_set_norm_freq / dp_ddcr_set_norm_freq. Cheap — updates the LO phase increment without disturbing the resampler history. Seamless across block boundaries.
  • Rate change (span / decimation change): destroy and recreate the DDC for the new rate.

Usage

// Complex DDC: shift a carrier at +0.1·fs to DC, decimate by 4
dp_ddc_state_t *ddc = dp_ddc_create(-0.1, 0.25);
float _Complex out[4096];
size_t n = dp_ddc_execute(ddc, in, 1024, out, 4096);
dp_ddc_destroy(ddc);

Public Types Documentation

typedef dp_ddc_state_t

Ddc state — an LO and the cascade it feeds.

typedef struct ddc_state dp_ddc_state_t;

Do not initialise directly; use dp_ddc_create() or dp_ddc_create_matched().


Public Functions Documentation

function dp_ddc_create

Create a complex-input Digital Down-Converter. Allocates internal state for the LO and RateConverter cascade. The RateConverter selects the cheapest multi-stage decimation chain (CIC + optional halfband + polyphase resampler) for the given rate.

dp_ddc_state_t * dp_ddc_create (
    double norm_freq,
    double rate
) 

Parameters:

  • norm_freq LO frequency in cycles/sample at the input rate. Set to -f_carrier to shift a carrier at f_carrier to DC. Any real value is accepted.
  • rate Output rate / input rate. Must be > 0. Values >= 1 are up-sampling; typical use is decimation (0 < rate < 1).

Returns:

A heap-allocated state owned by the caller (free it with dp_ddc_destroy()), or NULL when rate <= 0, when the RateConverter cannot plan the rate, or on OOM.

>>> from doppler.ddc import DDC
>>> ddc = DDC(norm_freq=-0.1, rate=0.25)
>>> ddc.norm_freq
-0.1
>>> ddc.rate
0.25

function dp_ddc_create_matched

Create a DDC whose cascade's terminal stage IS a matched filter.

dp_ddc_state_t * dp_ddc_create_matched (
    double norm_freq,
    double rate,
    int pulse,
    double beta,
    size_t span,
    double pulse_sps,
    size_t num_phases
) 

The matched flavor of the same object — same state, same methods, one different constructor (Python: MatchedDDC). The pulse is a straight passthrough to the cascade, so everything dp_RateConverter_create_matched() documents holds here unchanged: the terminal fractional stage always exists, the bank is sized by the POST-decimation rate, and the CIC droop folds into the bank rather than costing a stage. What this layer adds is the mix in front of it, and with it the second control port — dp_ddc_execute_ctrl() steers the matched filter's polyphase arm (timing) and the LO's phase accumulator (carrier) together.

Droop compensation is not a parameter because it is unconditional here: the fold is worth 28 dB of EVM for six taps per arm and no extra pass over the data, so no operating point wants it off. (The plain dp_ddc_create() path is unchanged and uncompensated.)

Parameters:

  • norm_freq LO frequency in cycles/sample at the input rate, as dp_ddc_create().
  • rate Output-to-input sample rate ratio. Rate-agnostic: a caller wanting m outputs per symbol asks for rate = m/sps; the cascade never learns about symbols.
  • pulse RC_PULSE_RRC / RC_PULSE_IANDD. RC_PULSE_NONE is invalid here — use dp_ddc_create() for a plain down-conversion.
  • 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 exactly one symbol).
  • pulse_sps The pulse's period in output samples (2 = two samples per symbol out).
  • num_phases Terminal-stage arms; a power of two. Sets the timing resolution to 1/num_phases of an output period.

Returns:

A heap-allocated state owned by the caller (free it with dp_ddc_destroy()), or NULL on a bad parameter (rate <= 0, pulse == RC_PULSE_NONE, or anything dp_RateConverter_create_matched() rejects) or on OOM.

>>> from doppler.ddc import MatchedDDC
>>> rx = MatchedDDC(norm_freq=-0.1, rate=2 / 16, pulse="rrc")
>>> rx.rate
0.125

function dp_ddc_create_matched_scaled

dp_ddc_create_matched() , with the terminal stage's arm kind chosen.

dp_ddc_state_t * dp_ddc_create_matched_scaled (
    double norm_freq,
    double rate,
    int pulse,
    double beta,
    size_t span,
    double pulse_sps,
    size_t num_phases,
    int arms
) 

The arm kind passes straight through to dp_RateConverter_create_matched_scaled(), and that function's documentation holds here unchanged. RC_ARM_SAMPLED is what dp_ddc_create_matched() builds, and Gardner and the DTTL read these arms. RC_ARM_SYMBOL and RC_ARM_UNIT_NOISE build the optimum arms with the derivative tables beside them, which a derivative-bank timing detector reads through dp_ddc_execute_ctrl_push_pair() (docs/design/ratesync-timing.md, 9.1). dp_ddcr_create_matched_scaled() is the real-input twin.

Parameters:

Returns:

As dp_ddc_create_matched(), and NULL for an arms that is none of the three.


function dp_ddc_destroy

Free all resources held by a DDC instance. Releases the RateConverter and LO substructures, then the struct itself. Passing NULL is a no-op.

void dp_ddc_destroy (
    dp_ddc_state_t * state
) 

Parameters:

  • state DDC to free, or NULL. Invalid after this call.
>>> from doppler.ddc import DDC
>>> ddc = DDC(norm_freq=0.0, rate=0.25)
>>> ddc.destroy()   # releases C memory immediately

function dp_ddc_execute

Mix and resample a block of CF32 samples. Multiplies each input sample by the current LO phasor (advancing the NCO phase per sample), then feeds the mixed block into the RateConverter. The resampler maintains history across calls, so arbitrary block sizes produce contiguous output with no edge artefacts. Output length ≈ x_len * rate (varies by ±1 due to polyphase indexing).

size_t dp_ddc_execute (
    dp_ddc_state_t * state,
    const float _Complex * x,
    size_t x_len,
    float _Complex * out,
    size_t max_out
) 

Parameters:

  • state Must be non-NULL.
  • x CF32 input block; accepted as float32 (auto-cast).
  • x_len Number of input samples (C-only, hidden from Python).
  • out CF32 output buffer (C-only, hidden from Python).
  • max_out Output buffer capacity (C-only, hidden from Python).

Returns:

Number of output samples written (C-only); 0 when x_len is 0 or the temporary mix buffer cannot be allocated.

>>> from doppler.ddc import DDC
>>> import numpy as np
>>> ddc = DDC(norm_freq=-0.1, rate=0.25)
>>> t = np.arange(4096)
>>> x = np.exp(1j * 2 * np.pi * 0.1 * t).astype(np.complex64)
>>> y = ddc.execute(x)
>>> y.shape
(1024,)
>>> y.dtype
dtype('complex64')
>>> round(float(abs(y[500])), 2)   # shifted to DC; amplitude ≈ 1
1.0

function dp_ddc_execute_ctrl

Mix and resample a block, steering both control ports.

size_t dp_ddc_execute_ctrl (
    dp_ddc_state_t * state,
    const float _Complex * x,
    size_t x_len,
    double rate_ctrl,
    double freq_ctrl,
    float _Complex * out,
    size_t max_out
) 

The control-port form of dp_ddc_execute(): the LO advances by phase_inc + freq_ctrl on every sample of this block, and the cascade's terminal stage runs at stage_rate + rate_ctrl. Neither deviation is persisted — the centre norm_freq and rate are untouched — so a tracking loop passes its full filter output on every call and the DDC holds no loop state of its own.

Feeding a stream through dp_ddc_execute_ctrl_push() one sample at a time reproduces this call bit-for-bit when both controls are held constant, so the cheap block form stays correct for open-loop use (a fixed Doppler offset, a rate trim) and the push form is what a closed loop uses.

Parameters:

  • state Must be non-NULL.
  • x CF32 input block.
  • x_len Number of input samples.
  • rate_ctrl Rate deviation added to the terminal Resampler stage's rate. Referenced to the terminal (post-decimation) rate, not the overall rate; ignored by a plan whose last stage is an integer HB/CIC with nothing to steer.
  • freq_ctrl Frequency deviation added to the LO, in cycles/sample at the INPUT rate (any sign).
  • out CF32 output buffer.
  • max_out Capacity of out in samples.

Returns:

Number of output samples written; 0 when x_len is 0 or the temporary mix buffer cannot be allocated.

>>> from doppler.ddc import DDC
>>> import numpy as np
>>> ddc = DDC(norm_freq=0.0, rate=0.25)   # LO centred at DC
>>> t = np.arange(4096)
>>> x = np.exp(1j * 2 * np.pi * 0.1 * t).astype(np.complex64)
>>> y = ddc.execute_ctrl(x, 0.0, -0.1)    # freq_ctrl steers +0.1 to DC
>>> y.shape
(1024,)
>>> round(float(abs(y[100:].mean())), 2)  # settled output sits at DC
1.0

function dp_ddc_execute_ctrl_max_out

Maximum output samples one execute_ctrl() of x_len inputs can produce.

size_t dp_ddc_execute_ctrl_max_out (
    dp_ddc_state_t * state,
    size_t x_len
) 

Same bound as dp_ddc_execute_max_out(): the binding sizes its output buffer from it and resizes down to the actual count.

Parameters:

  • state Unused; may be any instance.
  • x_len Number of input samples the matching call sees.

Returns:

x_len.


function dp_ddc_execute_ctrl_push

Push ONE input sample; emit whatever outputs it completes.

size_t dp_ddc_execute_ctrl_push (
    dp_ddc_state_t * state,
    float _Complex x,
    double rate_ctrl,
    double freq_ctrl,
    float _Complex * out,
    size_t max_out
) 

The per-input streaming form of dp_ddc_execute_ctrl(), and the only form a closed loop can use: a block call has to know its whole control history up front, whereas a carrier or timing loop computes each correction from the outputs already emitted. Both loops close once per symbol, so both ports need this form.

The mix costs one LO step per input; the cascade then emits 0 outputs (the common decimating case, between strobes), 1, or several.

Parameters:

  • state Must be non-NULL.
  • x One CF32 input sample.
  • rate_ctrl Rate deviation for this input (terminal-stage rate).
  • freq_ctrl Frequency deviation for this input, cycles/sample at the input rate.
  • out Output buffer for any emitted samples.
  • max_out Capacity of out (emission stops at this bound).

Returns:

Number of outputs written (0, 1, or more).

>>> from doppler.ddc import DDC
>>> import numpy as np
>>> ddc = DDC(norm_freq=-0.1, rate=0.25)
>>> t = np.arange(64)
>>> x = np.exp(1j * 2 * np.pi * 0.1 * t).astype(np.complex64)
>>> outs = [ddc.execute_ctrl_push(complex(s), 0.0, 0.0) for s in x]
>>> int(sum(len(o) for o in outs))   # 64 inputs, rate 1/4 -> 16 outs
16
>>> [len(o) for o in outs[:4]]        # 0 outs until a strobe completes
[0, 0, 0, 1]

function dp_ddc_execute_ctrl_push_max_out

Output-buffer capacity for one execute_ctrl_push() call.

size_t dp_ddc_execute_ctrl_push_max_out (
    dp_ddc_state_t * state
) 

A single input completes at most ceil(rate) + 1 output periods; the binding has no input block to size from, so it uses this fixed bound.

Parameters:

  • state Must be non-NULL.

Returns:

(size_t)max(rate, 1.0) + 2 samples.


function dp_ddc_execute_ctrl_push_pair

dp_ddc_execute_ctrl_push_tap2() , also returning each output's derivative-bank value, its arm and the factor to the unit-noise arm.

size_t dp_ddc_execute_ctrl_push_pair (
    dp_ddc_state_t * s,
    float _Complex x,
    double rate_ctrl,
    double freq_ctrl,
    float _Complex * out,
    float _Complex * dout,
    uint32_t * arm,
    double * cu,
    size_t max_out,
    float _Complex * lo_out,
    int * n_lo,
    float _Complex * pre_out,
    int * n_pre
) 

The front end ahead of the cascade is the tap call's, verbatim: one body serves both. The cascade's part is dp_RateConverter_execute_ctrl_push_pair(). out is bit for bit the tap call's output, and dout, arm and cu are as that call documents. A derivative-bank detector forms Re{ conj(cu y) dy } from them and holds no table of its own. A front end with no derivative table (dp_ddc_has_derivative() is 0) writes 0 to dout and cu. dp_ddcr_execute_ctrl_push_pair() is the real-input twin.

Parameters:

Returns:

Number of terminal outputs written.


function dp_ddc_execute_ctrl_push_tap

dp_ddc_execute_ctrl_push() that also hands back the post-LO sample.

size_t dp_ddc_execute_ctrl_push_tap (
    dp_ddc_state_t * state,
    float _Complex x,
    double rate_ctrl,
    double freq_ctrl,
    float _Complex * out,
    size_t max_out,
    float _Complex * lo_out,
    int * n_lo
) 

Identical in every respect, plus a tap on the signal between the mix and the cascade — de-rotated, but not yet decimated or matched-filtered.

The tap exists because a carrier discriminator's unambiguous frequency range is set by the rate it UPDATES at: an M-th-power detector running at rate F can only see |df| < F/(2M). Take it from the terminal stage's on-time strobe and that rate is the symbol rate, which is the cleanest possible input and the narrowest possible pull-in. Take it here and the rate is the full input rate — sps times wider — at the cost of no matched filtering, so a caller wanting SNR back must run its own arm filter over this stream. That trade is the caller's to make, which is why this is a tap rather than a mode.

Parameters:

  • state Must be non-NULL.
  • x One CF32 input sample.
  • rate_ctrl Rate deviation for this input (terminal-stage rate).
  • freq_ctrl Frequency deviation for this input, cycles/sample at the input rate.
  • out Output buffer for any emitted outputs.
  • max_out Capacity of out (emission stops at this bound).
  • lo_out Receives the post-LO, pre-cascade sample when n_lo comes back 1. May be NULL.
  • n_lo Receives 1 (this front end mixes every input, so always 1 here; the real-input twin gates on its halfband and can return 0). May be NULL.

Returns:

Number of terminal outputs written (0, 1, or more).


function dp_ddc_execute_ctrl_push_tap2

dp_ddc_execute_ctrl_push_tap() , plus the PRE-TERMINAL tap.

size_t dp_ddc_execute_ctrl_push_tap2 (
    dp_ddc_state_t * state,
    float _Complex x,
    double rate_ctrl,
    double freq_ctrl,
    float _Complex * out,
    size_t max_out,
    float _Complex * lo_out,
    int * n_lo,
    float _Complex * pre_out,
    int * n_pre
) 

Two taps, at the two points a carrier discriminator can read without symbol timing, and they are not equivalent:

tap where cost
lo_out post-LO, pre-cascade full input noise BW
pre_out post-cascade, post-AGC, pre-MF none of the above

pre_out is the better-conditioned of the two for the reasons docs/design/mpsk.md §3.3 gives: the cascade's own filters have already band-limited it and the AGC has already levelled it, so a half-symbol arm filter bolted onto lo_out is a hand-rolled approximation of what this node gives for free. Its rate is dp_ddc_get_bank_sps() samples per symbol.

Note:

"Better conditioned" is not "more accurate", and the distinction is measured rather than assumed. The retired tap sweep found no residual-frequency-error advantage for this node over the symbol-rate strobe — three taps carrying one loop bandwidth over one signal settle to the same jitter. What it buys is a usable discriminator with no symbol timing and no arm filter; see doppler#766 for the pull-in-range question that would actually separate them.

Parameters:

  • state Must be non-NULL.
  • x One CF32 input sample.
  • rate_ctrl Rate deviation for this input (terminal-stage rate).
  • freq_ctrl Frequency deviation for this input, cycles/sample at the input rate.
  • out Output buffer for any emitted outputs.
  • max_out Capacity of out (emission stops at this bound).
  • lo_out Receives the post-LO, pre-cascade sample when n_lo comes back 1. May be NULL.
  • n_lo Receives 1 (this front end mixes every input, so always 1 here). May be NULL.
  • pre_out Receives the pre-terminal sample; may be NULL.
  • n_pre Receives 1 if pre_out was written, else 0; may be NULL. A non-terminal stage swallows inputs between its decimation strobes, so this is 0 on those calls.

Returns:

Number of terminal outputs written (0, 1, or more).


function dp_ddc_execute_max_out

Maximum output samples one execute() of x_len inputs can produce.

size_t dp_ddc_execute_max_out (
    dp_ddc_state_t * state,
    size_t x_len
) 

A DDC decimates (or passes at unity), so the output never exceeds the input length: returns x_len. The binding sizes the output buffer to this per-call bound and resizes down to the actual count (gh-607).

Parameters:

  • state Must be non-NULL.
  • x_len Number of input samples the matching execute() call sees.

Returns:

x_len (a safe upper bound on the produced samples).


function dp_ddc_get_bank_sps

Samples per symbol of the pre-terminal tap; a planner outcome.

double dp_ddc_get_bank_sps (
    const dp_ddc_state_t * state
) 

Forwarded from dp_RateConverter_get_bank_sps(): the symbol period on the terminal stage's input grid, pulse_sps / terminal_stage_rate, fixed at construction. This is the rate of the pre_out tap of dp_ddc_execute_ctrl_push_tap2().

Parameters:

  • state Must be non-NULL.

Returns:

Samples per symbol at the pre-terminal node for the matched flavor; 0.0 for the plain flavor, which has no pulse.


function dp_ddc_get_clipped

Has the cascade's CIC clipped its input since the last reset?

bool dp_ddc_get_clipped (
    const dp_ddc_state_t * state
) 

Forwarded from dp_RateConverter_get_clipped(): a CIC bounds its input to its full scale (CIC_PAPR_WIDE as built, 12 dB above unity — see cic_core.h) and clips silently at and past it — the output stays finite and plausible, merely distorted, at a cost of ~25 dB of EVM that no downstream metric attributes to the front end. Sticky until dp_ddc_reset(); always false for a plan with no CIC stage, which is the honest answer since those plans are scale-free.

Parameters:

  • state Must be non-NULL.

Returns:

true if any CIC input sample has been clipped since create or the last dp_ddc_reset(); false otherwise.


function dp_ddc_get_narrow_pulse

Is this object's rectangular matched filter degenerately narrow?

bool dp_ddc_get_narrow_pulse (
    const dp_ddc_state_t * state
) 

True only for the matched flavor built with pulse = RC_PULSE_IANDD and fewer than four output samples per symbol: 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, so this is the pull half of the same diagnostic.

Parameters:

  • state Must be non-NULL.

Returns:

true when the matched flavor has pulse == RC_PULSE_IANDD and pulse_sps < 4; false otherwise (always false for the plain flavor). Fixed at construction.


function dp_ddc_get_norm_freq

Return the current LO normalised frequency (cycles/sample).

double dp_ddc_get_norm_freq (
    const dp_ddc_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

The LO centre frequency in cycles/sample at the input rate, as last set by create or dp_ddc_set_norm_freq(). Per-call freq_ctrl deviations are never folded in.

>>> from doppler.ddc import DDC
>>> ddc = DDC(norm_freq=-0.1, rate=0.25)
>>> ddc.norm_freq
-0.1

function dp_ddc_get_rate

Return the configured output/input rate ratio (read-only). The rate is fixed at create time; change it by destroying and recreating the DDC with the new value.

double dp_ddc_get_rate (
    const dp_ddc_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

The output/input sample-rate ratio passed at create time.

>>> from doppler.ddc import DDC
>>> ddc = DDC(norm_freq=0.0, rate=0.25)
>>> ddc.rate
0.25

function dp_ddc_get_state

Serialize state's LO + RateConverter state intoblob .

void dp_ddc_get_state (
    const dp_ddc_state_t * state,
    void * blob
) 

Parameters:

  • state Must be non-NULL; not modified.
  • blob Caller-owned buffer of at least dp_ddc_state_bytes() bytes.

function dp_ddc_has_derivative

Whether the cascade carries the derivative bank dp_ddc_execute_ctrl_push_pair() reads.

int dp_ddc_has_derivative (
    const dp_ddc_state_t * s
) 

Forwarded from dp_RateConverter_has_derivative(). A derivative-bank detector checks this when it is built.

Parameters:

  • s Must be non-NULL.

Returns:

1 or 0.


function dp_ddc_reset

Zero LO phase and resampler history. After reset, the next execute call produces the same output as the first execute after create — useful for reproducible block-by-block processing or looped test fixtures. Also clears the cascade's sticky CIC clip flag (see dp_ddc_get_clipped() ). The configured norm_freq and rate are kept.

void dp_ddc_reset (
    dp_ddc_state_t * state
) 

Parameters:

  • state Must be non-NULL.
>>> from doppler.ddc import DDC
>>> import numpy as np
>>> ddc = DDC(norm_freq=0.0, rate=0.25)
>>> x = np.ones(64, dtype=np.complex64)
>>> y1 = ddc.execute(x)
>>> ddc.reset()
>>> y2 = ddc.execute(x)
>>> bool(np.array_equal(y1, y2))
True

function dp_ddc_run

Pure run: (state_in, input) -> (state_out, output) ; either blob may be NULL (NULL in = current; NULL out = discard).

size_t dp_ddc_run (
    dp_ddc_state_t * state,
    const void * state_in,
    void * state_out,
    const float _Complex * in,
    size_t n_in,
    float _Complex * out,
    size_t max_out
) 

Restores state_in into state (when non-NULL), runs dp_ddc_execute(), then exports the resulting state to state_out (when non-NULL).

Parameters:

  • state Must be non-NULL; the working instance.
  • state_in Blob to restore first, or NULL to keep the current state.
  • state_out Buffer of dp_ddc_state_bytes() bytes that receives the post-run state, or NULL to discard it.
  • in CF32 input block.
  • n_in Number of input samples.
  • out CF32 output buffer.
  • max_out Capacity of out in samples.

Returns:

Number of output samples written; 0 (and nothing run) when state_in is rejected by dp_ddc_set_state().


function dp_ddc_set_norm_freq

Retune the LO without resetting phase or resampler history. Updates the NCO phase increment atomically so the carrier shift changes seamlessly across block boundaries. The resampler history and LO phase accumulator are left intact, avoiding the transient that a full reset would cause.

void dp_ddc_set_norm_freq (
    dp_ddc_state_t * state,
    double val
) 

Parameters:

  • state Must be non-NULL.
  • val New normalised frequency (cycles/sample at input rate).
>>> from doppler.ddc import DDC
>>> ddc = DDC(norm_freq=-0.1, rate=0.25)
>>> ddc.norm_freq = -0.2
>>> ddc.norm_freq
-0.2

function dp_ddc_set_state

Restore LO + RateConverter state from blob .

int dp_ddc_set_state (
    dp_ddc_state_t * state,
    const void * blob
) 

Parameters:

  • state Must be non-NULL; built with the same rate (and the same flavor/pulse) as the instance that wrote blob.
  • blob Blob written by dp_ddc_get_state().

Returns:

DP_OK, or DP_ERR_INVALID if the envelope/rate rejects.


function dp_ddc_set_telemetry

Attach (or detach) a telemetry context on the cascade's AGC.

int dp_ddc_set_telemetry (
    dp_ddc_state_t * state,
    dp_tlm_t * tlm,
    const char * prefix,
    uint32_t decim
) 

Forwarded verbatim to dp_RateConverter_set_telemetry(): the mixer and the fixed stages have no loop to report, so the one instrumented child is the cascade's pre-terminal AGC ("<prefix>.gain_db" and "<prefix>.level_db"). DP_OK with no probes when the cascade has no AGC enabled. Setup path, never hot; the context is borrowed and must outlive the attachment.

Parameters:

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

Returns:

DP_OK, or DP_ERR_INVALID when the probe table cannot take the AGC's probes (the attach fails whole).


function dp_ddc_state_bytes

Byte size of state's blob (envelope + extra + lo + rc).

size_t dp_ddc_state_bytes (
    const dp_ddc_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

Size in bytes of the buffer dp_ddc_get_state() writes and dp_ddc_set_state() expects; fixed for a given construction.


Macro Definition Documentation

define DDC_STATE_MAGIC

Blob magic for a DDC state blob ("DDC_").

#define DDC_STATE_MAGIC `DP_FOURCC ('D', 'D', 'C', '_')`


define DDC_STATE_VERSION

Blob layout version for a DDC state blob.

#define DDC_STATE_VERSION `1u`



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