Field Guide · algorithm

Also known as: Gray code, reflected binary code, Gray mapping

A Gray code (or reflected binary code) is an ordering of binary values in which each value differs from the next in exactly one bit.1 In digital radio it is the standard rule for mapping bits onto constellation points: adjacent points in a QAM or PSK diagram are labelled so that neighbours differ by a single bit. The result is that the most common demodulation mistake — sliding to an adjacent symbol — corrupts only one bit instead of several, directly lowering the bit error rate.

000001011010 110111101100 neighbours 000 ↔ 001 differ in 1 bit → an adjacent-symbol slip costs 1 bit error
Gray-labelled 8-PSK: every adjacent constellation point differs by one bit, so the dominant error — a slip to a neighbouring symbol — flips only one bit.

How it works

The construction is the reflected rule that gives the code its second name. Build the (n+1)-bit Gray sequence from the n-bit one by writing the list, mirroring it below, prefixing 0 to the top half and 1 to the bottom half. Equivalently, the Gray code g of an ordinary binary number b is g = b XOR (b >> 1), and the inverse recovers b by cumulatively XOR-ing the Gray bits from the most significant down. Either way, stepping from one value to the next toggles a single bit.

Applied to modulation, the constellation points are placed on their grid (for QAM) or circle (for PSK) and then labelled by walking a Gray sequence so that horizontal and vertical neighbours differ in one bit. Why this matters: at moderate signal-to-noise ratio, symbol errors are overwhelmingly nearest-neighbour errors — noise nudges the received point just across the decision boundary into the adjacent cell. With a Gray map that dominant error contributes exactly one bit error; with a naive binary map it might flip two or three. For a large constellation this pushes the bit-error-rate curve measurably to the left “for free,” since Gray mapping adds no redundancy and no bandwidth — it only chooses which label goes on which point.

In practice

  • QAM and PSK links — Wi-Fi, LTE, 5G NR, DVB, cable and DSL modems all Gray-map their 16-QAM, 64-QAM, 256-QAM (and higher) constellations. Two-dimensional QAM maps are Gray-coded independently along the in-phase and quadrature axes.
  • Differential schemes — systems like π/4-DQPSK carry information in phase transitions rather than absolute positions, and the transitions are Gray-mapped so a misjudged step costs one bit.
  • Rotary encoders and mechanics — the original engineering use: a Gray-coded position disc guarantees that as it rotates past a boundary, only one track changes at a time, eliminating the transient glitches a straight binary disc would produce when several bits flip together.

Gray coding is a labelling choice, not forward error correction: it reduces how many bit errors each symbol slip produces, but it adds no parity and cannot correct anything on its own. It composes with FEC — the demapper hands Gray-derived soft bits to a downstream decoder.

Relevance to SDR

Every multi-level digital-radio waveform a software receiver demodulates relies on Gray mapping to get from noisy IQ samples back to bits with the fewest errors, so the soft-decision bit demapper in an SDR chain assumes the Gray labelling defined by each standard. GopherTrunk decodes primarily constant-envelope C4FM/CQPSK and π/4-DQPSK trunking waveforms, and where those carry multi-bit symbols (dibits in P25, the QPSK-family constellations elsewhere) it must apply the correct Gray-to-bit mapping when converting demodulated symbols to bits — otherwise a single symbol slip would scramble several bits and defeat the frame’s error-correction coding downstream.

Sources

  1. Gray code — Wikipedia, for the reflected-binary construction, the b XOR (b >> 1) conversion, single-bit adjacency, and the constellation-mapping and rotary-encoder applications. 

See also