File carrier_acq_core.h¶
FileList > carrier_acq > carrier_acq_core.h
Go to the source code of this file
CarrierAcquisition — PSDMF residual-carrier frequency refinement. More...
#include "doppler/clib_common.h"#include "doppler/dp_state.h"#include "doppler/jm_perf.h"#include "doppler/psd/psd_core.h"#include "doppler/detection/detection_core.h"#include "doppler/spectral/spectral_core.h"#include "doppler/correlator/correlator_core.h"#include "doppler/fft/fft_core.h"#include "doppler/acc_trace/acc_trace_core.h"#include "doppler/dp_tlm/dp_tlm_core.h"
Classes¶
| Type | Name |
|---|---|
| struct | carrier_acq_tlm_t Telemetry attachment: a borrowed context and this object's probe ids. NULL ctx (the default) means detached: every probe site is one predicted-not-taken branch per tested block. Not part of the state blob, and kept across reset() and set_state(). |
| struct | dp_carrier_acq_state_t CarrierAcquisition state: owned PSD and detector children, scratch, config and the running detection result. |
Public Functions¶
| Type | Name |
|---|---|
| dp_carrier_acq_state_t * | dp_carrier_acq_create (double sample_rate_hz, double symbol_rate_hz, double resolution_hz, size_t zero_pad, int window, float beta, const float * psd_template, size_t psd_template_len, double pfa, double pd, double design_snr, bool sequential, size_t max_n_blocks) Create a PSD-template carrier acquisition (residual-carrier detector and estimator). |
| void | dp_carrier_acq_destroy (dp_carrier_acq_state_t * state) Destroy a carrier_acq instance and release all memory. |
| void | dp_carrier_acq_get_state (const dp_carrier_acq_state_t * state, void * blob) Serialize the running state into a caller-owned blob. |
| void | dp_carrier_acq_reset (dp_carrier_acq_state_t * state) Reset to the post-create state: discard the running PSD average and detection state; n_blocks/ready/residual_hz return to their initial values. Config (psd/detector/dwell_target) is untouched. |
| int | dp_carrier_acq_set_state (dp_carrier_acq_state_t * state, const void * blob) Restore the running state from a dp_carrier_acq_get_state() blob. |
| int | dp_carrier_acq_set_telemetry (dp_carrier_acq_state_t * state, dp_tlm_t * tlm, const char * prefix, uint32_t decim) Attach (or detach) a telemetry context and register the estimator's probes on it. |
| size_t | dp_carrier_acq_state_bytes (const dp_carrier_acq_state_t * state) Size of this instance's serialized state blob. |
| void | dp_carrier_acq_steps (dp_carrier_acq_state_t * state, const float _Complex * x, size_t x_len) Fold raw complex samples into the running PSD average and test for a detection. Accepts any chunk size across repeated calls a partial trailing block is carried to the next call. A no-op once ready is true or the give-up cap (max_n_blocks in sequential mode, dwell_target otherwise) has been reached. |
Macros¶
| Type | Name |
|---|---|
| define | CARRIER_ACQ_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc)('C', 'A', 'Q', 'R')State-blob magic ("CAQR"); set_state() rejects any other. |
| define | CARRIER_ACQ_STATE_VERSION 2uState-blob layout version; bumped when the payload changes. Version 2: the nested detector blob is the one correlator's 'CORL', in its 1-D detector flavor (#2752 steps 3.2 and 3.3, between which no release was cut, so 3.3's change rides the same unreleased version). |
Detailed Description¶
Runs AFTER Acquisition's own coarse Doppler search, as a one-shot matched-filter refinement stage: feed the already-despread symbol-rate stream via steps(), and once enough non-coherent looks have accumulated to cross a Pfa/Pd-driven detection threshold, ready becomes true and residual_hz holds the sub-bin-refined residual carrier estimate, Hz.
Composes existing primitives rather than reimplementing them:
- dp_psd_state_t: FFT + window + zero-pad + non-coherent power averaging (Welch's method) the entire "measure the average power spectrum of what's coming in" half of the algorithm.
- the correlator's 1-D detector flavor (dp_correlator_create_detector_1d()): FFT-based circular correlation of the averaged power spectrum against a known template (the average PSD shape of a random rectangular-pulse BPSK symbol stream by default, or a caller-supplied override for a different pulse/modulation) plus a noise-referenced test statistic and argmax lag.
- detection_core's dp_det_n_noncoh()/dp_det_threshold(): det_n_noncoh (the same chi-square statistic Acquisition's own auto-config uses) drives the precomputed fixed-dwell/give-up cap; det_threshold (sqrt(-2*ln(pfa))) is reused as the tail-quantile stand-in inside the per-block CFAR ratio threshold below.
The per-block CFAR ratio threshold is NOT dp_det_threshold_noncoherent() (that statistic a classic complex-correlator peak/noise envelope ratio does not transfer to this object's real statistic, a power-spectrum-vs-known-template correlation; confirmed via Monte Carlo, ~5x too conservative). carrier_acq_ratio_threshold() (carrier_acq_core.c) instead uses the derived H0 model for this specific statistic (an exact Gamma-sum mean/variance for the averaged, template-correlated periodogram) plus ONE empirically-calibrated tail-inflation constant (kappa, standing in for the argmax-over-nfft-correlated-lags extreme- value quantile a full closed form hasn't cleanly reduced to yet see FINISHING_PLAN.md's CarrierAcquisition section / the derive_carrier_acq_statistic.py derivation for the full story, and revisit/refine kappa when time allows).
Only the default template generator (a sinc^2 shape, DC-centred to match dp_psd_power_twosided()'s own bin order) and the 3-point parabolic sub-bin peak refinement (read directly off the detector's own det_out, the map of the dump that fired no second correlation pass needed) are new leaf code.
Lifecycle: create -> steps()* -> (ready ? residual_hz : keep feeding) -> reset()/destroy
dp_carrier_acq_state_t *ca = dp_carrier_acq_create(
4.092e6, 100e3, 0.0, 4, DP_PSD_WINDOW_HANN, 0.0f, NULL, 0, 1e-3, 0.9,
2.0, true, 100000);
while (!ca->ready && ca->n_blocks < ca->max_n_blocks)
dp_carrier_acq_steps(ca, block, block_len);
double hz = ca->residual_hz; // valid only when ca->ready
dp_carrier_acq_destroy(ca);
Public Functions Documentation¶
function dp_carrier_acq_create¶
Create a PSD-template carrier acquisition (residual-carrier detector and estimator).
dp_carrier_acq_state_t * dp_carrier_acq_create (
double sample_rate_hz,
double symbol_rate_hz,
double resolution_hz,
size_t zero_pad,
int window,
float beta,
const float * psd_template,
size_t psd_template_len,
double pfa,
double pd,
double design_snr,
bool sequential,
size_t max_n_blocks
)
In C the window is DP_PSD_WINDOW_HANN, DP_PSD_WINDOW_KAISER or DP_PSD_WINDOW_BLACKMAN_HARRIS; any other, the rectangular window included, returns NULL.
Parameters:
sample_rate_hzSample rate of the input stream, Hz (required).symbol_rate_hzSymbol rate, Hz builds the default template (required).resolution_hzDesired FFT frequency resolution, Hz. <= 0.0 is a sentinel meaning "auto": symbol_rate_hz/10.0. The block is round(sample_rate_hz/resolution_hz) samples, floored at 3 a block of 1 or 2 gives no usable estimate (#1959).zero_padPSD zero-pad factor (>= 1); see psd_core.h.window"hann" (the default, and the window the threshold was fit at), "kaiser" or "blackman-harris".betaKaiser beta (ignored for hann/blackman-harris).psd_templateKnown PSD-shape template override, length must equal nfft = next_pow_two(block * zero_pad), block as above; NULL/length-0 means "not supplied" the default rectangular-pulse sinc^2 template (from symbol_rate_hz) is used.psd_template_lenLength ofpsd_template(0 if not supplied).pfaTarget per-test false-alarm probability.pdTarget detection probability.design_snrAssumed per-sample amplitude SNR used ONLY to precompute dwell_target via dp_det_n_noncoh(); not a live measurement. An optimistic guess only affects NON-sequential mode (which trusts this one-shot wait count outright) sequential mode's own give-up bound is max_n_blocks, not dwell_target, precisely so a wrong design_snr can't stop it from trying more blocks once real data shows it needs to.sequentialTrue: test for a detection after EVERY block (the per-block CFAR ratio threshold see carrier_acq_ratio_threshold() in carrier_acq_core.c tightens as more looks accumulate), stopping the moment one fires or max_n_blocks is reached. False: accumulate silently and test once, at dwell_target.max_n_blocksSequential mode's own give-up cap (ignored by non-sequential mode, which stops at dwell_target instead) deliberately a SEPARATE, generous bound from dwell_target; capping sequential mode at design_snr's own point estimate would defeat the reason to test every block in the first place.
Returns:
Heap-allocated state, or NULL on invalid argument or allocation failure.
Note:
Caller must call dp_carrier_acq_destroy() when done.
>>> import numpy as np
>>> from doppler.acquire import CarrierAcquisition
>>> rng = np.random.default_rng(12345)
>>> bits = np.where(rng.integers(0, 2, 4000), 1.0, -1.0)
>>> data = np.repeat(bits, 8) # 8 samples/symbol BPSK
>>> t = np.arange(len(data))
>>> x = (data * np.exp(2j * np.pi * 123.0 * t / 8000.0)).astype(
... np.complex64) # residual carrier at 123 Hz
>>> ca = CarrierAcquisition(
... sample_rate_hz=8000.0, symbol_rate_hz=1000.0,
... psd_template=np.array([], dtype=np.float32))
>>> ca.steps(x) # fold the stream, testing each block
>>> ca.ready # detection fired
True
>>> round(ca.residual_hz, 0) # recovered residual carrier, Hz
123.0
function dp_carrier_acq_destroy¶
Destroy a carrier_acq instance and release all memory.
Parameters:
stateMay be NULL.
function dp_carrier_acq_get_state¶
Serialize the running state into a caller-owned blob.
Parameters:
stateInstance to snapshot (non-NULL).blobDestination of at least dp_carrier_acq_state_bytes() bytes.
function dp_carrier_acq_reset¶
Reset to the post-create state: discard the running PSD average and detection state; n_blocks/ready/residual_hz return to their initial values. Config (psd/detector/dwell_target) is untouched.
Use it to reuse one detector across successive captures: after a detection (or a give-up) the running average and counters are cleared, so the next steps() starts folding a fresh stream from zero.
Parameters:
stateMust be non-NULL.>>> import numpy as np >>> from doppler.acquire import CarrierAcquisition >>> ca = CarrierAcquisition( ... sample_rate_hz=8000.0, symbol_rate_hz=1000.0, ... psd_template=np.array([], dtype=np.float32)) >>> ca.steps(np.zeros(2048, dtype=np.complex64)) # accumulate looks >>> ca.n_blocks > 0 True >>> ca.reset() # discard the running PSD average >>> ca.n_blocks 0
function dp_carrier_acq_set_state¶
Restore the running state from a dp_carrier_acq_get_state() blob.
The instance must have been created with the same configuration as the one that produced the blob (see the block comment above).
Parameters:
stateInstance to overwrite (non-NULL).blobBlob of dp_carrier_acq_state_bytes() bytes.
Returns:
DP_OK on success; DP_ERR_INVALID when the envelope does not match, nfft / dwell_target / max_n_blocks differ from this instance, carry_len >= psd->k.n, residual_hz is NaN or beyond +/- sample_rate_hz/2, or a child blob is rejected. A child rejection can leave the psd child already restored.
function dp_carrier_acq_set_telemetry¶
Attach (or detach) a telemetry context and register the estimator's probes on it.
int dp_carrier_acq_set_telemetry (
dp_carrier_acq_state_t * state,
dp_tlm_t * tlm,
const char * prefix,
uint32_t decim
)
Five probes, emitted once per TESTED block every block in sequential mode, once at dwell_target otherwise and thinned by decim: * "<prefix>.stat": the test statistic the decision compares, the correlator's peak over its noise estimate (dimensionless); * "<prefix>.thr": the threshold it was compared against at this block count (the ratio a detection must exceed; it falls as blocks accrue); * "<prefix>.hz": the frequency of the correlation peak, Hz, refined to a sub-bin as the decision's residual_hz is so on the block that decides, it IS residual_hz; * "<prefix>.n": blocks folded so far (n_blocks); * "<prefix>.ready": the decision, 0 or 1.
A dwell that reaches its give-up cap without deciding shows as a last record with ".ready" 0 at ".n" equal to the cap. Setup path, never hot; the context is borrowed and must outlive the attachment (SPSC rules in dp_tlm/dp_tlm_core.h). Passing NULL detaches.
Parameters:
stateMust be non-NULL.tlmTelemetry context to attach, or NULL to detach.prefixProbe-name prefix; NULL means "ca".decimEmit every decim-th tested block; >= 1.
Returns:
DP_OK, or DP_ERR_INVALID on decim 0, a prefix too long for a probe's name, or a probe table without room for all five (the attach fails whole; the object stays as it was).
>>> import numpy as np
>>> from doppler.acquire import CarrierAcquisition
>>> from doppler.telemetry import Telemetry
>>> tlm = Telemetry(1 << 12)
>>> ca = CarrierAcquisition(
... sample_rate_hz=8000.0, symbol_rate_hz=1000.0,
... psd_template=np.array([], dtype=np.float32))
>>> ca.set_telemetry(tlm, "ca")
>>> sorted(tlm.probe_names)
['ca.hz', 'ca.n', 'ca.ready', 'ca.stat', 'ca.thr']
>>> rng = np.random.default_rng(12345)
>>> bits = np.where(rng.integers(0, 2, 4000), 1.0, -1.0)
>>> data = np.repeat(bits, 8)
>>> t = np.arange(len(data))
>>> ca.steps((data * np.exp(2j * np.pi * 123.0 * t / 8000.0)).astype(
... np.complex64))
>>> recs = tlm.read() # five records per tested block
>>> len(recs) % 5
0
>>> name = {i: n for n, i in tlm.probe_names.items()}
>>> last = {name[int(r["probe"])]: float(r["value"]) for r in recs[-5:]}
>>> last["ca.ready"], round(last["ca.hz"]), last["ca.stat"] > last["ca.thr"]
(1.0, 123, True)
function dp_carrier_acq_state_bytes¶
Size of this instance's serialized state blob.
Parameters:
stateInstance to size (non-NULL).
Returns:
Bytes: envelope + own running fields + the psd and detector child blobs + a fixed carry region of psd->k.n samples.
function dp_carrier_acq_steps¶
Fold raw complex samples into the running PSD average and test for a detection. Accepts any chunk size across repeated calls a partial trailing block is carried to the next call. A no-op once ready is true or the give-up cap (max_n_blocks in sequential mode, dwell_target otherwise) has been reached.
void dp_carrier_acq_steps (
dp_carrier_acq_state_t * state,
const float _Complex * x,
size_t x_len
)
Parameters:
stateMust be non-NULL.xRaw complex input samples (cf32).x_lenNumber of samples inx.>>> import numpy as np >>> from doppler.acquire import CarrierAcquisition >>> rng = np.random.default_rng(12345) >>> bits = np.where(rng.integers(0, 2, 4000), 1.0, -1.0) >>> data = np.repeat(bits, 8) # 8 samples/symbol BPSK >>> t = np.arange(len(data)) >>> x = (data * np.exp(2j * np.pi * 123.0 * t / 8000.0)).astype( ... np.complex64) # residual carrier at 123 Hz >>> ca = CarrierAcquisition( ... sample_rate_hz=8000.0, symbol_rate_hz=1000.0, ... psd_template=np.array([], dtype=np.float32)) >>> ca.steps(x) # fold the stream, testing each block >>> ca.ready True >>> round(ca.residual_hz, 0) # recovered residual carrier, Hz 123.0
Macro Definition Documentation¶
define CARRIER_ACQ_STATE_MAGIC¶
State-blob magic ("CAQR"); set_state() rejects any other.
define CARRIER_ACQ_STATE_VERSION¶
State-blob layout version; bumped when the payload changes. Version 2: the nested detector blob is the one correlator's 'CORL', in its 1-D detector flavor (#2752 steps 3.2 and 3.3, between which no release was cut, so 3.3's change rides the same unreleased version).
The documentation for this class was generated from the following file native/inc/doppler/carrier_acq/carrier_acq_core.h