Skip to content

The Python Library

Everything in the doppler.wfm package imports from one place — from doppler.wfm import …. The two low-level generators are:

Class Output Use when
Synth CF32 — the nine-type waveform engine Generate tone / noise / PN / BPSK / QPSK / chirp / bits / symbols / DSSS, with optional LO offset and AWGN
PN uint8 — raw LFSR chips (0/1) Spreading / ranging codes, scrambling, test vectors

Synth is also the unit of composition — pass synths into Segment.sum to mix them (see compose below).

Source: src/doppler/wfm/__init__.py

These same C cores back the one command-line tool, wfmgen — see the Waveform Generator guide.

Reading or writing a capture file is on its own page — Python: Capture I/O covers Reader, Writer and write_blue_header, with the Capture I/O guide as the narrative version.

Synth — the nine-type waveform engine

One declarative engine produces every waveform type, selected by the string type (tone, noise, pn, bpsk, qpsk, chirp, bits, symbols, dsss). Construction takes keyword arguments mirroring the generator flags; sensible defaults mean a bare Synth() is a clean, unit-power baseband tone.

from doppler.wfm import Synth
import numpy as np

# Bare construct → clean baseband tone, unit power, no noise
x = Synth().steps(4096)            # complex64

# Tone at Fs/10 with 20 dB SNR
tone = Synth(type="tone", fs=1e6, freq=100_000, snr=20).steps(4096)

# Complex AWGN (unit power)
noise = Synth(type="noise", seed=7).steps(8192)

# PN / BPSK / QPSK — sps samples per chip/symbol
pn   = Synth(type="pn",   pn_length=7, sps=1).steps(127)
bpsk = Synth(type="bpsk", sps=8, snr=10).steps(8192)
qpsk = Synth(type="qpsk", sps=8, snr=10).steps(8192)

# Scalar (one sample at a time)
s = Synth(type="tone", freq=1000, fs=1e6).step()

Multiplying by a waveform — prod() and rotate()

A synth is also an operator: Synth.prod(x) returns x times the synth's next len(x) samples, advancing the synth exactly as steps(len(x)) would (split calls equal one call; x is not modified). A tone makes it a rotation, a chirp a swept rotation, noise a noise multiplier, PN/BPSK a modulation. rotate(x, freq, rate, fs, center) is the swept-carrier special case: it multiplies x by exp(j 2 pi (freq u + rate u^2 / 2)) about a stated center sample (default the middle of x), to a constant phase. The chirp's start and end frequencies come from the one C home of that arithmetic, dp_wfm_synth_sweep_ends, which Python reaches through the private _sweep_ends; rotate is the supported way in, and it refuses an fs that is not positive and finite.

import numpy as np
from doppler.wfm import rotate

x = np.ones(1001, np.complex64)
y = rotate(x, freq=0.0, rate=1e-4)       # cycles/sample, cycles/sample^2
inst = np.angle(y[1:] * np.conj(y[:-1])) / (2 * np.pi)
assert abs(inst[0] + 0.05) < 1e-4 and abs(inst[-1] - 0.05) < 1e-4

Bits (user-defined pattern)

A bits waveform sends a specific bit sequence — preambles, sync words, test vectors, exact packet structures — from its data source, data=. The data is bits: a uint8 array, bytes or any sequence of 0/1. Text becomes bits through field_bits() — binary, 0x hex (MSB first), or a generated field such as pn:31:5 — and a str passed directly is refused, naming it. modulation maps the bits to symbols ("none" → 0/1 amplitude, "bpsk" → ±1, "qpsk" → two bits per symbol, Gray-coded). Each bit is held sps samples and the bits are sent once, then silence. A data source is a frame's payload and is sent exactly as given; a CRC-16 trailer, a sync word or a coding stage is part of a frame description, passed as frame= (see Data).

from doppler.wfm import Synth, bits, field_bits

# 8-bit preamble, BPSK, 4 samples/bit → 32 samples, sent once
s = bits(data=field_bits("10110101"), sps=4, modulation="bpsk")
preamble = s.steps(32)  # 8 bits * 4 sps

# Hex sync word, unmodulated 0/1; direct construction is equivalent
sync = Synth(
    type="bits", data=field_bits("0xAA55"), modulation="none", sps=8,
)

# From a numpy array
import numpy as np
payload = bits(
    data=np.array([1, 0, 1, 1, 0, 1, 0, 1], np.uint8), modulation="qpsk",
)

Symbols (arbitrary constellation)

Where bits maps data through a fixed modulation, type="symbols" skips the map entirely: you supply a complex64 constellation stream and each element is an output point directly, oversampled by sps, cycled to fill the request, and RRC-shaped through the same matched-FIR path (pulse="rrc"). That expresses any modulation an enum doesn't — pi/4-QPSK, QAM, APSK — by computing the points yourself and passing them. On the composer Synth the stream is the symbols= keyword; on the low-level _SynthEngine it is attached with set_symbols() after construction. A complex128 array is accepted (force-cast to complex64).

import numpy as np
from doppler.wfm import Synth

# pi/4-QPSK: rotate every other QPSK symbol by pi/4, then pass the stream
qpsk = np.array([1 + 1j, -1 + 1j, -1 - 1j, 1 - 1j], np.complex64) / np.sqrt(2)
stream = np.array(
    [qpsk[i % 4] * (np.exp(1j * np.pi / 4) if i % 2 else 1) for i in range(64)],
    np.complex64,
)
iq = Synth(type="symbols", symbols=stream, sps=8, pulse="rrc").steps(64 * 8)

See the Symbols gallery walkthrough for worked pi/4-QPSK and 16-QAM constellations, rect vs RRC pulses, and the envelope floor behind pi/4-QPSK's lower PAPR.

Chirp (LFM sweep)

A chirp is a linear-FM sweep: its instantaneous frequency ramps from freq (the start, also spellable f_start=) to f_end over span samples, then holds at f_end. Its phase is one running accumulator, so a Synth read in pieces joins seamlessly: the pieces are byte for byte one read (the second example below). Pulse-compression, SAR, sonar and frequency-response test signals all fall out of this one type. A composer Segment is different: each starts its sources afresh, so a sweep meant to run unbroken is one segment. f_end < freq is a down-chirp; snr adds AWGN exactly as for a tone.

from doppler.wfm import Synth, chirp

# Up-chirp 100 kHz → 300 kHz over 10000 samples at 1 MS/s
up = chirp(f_start=100e3, f_end=300e3, fs=1e6, span=10000).steps(10000)

# Down-chirp (equivalent direct construction; freq IS the start frequency)
down = Synth(type="chirp", freq=1e6, f_end=500e3, fs=2e6, span=50000)
x = down.steps(50000)
import numpy as np

# Four reads of one chirp are one read, byte for byte.
s = chirp(f_start=100e3, f_end=300e3, fs=1e6, span=2044)
pieces = np.concatenate([s.steps(511) for _ in range(4)])
whole = chirp(f_start=100e3, f_end=300e3, fs=1e6, span=2044).steps(2044)
assert pieces.tobytes() == whole.tobytes()

The span is declared, never inferred from a read: step(), steps(N) and any chunking of reads give the same waveform. A standalone sweeping chirp without span raises when it first generates. In a Segment the span defaults to the segment's num_samples. Sample n steps by freq + n·k, with k = (f_end − freq) / span, so the span's last sample steps at f_end − k, and f_end is held from the sample after.

Clean vs noisy, baseband vs offset

snr is in dB. snr >= 100 (the default) is clean — no AWGN is generated at all, so a clean waveform pays no noise cost. Lower it to add noise. freq = 0 (the default) is baseband — the LO is skipped entirely.

clean   = Synth(type="qpsk", sps=8, snr=100).steps(8192)   # no AWGN
noisy   = Synth(type="qpsk", sps=8, snr=12).steps(8192)     # Es/No 12 dB
offset  = Synth(type="pn", pn_length=9, sps=1, freq=2.5e5, fs=1e6).steps(511)

snr_mode ("auto", "fs", "ebno", "esno") sets how snr is interpreted. Which types "auto" sends to which reference is written out once, in the guide: Levels & SNR.

RRC pulse shaping (band-limited carriers)

By default the modulated types (pn / bpsk / qpsk) emit rectangular sample-and-hold chips — a wide sinc² spectrum. Set pulse="rrc" for root-raised-cosine pulse shaping: the symbol stream is filtered to a band-limited channel, so a realistic carrier (e.g. WCDMA QPSK, RRC roll-off 0.22) comes straight from the generator. rrc_beta is the roll-off and rrc_span the filter support in symbols. The taps are unit-transmit-power scaled, so the output stays at unit average power.

from doppler.wfm import qpsk

shaped = qpsk(sps=8, pulse="rrc", rrc_beta=0.22, rrc_span=8).steps(1 << 16)
# band-limited: its occupied bandwidth is ~(1+beta)/sps, far below the rect sinc²

PN modulation: length, polynomial, realization

# Auto-pick the maximum-length polynomial for the register length (2..64)
Synth(type="pn", pn_length=23, sps=1).steps(8192)

# Explicit 64-bit polynomial
Synth(type="pn", pn_length=40, pn_poly=0x800000001C, sps=1).steps(8192)

# Fibonacci realization (same polynomial/period, different chip ordering)
Synth(type="pn", pn_length=9, sps=1, lfsr="fibonacci").steps(511)

Determinism

s = Synth(type="qpsk", sps=4, seed=11)
a = s.steps(512)
s.reset()
assert np.array_equal(a, s.steps(512))   # same seed → identical stream

PN — raw LFSR m-sequence

A right-shift LFSR producing one bit (0/1) per call. With a primitive polynomial it is a maximum-length sequence: period 2**n - 1 with 2**(n-1) ones per period. Registers up to 64 bits are supported, in either the Galois (internal-XOR, default) or Fibonacci (external-XOR) realization — both realize the same polynomial and period.

from doppler.wfm import PN
import numpy as np

# Length-7 MLS (primitive polynomial 0x41), one full period
chips = np.asarray(PN(0x41, 1, 7).generate(127))   # uint8, 64 ones / 63 zeros

# Fibonacci realization of the same polynomial
fib = np.asarray(PN(0x41, 1, 7, lfsr="fibonacci").generate(127))

# 64-bit register
big = np.asarray(PN(0x800000001C, 1, 40).generate(50_000))

# Deterministic replay
p = PN(0x41, 1, 7)
a = np.asarray(p.generate(127)).copy()
p.reset()
assert np.array_equal(a, np.asarray(p.generate(127)))

The constructor is PN(poly, seed, length, lfsr="galois"). seed must be non-zero (the all-zero register is a fixed point). To map chips to ±1 BPSK symbols, use Synth(type="pn", ...) instead, which also handles oversampling, the LO, and AWGN.

Gold — a CCSDS Gold-code generator

Gold XORs two same-length LFSRs that free-run in lock-step, so its period is 2**length - 1 and varying seed_a walks the members of the Gold family while register B stays fixed. Use it when a code needs the bounded cross-correlation of a Gold family, as in DSSS; PN above is the single m-sequence.

compose — multi-segment composition, writers, and a NATS sink

The composition layer is the Python face of the C wfmgen composer subsystem — the same engine behind the wfmgen CLI, output byte-identical for the same parameters. There are two composition verbs:

  • Segment.sum(*synths, num_samples=…) mixes synths at the same time over one resolved noise floor (a multi-source scene);
  • Segment.add(*segments) sequences segments in time (a timeline).

The ladder is Synth → (.sum) → Segment → (.add) → Timeline → Composer → samples: .sum stacks synths in the same time window (one column), .add lays segments out along time (one row).

flowchart LR
    subgraph SEG["Segment — .sum() mixes at the SAME time, one noise floor"]
        direction TB
        y1["Synth qpsk · level −10 dBFS"]
        y2["Synth tone · level −3 dBFS"]
        y3["Synth noise · the floor"]
    end
    subgraph TL["Timeline — .add() sequences in TIME ▶"]
        direction LR
        sA["Segment A"] --> sB["Segment B<br/>(+ trailing gap)"] --> sC["…"]
    end
    SEG -- ".add(B, …)" --> sA
    TL --> COMP["Composer(…).compose()"] --> IQ[("complex64 I/Q")]

    classDef syn stroke-width:3px;
    classDef seg stroke-width:3px,stroke-dasharray:4 2;
    class y1,y2,y3 syn;
    class sA,sB,sC seg;

A Composer turns a Segment / Timeline / segment-list into samples, optionally looping (repeat) or running forever (continuous); Writer serialises to the four file types (raw / CSV / BLUE type-1000 / SigMF), and StreamSink publishes over NATS (requires a nats-server reachable at the endpoint; NATS Broker installs and runs one). The resolved spec round-trips through JSON, so a capture is fully reproducible.

import numpy as np
from doppler.wfm import Composer, Reader, Segment, Writer, mls_poly, qpsk, tone

# Mix: a QPSK signal of interest under a CW interferer, one noise floor.
scene = Segment.sum(
    qpsk(snr=15, sps=8, level=-10),       # builders return Synth
    tone(freq=2e5, level=-3),
    num_samples=65536,
)

# Sequence: a PN preamble, then the scene, back-to-back in time.
timeline = Segment("pn", num_samples=127, pn_length=7).add(scene)
iq = Composer(timeline).compose()         # one complex64 array

# Or stream block-by-block (an empty block marks the end):
c = Composer(timeline)
with Writer("frame.cf32", fs=1e6, sample_type="cf32") as w:
    while len(blk := c.execute(4096)):
        w.write(blk)
with Reader("frame.cf32", sample_type="cf32") as r:  # C reader → complex64
    back = r.read(r.num_samples)

# Reproducible: the resolved spec serialises to JSON and back.
j = Composer(timeline).to_json()
assert np.array_equal(Composer.from_json(j).compose(), iq)

# Utilities
mls_poly(7)                               # 0x41 — the length-7 MLS polynomial

The builders tone() / bpsk() / qpsk() / pn() / noise() / chirp(f_start=…, f_end=…, span=…) / bits(data=…, modulation=…) each return a Synth (a noise(level=…) is a bare AWGN floor at that level in dBFS; a chirp is an LFM sweep; a bits(...) sends its data source's bits); or construct Synth(...) directly. In a Segment.sum the per-synth snr resolves into one shared noise floor, and each synth's level (dBFS) sets its share.

Getting samples into and out of a file is its own topic — Writer, its dual Reader, content-based file-type detection, and what metadata each file type survives are all on Python: Capture I/O. For SigMF, pair a Writer(..., file_type="sigmf") data file with Composer(...).to_sigmf(...), which is the piece that knows the scene and can therefore annotate it.

DSP helpers rrc_taps(beta, sps, span) and dsss_spread(syms, code, sf) expose the pulse-shaping and spreading primitives.

Taps or pulse? rrc_taps returns taps on an integer sample grid, which is what a filter needs. rrc_h(t, beta) and rc_h(t, beta) evaluate the same pulses analytically at arbitrary times in symbol periods — use those when a stimulus has no grid to sample, which is any non-integer samples-per-symbol or any fractional timing offset. rrc_h is the root raised cosine, the transmit half of a matched-filter pair; rc_h is the full raised cosine, already the Nyquist response that pair produces, so it models the matched-filter output directly (a timing-detector S-curve reference, say).

SampleClock (POSIX) paces and timestamps a stream against an ideal fs-Hz clock — the same C core behind the wfmgen --realtime CLI flag. Use it to throttle a producer to real time and to tag blocks with their ideal timestamp:

from doppler.wfm import Composer, SampleClock, StreamSink

# Stream at the true 1 MS/s instead of as fast as possible. Requires a
# nats-server reachable at the endpoint.
comp = Composer(type="qpsk", sps=8, continuous=True)
clk = SampleClock(fs=1e6)
with StreamSink("nats://127.0.0.1:4222/iq") as sink:
    while True:
        blk = comp.execute(4096)
        ts = clk.stamp()              # ideal ns timestamp of this block
        sink.send(blk, fs=1e6, fc=0.0)
        clk.pace(len(blk))            # sleep to epoch + n/fs (GIL released)

The schedule is drift-free (deadlines come from the cumulative sample count, not summed sleeps); underruns are counted in clk.underruns / clk.max_lateness, and SampleClock(fs, resync=True) re-anchors to "now" on each underrun.

Module-level helpers

The SigMF sidecar is now Composer(...).to_sigmf(...) — see the Composer class above. write_blue_header (detached BLUE headers) is on Python: Capture I/O.

Modulation & SNR helpers

Low-level primitives behind the modulated types and the SNR model, exposed for callers who build their own symbol streams or noise budgets: bpsk_map / qpsk_map map bits (and Gray-coded symbol indices) to unit-energy constellation points, wfm_ebno_to_snr_db converts an Eb/No target to the over-fs SNR the generator actually places, and wfm_awgn_amplitude returns the noise amplitude for a given SNR.

draws() — what a ranged scene actually drew

A ranged field is re-picked at random for every repeat instance, so the scene declares a span while each burst flies one value out of it. Scoring a receiver means knowing which value, and the span cannot tell you — read the range's lo instead and you are wrong by up to its width.

draws(scene) returns one record per source per instance: where it sits (seg, instance, src, start, delay, on, off) and what it drew (freq, f_end, snr, level, doppler, doppler_rate). These are the same rows a capture's SigMF metadata is built from — both read through dp_wfm_compose_draws() in C — so an in-process render and a written capture cannot disagree about what was generated.

Plan — prepare-once stimulus engine

A composed scene is a linear form Σ gainₖ·signalₖ + noise, and the expensive DSP lives entirely in the signal terms — invariant across a parameter sweep. prepare(scene) renders and caches each source once; Plan.render / Plan.at then re-materialize any variation (per-source gains / phases / enable, global snr, Monte-Carlo seed) as a cheap re-weighted sum, bit-for-bit identical to a full compose. The stimulus for a detection/BER sweep or a Monte-Carlo campaign that re-runs one scene at many operating points — see the guide, and the DSSS BER Monte Carlo for one driving a receiver.

A prepared Plan can be saved and restored: plan.save() returns the cache as bytes and plan.dump(path) writes it to a file; PlanFromBlob(blob) and PlanFromFile(path) reconstruct a Plan without re-running prepare() (the blob carries a DSP-source fingerprint, so a stale cache transparently rebuilds rather than returning wrong samples).

Reach for it to checkpoint or resume a live Plan, not to move one between processes — the blob is the whole rendered cache, so for a hand-off the spec JSON is the thing to ship. The reasoning, with the sizes: Prepare Once, Sweep Many.

field_bits — a Field, from its text

The one door from text to the bits every frame object takes. A literal is written as its bits (1101) or in hex (0x1ACFFC1D); a generated field names its generator (pn:1023:10, gold:…, dotted:16); any of them may repeat (pn:31:5*4). The grammar is Fields: bits as text, read by one C function, and text outside it raises rather than coming back empty.

Frame — the bit layout, held by both ends

A frame is [preamble × reps | sync | payload | CRC], and the point of describing it as an object is that the transmitter and the receiver hold the same description. The generator takes the frame as a description too (Segment(frame=…), or wfmgen --sync … / --frame FILE); Frame is the same layout on the analysis side, so a capture is scored against the frame that was actually sent rather than one reconstructed from parts.

Each of the three fields is bits — one per element, each 0 or 1 — and is omitted when absent, the convention wfm_seq_t itself uses (a zero length). A field a receiver can regenerate — a PN or Gold sequence — is written as text and turned into bits by field_bits, so its truth is a handful of numbers (field_bits("pn:1023:10")) rather than a stored array, and a capture stays reproducible from its metadata alone. An element that is not a bit is refused, not masked.

crc_ok is the one that earns its place. It needs no payload truth at all, so it works on a real capture, and unlike a self-referenced EVM or a blind M2M4 it still catches a false lock — a rotated constellation fails the check rather than looking clean. Paired with FrameMeter, that is a frame error rate measured on a signal nobody knows the contents of:

import numpy as np

from doppler.ber import FrameMeter
from doppler.wfm import Frame

sync = np.array([1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1], np.uint8)  # Barker-13
payload = np.array([0, 1, 1, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0, 1], np.uint8)

f = Frame(sync=sync, payload=payload, crc="crc16")   # no preamble: omitted

# Stand-in for a capture: the frame as sent, and the same frame with one
# payload bit knocked over. On a real record these come from a demodulator.
clean = f.bits()
damaged = clean.copy()
damaged[f.field_off(f.field_index("payload"))] ^= 1
captured_frames = [clean, clean, damaged, clean, damaged]

m = FrameMeter(target_errors=2)
for rx_bits in captured_frames:        # one frame's bits per iteration
    m.add(sync_ok=1, crc=f.crc_ok(rx_bits))
    if m.enough:                        # stop on error count, not frame count
        break

assert m.errors == 2 and m.crc_passed == 3
print(m.fer().lo)                      # assert on `lo`, never on `p_hat`

A frame is read by field NAME: field_index("payload") finds the field, and field_off(i) / field_bits(i) give where it sits and how long it is, in bits from the start of the frame. A Frame holds only the fields it was given, so an omitted preamble takes no index. The CRC field is 16 bits, or 0 when the payload is empty: a CRC over nothing protects nothing, so it is dropped rather than carried as a trailer over no data.

FrameDesc — the same frame, deferred

Frame names three fields and a CRC and materialises them in the constructor. FrameDesc takes the same arguments and stops before laying anything out, so they are a starting point a caller extends with add_field(), add_derived() and add_stage() before calling build(). Omit them all to begin from nothing. Every field is bits; text reaches it through field_bits.

That is what makes a frame doppler has never heard of describable from Python. The two axes it adds over the named layout are:

  • A field is anything on the wire, whether the caller supplies it or a stage produces it. A parity block nobody passes in is still a field — declare it with add_derived(name, bits); the stage whose cover ends on it fills it.
  • A stage declares the span it covers, as first_field / n_fields, rather than inheriting "everything before me". A stage covering no fields does not run. This is the part a pipeline representation cannot express, and it is exactly what a CCSDS CADU needs: the inner code covers the attached sync marker, while the outer code and the randomiser start behind it.

A CADU — attached sync marker, RS(255,223) parity, randomiser — described end to end, with no ccsds_tm binding involved:

import numpy as np

from doppler.ccsds import asm_bits
from doppler.wfm import STAGE_RANDOMISE, STAGE_RS, STAGE_USER, FrameDesc

K, E2 = 223, 32                      # RS(255,223): 223 data, 32 parity octets

asm = asm_bits()                     # 0x1ACFFC1D, never transcribed by hand
octets = np.array([(i * 29 + 5) & 0xFF for i in range(K)], np.uint8)
data = np.unpackbits(octets).astype(np.uint8)

d = FrameDesc()                                  # begin from nothing
assert d.add_field("asm", asm) == 0              # attached sync marker
assert d.add_field("data", data) == 1            # the transfer frame
assert d.add_derived("parity", E2 * 8) == 2      # the outer code fills it

# Both stages start at field 1, so both skip the marker -- declared, not
# inherited.
assert d.add_stage(STAGE_RS, first_field=1, n_fields=2, depth=1) == 0
assert d.add_stage(STAGE_RANDOMISE, first_field=1, n_fields=2) == 1
d.build()

assert d.nbits == 32 + 255 * 8                   # marker + one RS codeblock
assert (d.stage_first(0), d.stage_bits(0)) == (32, 2040)

r = d.check(d.bits(1))
assert (r.passed, r.ok, r.units) == (1, 2, 2)   # one check per stage reversed

check() is the receive mirror of bits(), reading the same description — so a transmitter and a receiver holding one FrameDesc cannot disagree about which stage covered what. On a coded link it reports more than a verdict: an outer code says how much repair a frame took, and that is margin being spent while it is still there to spend. A CRC cannot report it at all, which is why an outer code is a strictly better detector and not merely a stronger one:

rx = np.asarray(d.bits(1)).copy()
rx[100] ^= 1                            # two bit errors inside one RS symbol
rx[101] ^= 1

r = d.check(rx)
assert r.passed == 1                    # still good ...
assert (r.corrected, r.symbols) == (1, 1)   # ... and it cost one symbol

Read a built description with n_fields() / n_stages() and the indexed field_off(), field_bits(), stage_first(), stage_bits(). layout() is the named view and reports zeros for a description assembled this way; a Frame is one configuration of the same object, so the indexed accessors read it too.

Stage kinds

add_stage() takes the kind as a number, and doppler.wfm exports the names for it:

constant what the stage does
STAGE_CRC16 CRC-16-CCITT over the covered bits, into a derived field
STAGE_RS a Reed-Solomon code, interleaved to depth
STAGE_RANDOMISE XOR a pseudo-random sequence, in place
STAGE_CONV a convolutional code, expanding by emit_num / emit_den
STAGE_INTERLEAVE a block interleaver: permute in place, length unchanged
STAGE_USER the first kind reserved for callers

These are generated from wfm_stage_kind_t by scripts/gen_stage_kinds.py, so they cannot drift from the C the way five hand-written copies of CRC16, RS, RANDOMISE, CONV = 0, 1, 2, 3 had begun to (#1223).

The kind stays a number on purpose. It is an open uint32_t, not a menu: doppler promises never to allocate at or above STAGE_USER, so a kind you choose today cannot collide with a built-in added later. Take STAGE_USER + n, supply the kernel through the ops table, and the description carries it:

# A fresh description under its own name: this page is one namespace, and
# `d` above is the CADU the rest of it goes on to check.
mine = FrameDesc()
mine.add_field("bits", np.ones(8, np.uint8))
assert mine.add_stage(STAGE_USER + 1, first_field=0, n_fields=1) == 0

A named choice list would read better and would refuse exactly that call, which is why the nicer spelling was measured and rejected.

Supplying the kernel is a C contract, not a Python one — a per-stage Python callback would make the one surface that must stay fast the one that cannot be (#1125). So build() refuses a kind it has no kernel for, and a Python caller reaches the same end by running the transform itself and handing the wire the result: src/doppler/examples/frame_own_stage_demo.py does exactly that, end to end, and native/examples/wfmgen_frame_demo.c §6 does it the C way with an ops table. Both are self-validating.

Acquiring one — where a received frame starts

check() scores a frame you were handed. Finding one in a bit stream is the other half, and it lives in doppler.detection: SyncFinder correlates a known marker against every offset, in both polarities. asm_bits() is what gives it the CCSDS marker without anyone transcribing 0x1ACFFC1D a second time — an MSB-first expansion written out twice is one that can disagree with itself, and a receiver that disagrees with the assembler about the marker syncs to nothing.

from doppler.detection import SyncFinder

rng = np.random.default_rng(7)
lead = rng.integers(0, 2, 96).astype(np.uint8)      # stream before the frame
stream = np.concatenate([lead, np.asarray(d.bits(1))])
stream = (stream ^ 1).astype(np.uint8)             # ...and a 180-degree flip

f = SyncFinder(asm_bits())
hit = f.find(stream, max_errors=f.max_errors_for(96, pfa=1e-3))

assert (hit.found, hit.offset, hit.inverted) == (1, 96, 1)

rx = stream[hit.offset : hit.offset + d.nbits] ^ 1  # undo what it reported
assert d.check(rx).passed == 1

The polarity flag is not a convenience. A complemented CADU passes its own outer code: Reed-Solomon is linear and the all-ones vector is itself a full-length codeword, so a global flip lands on another codeword and the decoder has nothing to object to. A receiver that acquired at the right offset and ignored inverted would score a clean PASS on a frame whose every payload bit is wrong. The marker is what can see it, because no randomiser covers it.

The marker itself is documented with the rest of the standard's literals: Python CCSDS API.