CppSDR: Real-Time DSP in C++, a Companion to PySDR

This textbook is based on the fantastic PySDR and is meant as an addition on how to realise the concepts it discusses in C++. PySDR teaches you what a filter, an oscillator or a Costas loop does. This companion takes the same building blocks and asks what it takes to run them on a real stream of samples, on time, every time: which C++ language features matter, which implementation strategies compete, and what each of them actually costs, measured rather than guessed.

Every chapter starts where a PySDR chapter ends, implements its topic several ways in C++, checks each version against a reference (often PySDR’s own Python code) and measures them side by side. All code, benchmarks and the scripts that draw the figures are part of the book, so you can repeat every measurement on your own machine.

A few things you will find inside:

  • PySDR’s filter designs (firwin, the fractional delay filter, the raised cosine) computed by the compiler, checked with static_assert, and matching SciPy to float precision; plus a 0/0 in the raised cosine that a +1e-20 does not fix (Compile-Time DSP: Filters, Tables and Constellations).

  • PySDR’s ADS-B link budget where adding a dBm to a dBW, or two powers in dB, is a compile error, and the SNR requirement is checked while compiling (Decibels with a Dimension: a Link Budget the Compiler Checks).

  • PySDR’s RDS decoder as a std::variant state machine with computed code tables, tested group-for-group against the Python original (Bits and State Machines: Decoding RDS).

  • All 32 GPS C/A codes generated by the compiler, three descriptions from the GPS specification checked against each other, and PySDR’s GPS acquisition reproduced satellite for satellite on its recording (Spreading Codes: GPS C/A Codes at Compile Time).

  • A fixed-point type whose result widths follow VHDL-2008’s fixed_pkg, a bit-true CIC model, and test vectors for a VHDL implementation (Fixed Point and CIC Filters: the Bridge to VHDL).

  • An integer phase accumulator, the one every FPGA uses, as the only oscillator whose error stays flat over a billion samples (Oscillators and Frequency Shifting).

  • PySDR’s Costas loop in C++, and why the speed of a feedback loop is limited by latency, not arithmetic (Feedback Loops: the Costas Loop).

  • PySDR’s complete FM and RDS receiver running on its own recording, matching the Python at every stage, decoding every RDS group the Python finds, on one thread or three (A Complete Receiver).

  • Window sidelobes and Hamming-code distances proven by the compiler, with an FFT and an exhaustive search that run inside static_assert (The FFT and the Spectrogram, Channel Coding).

  • All three of PySDR’s direction-finding scans (conventional, MVDR, MUSIC) reproduced on its scenario, with MVDR computed from one Cholesky factorization instead of a pseudo-inverse per angle, and a small Hermitian eigensolver (Beamforming and Direction of Arrival).

  • A Zadoff-Chu preamble that turns a frequency offset into a timing error instead of a missed packet, and an eye diagram that is a zero-copy std::mdspan view with a custom layout (Correlating Under Frequency Offset, Pulse Shaping and the Eye Diagram).

  • PySDR’s x = x*0.99 + new*0.01, which in float never reaches zero but sticks at a subnormal number forever, and an 8th-order Butterworth filter that rounding to float makes unstable (IIR Filters and Denormals).

  • An LDPC code designed by the compiler and proven free of 4-cycles, a sum-product decoder that makes the same decisions as GNU Radio’s 13 times faster, and an 8-bit layered min-sum decoder that needs no noise estimate (LDPC Codes: Messages Live on Edges).

  • A complete coded QPSK link assembled from the book’s blocks, within 10 to 15 % of ideal QPSK, and an OFDM receiver that finds its symbols from the cyclic prefix (Digital Modulation, End to End, OFDM: Transmitter and Receiver).

  • PySDR’s cyclic autocorrelation in 105 ms instead of 27 s, and a detector that finds OFDM 5 dB below the noise without any synchronization (Cyclostationary Processing).

  • PySDR’s null steering, whose one-null-at-a-time update leaves three of its four nulls at −29 to −45 dB, made exact and checked by the compiler; PySDR’s LMS beamformer reproduced to \(3 \times 10^{-16}\) (Null Steering and LMS).

  • GNU Radio’s correlation estimator run in a flowgraph: its sub-sample estimate returns about 0.6 times the true offset, and a peak on a work() boundary is refined from outside the buffer. The TDOA position solver as GPS backwards, at the Cramér-Rao bound (TDOA: Delays, Peaks and Positions).

  • GNU Radio’s corr_est_cc, whose dynamic threshold tags 0 of 12 bursts or all 12 depending on how the scheduler cuts the stream, and a detector whose tags, messages and PDUs are bit-identical for every call size from 1 to 100 samples (Tags, Messages and Bursts in GNU Radio).

  • A moving emitter that plain cross-correlation cannot see at all, found by the cross-ambiguity function to 0.012 samples and 0.05 Hz; the delay-Doppler plane in 10 ms with Stein’s decimation (Delay and Doppler: the Ambiguity Function).

  • A waterfall that sees every sample, shows a 0.5 ms burst that averaging and GNU Radio’s sink miss, never makes the radio wait for the screen, and is tested pixel for pixel without a window (Real-Time Display: Two Threads, No Waiting).

Contents