Skip to content

File dsss_receiver_core.h

FileList > doppler > dsss_receiver > dsss_receiver_core.h

Go to the source code of this file

Composed continuous DSSS receiver: Acquisition -> Costas(bn_fll) pre-despread carrier wipeoff -> Dll(segments) -> RateConverter -> MpskReceiver, one object. More...

  • #include "doppler/RateConverter/RateConverter_core.h"
  • #include "doppler/correlator/correlator_core.h"
  • #include "doppler/cic/cic_core.h"
  • #include "doppler/dll/dll_core.h"
  • #include "doppler/dp_state.h"
  • #include "doppler/hbdecim/hbdecim_core.h"
  • #include "doppler/mpsk_receiver/mpsk_receiver_core.h"
  • #include "doppler/resamp/resamp_core.h"
  • #include "doppler/resample/resample_core.h"
  • #include "doppler/dp_complex.h"
  • #include <stddef.h>
  • #include "doppler/costas/costas_core.h"

Classes

Type Name
struct dp_dsss_receiver_state_t
Composed receiver state.
struct dsss_receiver_extra_t
Receiver-level payload that follows the state envelope: the routing flag, cached hit estimates, the grid (layout key) and the carrier-carry depth.

Public Functions

Type Name
int dp_dsss_receiver_configure_chain_raw (dp_dsss_receiver_state_t * state, size_t segments, size_t sps, int n)
Pin the despread/resample/demod grid directly, bypassing the create-time segments /sps defaults.
void dp_dsss_receiver_configure_lock_raw (dp_dsss_receiver_state_t * state, double up_thresh, double down_thresh, size_t n_looks, double alpha, uint32_t n_up, uint32_t n_down)
Re-tune the embedded Dll's code-lock detector directly. Forwards to dp_dll_configure_lock_raw() , which also clears the in-flight lock statistic and drops lock. Only meaningful once tracking has begun: while searching it tunes the placeholder Dll, which the next hit replaces, so the setting is lost (as it is on reset() and configure_chain_raw()). The detector is the hysteretic lockdet over the DLL's per-N-look CFAR statistic —up_thresh /down_thresh set the declare/drop levels andn_up /n_down the consecutive-look verify counts, trading declare latency against false-alarm rate.
int dp_dsss_receiver_configure_search_raw (dp_dsss_receiver_state_t * state, size_t doppler_bins, size_t n_noncoh)
Pin the embedded search's grid directly. Forwards to dp_correlator_configure_search_raw() — the escape hatch under this object's ownsymbol_rate -driven auto-sizing, for a power user who wants a specific(doppler_bins, n_noncoh) instead. Pinning exits the continuous engine's wideband window-tiling mode, re-derives its thresholds and resets it, discarding any search in flight. While tracking the engine is idle, so the pinned grid governs the search that resumes after the nextreset() .
dp_dsss_receiver_state_t * dp_dsss_receiver_create (const uint8_t * code, size_t code_len, double chip_rate, double symbol_rate, double sample_rate, int m, double cn0_dbhz, double pfa, double pd, double doppler_uncertainty, size_t segments, size_t sps, int differential)
Create a DSSS receiver in the searching state.
void dp_dsss_receiver_destroy (dp_dsss_receiver_state_t * state)
Destroy a receiver and release all four children.
double dp_dsss_receiver_get_chip_phase (const dp_dsss_receiver_state_t * state)
Dll's live tracked code phase (chips); 0.0 while searching.
double dp_dsss_receiver_get_cn0_dbhz_est (const dp_dsss_receiver_state_t * state)
C/N0 estimate from the winning acquisition hit.
double dp_dsss_receiver_get_code_rate (const dp_dsss_receiver_state_t * state)
Dll's tracked code rate; 1.0 while searching.
size_t dp_dsss_receiver_get_consumed (const dp_dsss_receiver_state_t * state)
Inputs the last dp_dsss_receiver_steps() call took: itsx_len , or 0 when it held its input back.
double dp_dsss_receiver_get_doppler_hz (const dp_dsss_receiver_state_t * state)
Doppler estimate from the winning acquisition hit.
double dp_dsss_receiver_get_lock (const dp_dsss_receiver_state_t * state)
MpskReceiver's carrier lock EMA; 0.0 while searching.
int dp_dsss_receiver_get_n (const dp_dsss_receiver_state_t * state)
MpskReceiver terminal outputs per symbol ( m_out ) in use.
double dp_dsss_receiver_get_norm_freq (const dp_dsss_receiver_state_t * state)
MpskReceiver's tracked carrier frequency; 0.0 while searching.
size_t dp_dsss_receiver_get_segments (const dp_dsss_receiver_state_t * state)
Dll partial correlations per code period currently in use.
double dp_dsss_receiver_get_settle_time (const dp_dsss_receiver_state_t * state)
Symbols a track emits before its demodulator has settled: where a steady-state measurement of a track's symbols may start.
size_t dp_dsss_receiver_get_sps (const dp_dsss_receiver_state_t * state)
MpskReceiver samples per symbol currently in use.
void dp_dsss_receiver_get_state (const dp_dsss_receiver_state_t * state, void * blob)
Serialize the whole receiver (searching or tracking) into blob .
int dp_dsss_receiver_get_tracking (const dp_dsss_receiver_state_t * state)
Routing state: searching or tracking.
void dp_dsss_receiver_reset (dp_dsss_receiver_state_t * state)
Return to the searching state. Resets the embedded search and rebuilds dll /rc /rx and the carrier loop at the placeholder seed (phase 0, no Doppler) on the current grid (a configure_chain_raw() pin survives), clearing the carrier carry and the cached Doppler/C/N0 estimates. Any configure_lock_raw() tuning is lost with the old Dll; a grid pinned by configure_search_raw() is kept. A receiver that has locked cannot be "reset back to tracking the same signal," only back to searching, matching every other object's reset() semantics in this codebase.
int dp_dsss_receiver_set_state (dp_dsss_receiver_state_t * state, const void * blob)
Restore a blob from dp_dsss_receiver_get_state() intostate .
size_t dp_dsss_receiver_state_bytes (const dp_dsss_receiver_state_t * state)
Byte size of state's blob.
size_t dp_dsss_receiver_steps (dp_dsss_receiver_state_t * state, const float _Complex * x, size_t x_len, float _Complex * out, size_t max_out)
Stream raw cf32 samples; emit demodulated symbols once locked.
size_t dp_dsss_receiver_steps_max_out (dp_dsss_receiver_state_t * state, size_t x_len)
The capacity that lets the next steps() call on x_len samples deliver everything it can: the symbols held, plus the most the call can produce.

Macros

Type Name
define DSSS_RECEIVER_STATE_MAGIC [**DP\_FOURCC**](dp__state_8h.md#define-dp_fourcc) ('D', 'S', 'R', 'X')
Magic tag ("DSRX") stamped in a receiver state blob.
define DSSS_RECEIVER_STATE_VERSION /* multi line expression */
Layout version of the receiver state blob.
define DSSS_RX_BN_CARRIER 0.01
Pre-despread carrier loop's PLL noise bandwidth, normalized to its once-per-code-period update rate.
define DSSS_RX_BN_FLL 0.03
Pre-despread carrier loop's FLL-assist bandwidth, normalized to its once-per-code-period update rate.
define DSSS_RX_DEMOD_BN_CARRIER 0.01
The demodulator's carrier loop noise bandwidth, cycles per symbol, as this receiver builds its MpskReceiver.
define DSSS_RX_DEMOD_BN_TIMING 0.005
The demodulator's timing loop noise bandwidth, cycles per symbol, as this receiver builds its MpskReceiver.
define DSSS_RX_DEMOD_ZETA 0.707
The damping of both the demodulator's loops.

Detailed Description

The single-object form of the chain validated across this repo's "continuous async-DSSS receiver" story (docs/gallery/async-dsss-receiver-spec.md, docs/gallery/dsss-acq-characterization.md, docs/gallery/dsss-receiver.md): a continuous, non-bursty spreading code whose data-symbol clock need not be synchronous to the code-epoch clock. steps() streams raw samples through whichever child is currently active:

  • searching (tracking() == 0): samples feed the embedded continuous search (the Correlator flavor). Nothing is emitted. On a hit, the carrier loop/ Dll/RateConverter/MpskReceiver are built from the hit's code phase and Doppler estimate (the exact dp_correlator_hit_t::chip_phase hand-off phase and RateConverter-bridged sample-rate hand-off this repo's gallery pages validated by hand), and the unconsumed tail of the same steps() call is handed straight to them — no samples are dropped at the transition.
  • tracking (tracking() == 1): samples are first derotated by a pre-despread carrier loop (costas_wipeoff/costas_update, one update per code period, bn_fll-assisted removes BULK Doppler and its RATE OF CHANGE before the code loop ever sees it; a fixed/ bounded residual alone is fine downstream-only, per docs/design/async-dsss-receiver.md §3.4, but an unbounded Doppler RATE is not), one code period at a time (a small internal carry buffer holds any leftover partial-period tail across calls steps() still accepts any block size), then feed Dll -> RateConverter -> MpskReceiver in sequence the C-level equivalent of hand-composing those four objects (plus the new carrier stage) and demodulated symbols are emitted. This is a NEW composition living entirely in this object deliberately NOT a swap to the existing Despreader object (which fuses Costas+Dll per-sample), because Despreader embeds Dll via dp_dll_init(), hardcoded to segments==1; it cannot carry this object's own segments>1 async-lookback tracking. dp_dll_steps() itself is called completely unmodified.

Per [[feedback_despread_resample_demod_separation]] (this story's own hard-won lesson): segments (the despreader's own tracking parameter) and sps (the demodulator's own sample-rate need) are independently configurable and bridged by an explicit RateConverter, never coupled to each other.

// "Just works": only the signal's own physical parameters are required.
dp_dsss_receiver_state_t *rx = dp_dsss_receiver_create(
    code, code_len, 3.0e6, 2100.0,   // chip_rate, symbol_rate
    6.0e6, 2,                        // sample_rate, m (BPSK)
    55.0, 1e-3, 0.9, 100.0,          // cn0_dbhz, pfa, pd,
                                     // doppler_uncertainty
    4, 8,                            // segments, sps
    0);                              // differential
float _Complex syms[4096];
size_t n = dp_dsss_receiver_steps(rx, x, x_len, syms, 4096);
dp_dsss_receiver_destroy(rx);

Public Functions Documentation

function dp_dsss_receiver_configure_chain_raw

Pin the despread/resample/demod grid directly, bypassing the create-time segments /sps defaults.

int dp_dsss_receiver_configure_chain_raw (
    dp_dsss_receiver_state_t * state,
    size_t segments,
    size_t sps,
    int n
) 

The escape hatch for the one composition-specific knob this object adds beyond its children's own: segments (Dll's tracking parameter) and sps/n (MpskReceiver's samples and terminal outputs per symbol) are independently overridable here, still bridged by a freshly-sized RateConverter never coupled to each other (see the module docstring). It rebuilds dll/rc/rx at once, allocating every replacement before freeing the old ones (the search's dp_correlator_regrid() discipline), and the pinned grid is the one every later chain is built on: the next hit's hand-off and reset() both rebuild at it.

The new grid is checked before anything is rebuilt, and refused with the receiver left on its prior grid: segments >= 1, sps >= 2, a symbol no faster than a chip and a resampling ratio that is a normal double (doppler#2103), and an n MpskReceiver would accept (doppler#2426). Still an abort: an allocation failure in the rebuild, which runs under dp_xnn (doppler#2112).

Parameters:

  • state The receiver.
  • segments Dll tracking segments per code period, >= 1.
  • sps MpskReceiver samples per symbol (the resample target), >= 2.
  • n MpskReceiver's terminal outputs per symbol (m_out): inside dp_ratesync_m_ok() (even, 2..8) and at most sps mpsk_rx_m_out_ok(), the rule create()'s own derived n satisfies, so get_n() always re-applies (doppler#2650). It need not divide sps.

Returns:

0 on success, -1 on a grid refused as above (the receiver keeps its prior grid).

>>> import numpy as np
>>> from doppler.dsss import DsssReceiver
>>> from doppler.wfm import Gold
>>> code = np.asarray(Gold().generate(1023)).astype(np.uint8)
>>> rx = DsssReceiver(code, chip_rate=3.0e6, symbol_rate=2100.0,
...                   sample_rate=6.0e6)
>>> rx.configure_chain_raw(segments=6, sps=8, n=8)  # re-pin the chain
>>> rx.segments                       # tracking grid updated in place
6


function dp_dsss_receiver_configure_lock_raw

Re-tune the embedded Dll's code-lock detector directly. Forwards to dp_dll_configure_lock_raw() , which also clears the in-flight lock statistic and drops lock. Only meaningful once tracking has begun: while searching it tunes the placeholder Dll, which the next hit replaces, so the setting is lost (as it is on reset() and configure_chain_raw()). The detector is the hysteretic lockdet over the DLL's per-N-look CFAR statistic —up_thresh /down_thresh set the declare/drop levels andn_up /n_down the consecutive-look verify counts, trading declare latency against false-alarm rate.

void dp_dsss_receiver_configure_lock_raw (
    dp_dsss_receiver_state_t * state,
    double up_thresh,
    double down_thresh,
    size_t n_looks,
    double alpha,
    uint32_t n_up,
    uint32_t n_down
) 

Parameters:

  • state Must be non-NULL.
  • up_thresh CFAR-statistic level to declare code lock (hit when the statistic exceeds it).
  • down_thresh Level below which a look is a miss; choose <= up_thresh for level hysteresis.
  • n_looks Looks per decision — the DLL's non-coherent integration depth feeding one statistic.
  • alpha EMA smoothing coefficient on the lock statistic (0..1); smaller is smoother/slower.
  • n_up Consecutive hits required to declare lock.
  • n_down Consecutive misses required to drop lock.
    >>> import numpy as np
    >>> from doppler.dsss import DsssReceiver
    >>> from doppler.wfm import Gold
    >>> code = np.asarray(Gold().generate(1023)).astype(np.uint8)
    >>> rx = DsssReceiver(code, chip_rate=3.0e6, symbol_rate=2100.0,
    ...                   sample_rate=6.0e6)
    >>> rx.configure_lock_raw(up_thresh=0.4, down_thresh=0.2, n_looks=20,
    ...                       alpha=0.1, n_up=5, n_down=3)
    >>> rx.tracking                # a no-op until a hit builds the Dll
    0
    

function dp_dsss_receiver_configure_search_raw

Pin the embedded search's grid directly. Forwards to dp_correlator_configure_search_raw() — the escape hatch under this object's ownsymbol_rate -driven auto-sizing, for a power user who wants a specific(doppler_bins, n_noncoh) instead. Pinning exits the continuous engine's wideband window-tiling mode, re-derives its thresholds and resets it, discarding any search in flight. While tracking the engine is idle, so the pinned grid governs the search that resumes after the nextreset() .

int dp_dsss_receiver_configure_search_raw (
    dp_dsss_receiver_state_t * state,
    size_t doppler_bins,
    size_t n_noncoh
) 

Parameters:

  • state Must be non-NULL.
  • doppler_bins Coherent depth to pin, in [1, reps] as dp_correlator_configure_search_raw() defines it.
  • n_noncoh Non-coherent looks accumulated per grid cell (1..256); more looks buys sensitivity at the cost of dwell, replacing the auto-sized count.

Returns:

0 on success; DP_ERR_INVALID on an invalid grid (including n_noncoh > 1 on an engine with rate hypotheses); DP_ERR_MEMORY on a failed allocation (the engine keeps its prior grid; see dp_correlator_configure_search_raw()).

>>> import numpy as np
>>> from doppler.dsss import DsssReceiver
>>> from doppler.wfm import Gold
>>> code = np.asarray(Gold().generate(1023)).astype(np.uint8)
>>> rx = DsssReceiver(code, chip_rate=3.0e6, symbol_rate=2100.0,
...                   sample_rate=6.0e6)
>>> rx.configure_search_raw(doppler_bins=1, n_noncoh=16)  # pin it
>>> rx.tracking                # still searching, on the pinned grid
0


function dp_dsss_receiver_create

Create a DSSS receiver in the searching state.

dp_dsss_receiver_state_t * dp_dsss_receiver_create (
    const uint8_t * code,
    size_t code_len,
    double chip_rate,
    double symbol_rate,
    double sample_rate,
    int m,
    double cn0_dbhz,
    double pfa,
    double pd,
    double doppler_uncertainty,
    size_t segments,
    size_t sps,
    int differential
) 

Only code/chip_rate/symbol_rate describe the signal itself — everything else is a physically-motivated default a caller can override, not a requirement. Internally: the embedded continuous search is built via dp_correlator_create_continuous() (this receiver is inherently continuous/streaming) always window-tiles, never coherently combines across epochs, sensitivity purely from an internally auto-sized non-coherent look count (see correlator_core.h's file doc comment); Dll always uses bn=0.002 (this story's own validated stable loop bandwidth for a one-update-per-code-epoch geometry, not dp_dll_create()'s own default of 0.01, which this story found unstable here) and zeta=0.707, spacing=0.5; MpskReceiver always uses pulse=iandd, DSSS_RX_DEMOD_BN_CARRIER, DSSS_RX_DEMOD_BN_TIMING, DSSS_RX_DEMOD_ZETA and lock_thresh=0.3 — this story's own validated values throughout. It also passed acq_to_track=1 and warmup_syms=30 until those were deleted (doppler#877, 1f417e97); the composed receiver now runs its one NDA discriminator here as everywhere else. lock_thresh=0.3 predates the lock statistic becoming a calibrated detector and is retained because it is validated here, but it now has a derivable reading: the carrier lock EMA's noise-only sd is 0.1132 at every M, so 0.3 is 2.65 noise sigmas, a per-look Pfa of ~4e-3 — looser than MpskReceiver's own 0.5 default (4.42 sigma, 5e-6) and still ~6 sigma clear of the +0.99 a locked BPSK constellation reads, which is why it holds. See carrier_nda_core.h. n (MpskReceiver's terminal outputs per symbol, m_out) is derived from sps by mpsk_rx_derive_m_out(): the even count 2*floor(sps/2), capped at 8.

Parameters:

  • code Spreading code, one 0/1 chip per element (0 -> +1, 1 -> -1 BPSK; only the low bit is used, so pass 0/1, not +/-1).
  • code_len Chips in code (the spreading factor).
  • chip_rate Chip rate, Hz. Required.
  • symbol_rate Data-symbol rate, Hz. Required — passed straight to the embedded search's own symbol_rate (diagnostic there; see dp_correlator_create_continuous()).
  • sample_rate Input sample rate, Hz: a whole number of samples a chip (to a part in 1e9), at least one, or 0 for two a chip (the default). A fractional rate is refused: this receiver's code loop and carrier stage run whole-sample code periods (AsyncDsssReceiver takes any).
  • m PSK order, 2/4/8; default 2 (BPSK).
  • cn0_dbhz Design C/N0 for acquisition sizing, dB-Hz; default 55.0.
  • pfa Acquisition false-alarm target; default 1e-3.
  • pd Acquisition detection-probability target; default 0.9.
  • doppler_uncertainty One-sided Doppler search half-range, Hz; default 100.0.
  • segments Dll's partial correlations per code epoch: its despread output rate and the grain of its look-back window, independent of sps (see the module docstring); default 4.
  • sps MpskReceiver's samples/symbol, reached by an internal RateConverter bridging the despreader's own partial rate to this rate; default 8, MpskReceiver's own constructor default.
  • differential MpskReceiver's differential (rotation- invariant) demap; default 0 (coherent).

Returns:

A new receiver in the searching state, owned by the caller (free with dp_dsss_receiver_destroy()); NULL when code is NULL, a parameter is outside its domain (m not 2/4/8, sample_rate not a whole number of samples a chip of at least one, sps < 2, a non-positive or non-finite rate, a symbol rate above the chip rate, a code/segments pair the Dll refuses), or the embedded search refuses its own parameters (pfa, pd, cn0_dbhz, ...). An allocation failure aborts the process rather than returning NULL.

>>> import numpy as np
>>> from doppler.dsss import DsssReceiver
>>> from doppler.wfm import Gold
>>> sf, chip, sym, spc = 1023, 3.0e6, 2100.0, 2
>>> fs, te, tsym = chip * spc, sf * spc, chip * spc / sym
>>> code = np.asarray(Gold().generate(sf)).astype(np.uint8)
>>> csign = np.where(code & 1, -1.0, 1.0)
>>> rng = np.random.default_rng(6)
>>> n = int(400 * tsym) + 2 * te            # 400 BPSK data symbols
>>> idx = np.arange(n)
>>> data = (rng.integers(0, 2, 404) * 2 - 1).astype(float)
>>> si = np.clip((idx / tsym).astype(int), 0, 403)
>>> spread = data[si] * csign[(idx // spc) % sf]        # DSSS chips
>>> sig = spread * np.exp(2j * np.pi * (50.0 / fs) * idx)  # +50 Hz
>>> pre = 3 * te                     # noise-only lead-in, pre-signal
>>> sigma = np.sqrt(fs / 10 ** (90.0 / 10))            # ~90 dB-Hz C/N0
>>> noise = (sigma / np.sqrt(2)) * (rng.standard_normal(pre + n)
...          + 1j * rng.standard_normal(pre + n))
>>> x = (np.concatenate([np.zeros(pre), sig]).astype(np.complex64)
...      + noise.astype(np.complex64))
>>> rx = DsssReceiver(code, chip_rate=chip, symbol_rate=sym, sample_rate=fs,
...                   cn0_dbhz=55.0, doppler_uncertainty=100.0)
>>> syms = [rx.steps(x[p:p + te]) for p in range(0, len(x) - te, te)]
>>> syms = np.concatenate([s for s in syms if len(s)])
>>> rx.tracking                  # acquired, now demodulating
1
>>> len(syms) > 300              # a few hundred symbols recovered
True

Nearly all the energy lands on I, so the BPSK phase is resolved:

>>> bool(np.mean(syms.real**2) > 10 * np.mean(syms.imag**2))
True


function dp_dsss_receiver_destroy

Destroy a receiver and release all four children.

void dp_dsss_receiver_destroy (
    dp_dsss_receiver_state_t * state
) 

Parameters:

  • state May be NULL.

function dp_dsss_receiver_get_chip_phase

Dll's live tracked code phase (chips); 0.0 while searching.

double dp_dsss_receiver_get_chip_phase (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

Code phase in chips, from dp_dll_get_code_phase().


function dp_dsss_receiver_get_cn0_dbhz_est

C/N0 estimate from the winning acquisition hit.

double dp_dsss_receiver_get_cn0_dbhz_est (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

dB-Hz; 0.0 before the first hit and after reset().


function dp_dsss_receiver_get_code_rate

Dll's tracked code rate; 1.0 while searching.

double dp_dsss_receiver_get_code_rate (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

Chips advanced per nominal chip (~1.0 at lock), from dp_dll_get_code_rate().


function dp_dsss_receiver_get_consumed

Inputs the last dp_dsss_receiver_steps() call took: itsx_len , or 0 when it held its input back.

size_t dp_dsss_receiver_get_consumed (
    const dp_dsss_receiver_state_t * state
) 

Per-call, not in the blob: 0 after create and reset.

Parameters:

  • state Must be non-NULL.

Returns:

Input samples the last call consumed.


function dp_dsss_receiver_get_doppler_hz

Doppler estimate from the winning acquisition hit.

double dp_dsss_receiver_get_doppler_hz (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

Hz; 0.0 before the first hit and after reset(). Not updated while tracking.


function dp_dsss_receiver_get_lock

MpskReceiver's carrier lock EMA; 0.0 while searching.

double dp_dsss_receiver_get_lock (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

The NDA lock statistic, near 1 when locked and near 0 on noise, from dp_mpsk_receiver_get_lock().


function dp_dsss_receiver_get_n

MpskReceiver terminal outputs per symbol ( m_out ) in use.

int dp_dsss_receiver_get_n (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

2*floor(sps/2) capped at 8 from create, or the last configure_chain_raw() pin.


function dp_dsss_receiver_get_norm_freq

MpskReceiver's tracked carrier frequency; 0.0 while searching.

double dp_dsss_receiver_get_norm_freq (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

Cycles/sample at the demodulator's rate (sps * symbol_rate): the residual left after the pre-despread carrier loop, not the full Doppler.


function dp_dsss_receiver_get_segments

Dll partial correlations per code period currently in use.

size_t dp_dsss_receiver_get_segments (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

The create-time value, or the last configure_chain_raw() pin.


function dp_dsss_receiver_get_settle_time

Symbols a track emits before its demodulator has settled: where a steady-state measurement of a track's symbols may start.

double dp_dsss_receiver_get_settle_time (
    const dp_dsss_receiver_state_t * state
) 

The demodulator's own figure, dp_mpsk_receiver_get_settle_time(), at the bandwidths this receiver builds it with (DSSS_RX_DEMOD_BN_TIMING, DSSS_RX_DEMOD_BN_CARRIER and DSSS_RX_DEMOD_ZETA): 778.5 symbols. Counted from the first symbol a track emits, since nothing is emitted while the receiver searches; reset() starts the search, and so the count, again. It is a design figure of the demodulator's two linear loops: the code loop and the pre-despread carrier loop, which run ahead of it and pull in over the same span, are not counted.

Parameters:

  • state Must be non-NULL.

Returns:

Symbols, from the first one of a track.

uint8_t code[7] = { 1, 1, 1, 0, 0, 1, 0 };
dp_dsss_receiver_state_t *rx = dp_dsss_receiver_create (
    code, 7, 1.0e6, 35714.29, 4.0e6, 2, 70.0, 1e-2, 0.9, 500.0, 4, 8, 0);
if (!rx)
  return 1;
// known before a sample is fed: prints 778.5
printf ("%.1f\n", dp_dsss_receiver_get_settle_time (rx));
dp_dsss_receiver_destroy (rx);


function dp_dsss_receiver_get_sps

MpskReceiver samples per symbol currently in use.

size_t dp_dsss_receiver_get_sps (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

The create-time value, or the last configure_chain_raw() pin.


function dp_dsss_receiver_get_state

Serialize the whole receiver (searching or tracking) into blob .

void dp_dsss_receiver_get_state (
    const dp_dsss_receiver_state_t * state,
    void * blob
) 

Parameters:


function dp_dsss_receiver_get_tracking

Routing state: searching or tracking.

int dp_dsss_receiver_get_tracking (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

0 while searching (after create/reset), 1 once a hit has built the chain and symbols are being demodulated.


function dp_dsss_receiver_reset

Return to the searching state. Resets the embedded search and rebuilds dll /rc /rx and the carrier loop at the placeholder seed (phase 0, no Doppler) on the current grid (a configure_chain_raw() pin survives), clearing the carrier carry and the cached Doppler/C/N0 estimates. Any configure_lock_raw() tuning is lost with the old Dll; a grid pinned by configure_search_raw() is kept. A receiver that has locked cannot be "reset back to tracking the same signal," only back to searching, matching every other object's reset() semantics in this codebase.

void dp_dsss_receiver_reset (
    dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.
    >>> import numpy as np
    >>> from doppler.dsss import DsssReceiver
    >>> from doppler.wfm import Gold
    >>> code = np.asarray(Gold().generate(1023)).astype(np.uint8)
    >>> rx = DsssReceiver(code, chip_rate=3.0e6, symbol_rate=2100.0,
    ...                   sample_rate=6.0e6)
    >>> rx.reset()                 # abort any lock, hunt from scratch
    >>> (rx.tracking, rx.chip_phase)   # back to searching, all cleared
    (0, 0.0)
    

function dp_dsss_receiver_set_state

Restore a blob from dp_dsss_receiver_get_state() intostate .

int dp_dsss_receiver_set_state (
    dp_dsss_receiver_state_t * state,
    const void * blob
) 

A searching engine may restore a tracking blob and vice versa. Children are restored in order (acq, carrier, dll, rc, rx); a child that rejects aborts with DP_ERR_INVALID after the earlier children were already restored.

Parameters:

  • state Must be non-NULL, built with the same code/spc and set to the same segments/sps/n grid as the blob's source.
  • blob Blob of dp_dsss_receiver_state_bytes(state) bytes.

Returns:

DP_OK, or DP_ERR_INVALID on an envelope mismatch, a grid that differs from the live engine's (pin it with configure_chain_raw() first), a carry length >= tsamps, or a rejected child.


function dp_dsss_receiver_state_bytes

Byte size of state's blob.

size_t dp_dsss_receiver_state_bytes (
    const dp_dsss_receiver_state_t * state
) 

Parameters:

  • state Must be non-NULL.

Returns:

Envelope + extra + the five children + a tsamps-sample carry region; fixed for a given grid, independent of tracking.


function dp_dsss_receiver_steps

Stream raw cf32 samples; emit demodulated symbols once locked.

size_t dp_dsss_receiver_steps (
    dp_dsss_receiver_state_t * state,
    const float _Complex * x,
    size_t x_len,
    float _Complex * out,
    size_t max_out
) 

No symbol is dropped while the code loop stays within its rate headroom (dp_dll_steps_max_out(): twice nominal); a loop past it, as one acquiring can be, drops partials inside the Dll, before they reach this receiver. Symbols held by an earlier call are delivered first, in order. A call consumes its input only when nothing stays held after that and its symbols fit: P(x_len) (see dp_dsss_receiver_steps_max_out()) is at most the room left in out plus the store, which holds what one call of a code period can produce. What does not fit in out is held for the next call. A call that cannot consume returns what it delivered and takes nothing: dp_dsss_receiver_get_consumed() reads 0, and the caller calls again with the same x. A C caller that sizes out below dp_dsss_receiver_steps_max_out() for a call longer than a code period meets this every time, so it must check consumed() or size out from that function, as the Python binding does.

While searching, samples feed the embedded search and nothing is emitted (0 return is normal, not an error). The moment a hit fires, Dll/RateConverter/MpskReceiver are built and seeded from it, and the rest of THIS call from where the hit's frame ended — the hit's own samples_consumed, so no samples are dropped or double-fed — is handed straight to them in the same call. While tracking, samples feed Dll -> RateConverter -> MpskReceiver in sequence. Accepts any block size; state carries across calls (the search/Dll/RateConverter/MpskReceiver are all already block-size invariant; the only buffering this object adds is the carrier loop's partial-code-period carry). While tracking, each call allocates two scratch buffers (abort on OOM).

Parameters:

  • state Must be non-NULL.
  • x Input cf32 samples.
  • x_len Number of input samples.
  • out Output symbols; caller provides max_out capacity.
  • max_out Output capacity. steps() never writes past it; symbols past it are held and delivered by the next call. dp_dsss_receiver_steps_max_out() for x_len is always enough.

Returns:

Number of symbols written: held ones first, then this call's; 0 while searching with nothing held, or while tracking with not yet a full symbol's worth of input.

>>> import numpy as np
>>> from doppler.dsss import DsssReceiver
>>> from doppler.wfm import Gold
>>> sf, chip, sym, spc = 1023, 3.0e6, 2100.0, 2
>>> fs, te, tsym = chip * spc, sf * spc, chip * spc / sym
>>> code = np.asarray(Gold().generate(sf)).astype(np.uint8)
>>> csign = np.where(code & 1, -1.0, 1.0)
>>> rng = np.random.default_rng(6)
>>> n = int(400 * tsym) + 2 * te            # 400 BPSK data symbols
>>> idx = np.arange(n)
>>> data = (rng.integers(0, 2, 404) * 2 - 1).astype(float)
>>> si = np.clip((idx / tsym).astype(int), 0, 403)
>>> spread = data[si] * csign[(idx // spc) % sf]        # DSSS chips
>>> sig = spread * np.exp(2j * np.pi * (50.0 / fs) * idx)  # +50 Hz
>>> pre = 3 * te                     # noise-only lead-in, pre-signal
>>> sigma = np.sqrt(fs / 10 ** (90.0 / 10))            # ~90 dB-Hz C/N0
>>> noise = (sigma / np.sqrt(2)) * (rng.standard_normal(pre + n)
...          + 1j * rng.standard_normal(pre + n))
>>> x = (np.concatenate([np.zeros(pre), sig]).astype(np.complex64)
...      + noise.astype(np.complex64))
>>> rx = DsssReceiver(code, chip_rate=chip, symbol_rate=sym, sample_rate=fs,
...                   cn0_dbhz=55.0, doppler_uncertainty=100.0)
>>> syms = [rx.steps(x[p:p + te]) for p in range(0, len(x) - te, te)]
>>> syms = np.concatenate([s for s in syms if len(s)])
>>> rx.tracking                  # acquired and now demodulating
1
>>> len(syms) > 300              # a few hundred symbols recovered
True

Nearly all the energy lands on I, so the BPSK phase is resolved:

>>> bool(np.mean(syms.real**2) > 10 * np.mean(syms.imag**2))
True


function dp_dsss_receiver_steps_max_out

The capacity that lets the next steps() call on x_len samples deliver everything it can: the symbols held, plus the most the call can produce.

size_t dp_dsss_receiver_steps_max_out (
    dp_dsss_receiver_state_t * state,
    size_t x_len
) 

Sized to this, a call never holds and never refuses its input (dp_dsss_receiver_steps()), which is how the Python binding calls it. The most a call can produce, P(x_len), is bounded by the chain's structure, not by the nominal rate: the call runs at most x_len + tsamps - 1 samples through the tracking chain (the carry); the Dll emits at most dp_dll_steps_max_out() of them; the RateConverter at most ceil(ratio x n) + 1 of n partials (ratio fixed by configuration); MpskReceiver at most one symbol per input; and the hand-over a hit makes rebuilds the Dll and the RateConverter, one more close and one more output. A call holds at most one hand-over: tracking never returns to searching except through reset(). So P(x_len) = ceil(ratio x dp_dll_steps_max_out(dll, x_len + tsamps - 1)) + 1 + ceil(segments x ratio) + 1. A symbol may be shorter than a code period here, so a call that completes a carried period can make many symbols (#2469's 127-chip, 250 ksym/s case: 31.75 a period); the bound carries them. A Debug build aborts on a call that produces more than it.

Parameters:

  • state Must be non-NULL.
  • x_len Input samples the call will be given.

Returns:

Held symbols plus P(x_len); SIZE_MAX if that overflows.


Macro Definition Documentation

define DSSS_RECEIVER_STATE_MAGIC

Magic tag ("DSRX") stamped in a receiver state blob.

#define DSSS_RECEIVER_STATE_MAGIC `DP_FOURCC ('D', 'S', 'R', 'X')`


define DSSS_RECEIVER_STATE_VERSION

Layout version of the receiver state blob.

#define DSSS_RECEIVER_STATE_VERSION `/* multi line expression */`


define DSSS_RX_BN_CARRIER

Pre-despread carrier loop's PLL noise bandwidth, normalized to its once-per-code-period update rate.

#define DSSS_RX_BN_CARRIER `0.01`


define DSSS_RX_BN_FLL

Pre-despread carrier loop's FLL-assist bandwidth, normalized to its once-per-code-period update rate.

#define DSSS_RX_BN_FLL `0.03`


define DSSS_RX_DEMOD_BN_CARRIER

The demodulator's carrier loop noise bandwidth, cycles per symbol, as this receiver builds its MpskReceiver.

#define DSSS_RX_DEMOD_BN_CARRIER `0.01`


define DSSS_RX_DEMOD_BN_TIMING

The demodulator's timing loop noise bandwidth, cycles per symbol, as this receiver builds its MpskReceiver.

#define DSSS_RX_DEMOD_BN_TIMING `0.005`


define DSSS_RX_DEMOD_ZETA

The damping of both the demodulator's loops.

#define DSSS_RX_DEMOD_ZETA `0.707`



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