Fundamentals of Error-Correcting Codes

Definition:

Block Code

An (n,k)(n, k) binary block code C\mathcal{C} is a set of 2k2^k binary codewords, each of length nn bits. The code maps a kk-bit message u∈{0,1}k\mathbf{u} \in \{0,1\}^k to an nn-bit codeword c∈{0,1}n\mathbf{c} \in \{0,1\}^n.

The code rate is Rc=k/nR_c = k/n, representing the fraction of bits that carry information. The remaining nβˆ’kn - k bits provide redundancy for error detection and correction.

A code is linear if the sum (modulo 2) of any two codewords is also a codeword. All codes discussed in this chapter are linear.

Definition:

Generator Matrix and Parity-Check Matrix

For a linear (n,k)(n, k) code, the generator matrix G\mathbf{G} is a kΓ—nk \times n binary matrix such that every codeword is

c=uG(mod2)\mathbf{c} = \mathbf{u} \mathbf{G} \pmod{2}

The parity-check matrix H\mathbf{H} is an (nβˆ’k)Γ—n(n-k) \times n binary matrix satisfying

HcT=0(mod2)\mathbf{H} \mathbf{c}^T = \mathbf{0} \pmod{2}

for every codeword c∈C\mathbf{c} \in \mathcal{C}. The matrices are related by GHT=0\mathbf{G} \mathbf{H}^T = \mathbf{0}.

In systematic form, G=[Ik∣P]\mathbf{G} = [\mathbf{I}_k \mid \mathbf{P}] and H=[βˆ’PT∣Inβˆ’k]\mathbf{H} = [-\mathbf{P}^T \mid \mathbf{I}_{n-k}] (over GF(2)\mathrm{GF}(2), βˆ’1=1-1 = 1).

The syndrome s=HrT\mathbf{s} = \mathbf{H} \mathbf{r}^T of a received word r\mathbf{r} identifies the error pattern. If s=0\mathbf{s} = \mathbf{0}, either no errors occurred or the error pattern is an undetectable codeword.

Definition:

Hamming Distance

The Hamming distance d(ci,cj)d(\mathbf{c}_i, \mathbf{c}_j) between two binary vectors is the number of positions in which they differ:

d(ci,cj)=βˆ₯ciβŠ•cjβˆ₯H=βˆ‘β„“=1n(ci,β„“βŠ•cj,β„“)d(\mathbf{c}_i, \mathbf{c}_j) = \|\mathbf{c}_i \oplus \mathbf{c}_j\|_H = \sum_{\ell=1}^{n} (c_{i,\ell} \oplus c_{j,\ell})

The minimum distance of the code is

dmin⁑=min⁑ciβ‰ cj∈Cd(ci,cj)d_{\min} = \min_{\mathbf{c}_i \neq \mathbf{c}_j \in \mathcal{C}} d(\mathbf{c}_i, \mathbf{c}_j)

For a linear code, dmin⁑d_{\min} equals the minimum Hamming weight (number of ones) among all non-zero codewords.

Theorem: Error Detection and Correction Capability

A code with minimum distance dmin⁑d_{\min} can:

  • Detect up to dminβ‘βˆ’1d_{\min} - 1 errors.
  • Correct up to t=⌊(dminβ‘βˆ’1)/2βŒ‹t = \lfloor (d_{\min} - 1) / 2 \rfloor errors.

Equivalently, a code can correct tt errors if and only if dmin⁑β‰₯2t+1d_{\min} \geq 2t + 1.

If all codewords are at least dmin⁑d_{\min} apart, then tt errors move a codeword to a point that is still closer to the original codeword than to any other, provided t<dmin⁑/2t < d_{\min}/2. The decoder picks the nearest codeword and recovers the original.

,

Hamming Sphere Packing Geometry

Visualises the geometric intuition behind error correction: codewords are points separated by minimum distance dmin⁑d_{\min}, and Hamming spheres of radius tt around each codeword must be disjoint for unique decoding.
Error correction as sphere packing: the decoder maps any received word to the nearest codeword within its Hamming sphere.

Hamming Code Error Correction Demo

Explore how (n,k)(n, k) Hamming codes detect and correct errors. Adjust the code parameters to see the generator matrix, parity-check matrix, minimum distance, and a simulation of error correction performance.

Parameters
7
4

Example: The (7, 4) Hamming Code

The (7,4)(7, 4) Hamming code has the systematic generator matrix

G=[1000110010001100101010001111]\mathbf{G} = \begin{bmatrix} 1 & 0 & 0 & 0 & 1 & 1 & 0 \\ 0 & 1 & 0 & 0 & 0 & 1 & 1 \\ 0 & 0 & 1 & 0 & 1 & 0 & 1 \\ 0 & 0 & 0 & 1 & 1 & 1 & 1 \end{bmatrix}

(a) Find the parity-check matrix H\mathbf{H}.

(b) Determine dmin⁑d_{\min} and the error-correcting capability.

(c) Encode the message u=[1β€…β€Š0β€…β€Š1β€…β€Š1]\mathbf{u} = [1\; 0\; 1\; 1] and decode the received word r=[1β€…β€Š0β€…β€Š1β€…β€Š1β€…β€Š1β€…β€Š0β€…β€Š0]\mathbf{r} = [1\; 0\; 1\; 1\; 1\; 0\; 0] (which has a single bit error).

Definition:

Coding Gain

The coding gain Ξ³c\gamma_c of a code is the reduction in Eb/N0E_b/N_0 (in dB) required to achieve a target BER compared to uncoded transmission:

γc=(Eb/N0)uncoded(Eb/N0)coded∣same BER\gamma_c = \left.\frac{(E_b/N_0)_{\text{uncoded}}}{(E_b/N_0)_{\text{coded}}}\right|_{\text{same BER}}

For a binary code with rate RcR_c and minimum distance dmin⁑d_{\min}, the asymptotic coding gain (at high SNR) is

Ξ³cβ‰ˆRcβ‹…dmin⁑\gamma_c \approx R_c \cdot d_{\min}

In dB: Ξ³c (dB)=10log⁑10(Rcβ‹…dmin⁑)\gamma_c\,(\text{dB}) = 10\log_{10}(R_c \cdot d_{\min}).

Soft-decision decoding provides approximately 2-3 dB additional coding gain compared to hard-decision decoding, effectively doubling dmin⁑d_{\min} in terms of effective Euclidean distance.

Quick Check

A linear block code has minimum distance dmin⁑=7d_{\min} = 7. How many errors can it correct?

2

3

6

7

Common Mistake: Hard vs. Soft Decision Decoding

Mistake:

Using hard-decision decoding (quantising channel output to 0/1 before decoding) and expecting the same performance as soft-decision decoding.

Correction:

Hard-decision decoding discards reliability information from the channel. Soft-decision decoding uses the actual channel output values (e.g., LLRs) and achieves approximately 2-3 dB better performance. For the AWGN channel, this difference stems from the fact that hard decisions lose 10log⁑10(Ο€/2)β‰ˆ210\log_{10}(\pi/2) \approx 2 dB of information at the quantiser.

Modern systems (turbo, LDPC, polar codes) universally use soft-decision decoding.

Hard vs. Soft Decision Decoding

PropertyHard DecisionSoft Decision
Input to decoderBinary bits (0 or 1)Real-valued LLRs or channel outputs
Information preservedOnly bit identityBit identity + reliability
Typical coding gain lossReference (0 dB)2-3 dB better than hard
Decoder complexityLowerHigher (real-valued arithmetic)
Example algorithmsSyndrome decoding, algebraicViterbi (soft), BCJR, belief propagation
Used in modern systemsRarelyUniversally (turbo, LDPC, polar)

Historical Note: Richard Hamming and Error-Correcting Codes (1950)

1950

Richard Hamming, working at Bell Labs, developed the first error-correcting codes in 1950 after becoming frustrated with unreliable relay-based computers that would discard his weekend computing jobs when a single bit error occurred. He asked: "If the machine can detect an error, why can't it locate the position of the error and correct it?" His (7,4)(7, 4) Hamming code β€” the first single-error-correcting code β€” launched the field of coding theory. He also introduced the concepts of Hamming distance and Hamming weight that remain fundamental today.

Key Takeaway

The minimum Hamming distance dmin⁑d_{\min} is the single most important parameter of a block code: it determines the error-correcting capability (t=⌊(dminβ‘βˆ’1)/2βŒ‹t = \lfloor (d_{\min}-1)/2 \rfloor), the asymptotic coding gain (Ξ³c=Rcβ‹…dmin⁑\gamma_c = R_c \cdot d_{\min}), and on fading channels, the diversity order. Soft-decision decoding recovers 2-3 dB that hard-decision decoding discards at the quantiser.

⚠️Engineering Note

Finite-Precision LLR Representation

In hardware implementations, log-likelihood ratios (LLRs) are represented with finite precision (typically 5-8 bits for the integer + fractional parts). This introduces quantisation effects:

  • Saturation: Large-magnitude LLRs are clipped, losing information about very reliable bits. Typical clipping range is [βˆ’8,+8][-8, +8] or [βˆ’16,+16][-16, +16].
  • Granularity: Small LLR differences are rounded, affecting decoder convergence for marginal bits.
  • Performance impact: Moving from floating-point to 6-bit fixed-point typically costs 0.05-0.1 dB; moving to 4-bit costs 0.2-0.5 dB.

The scale factor between channel LLRs and decoder internal precision must be carefully chosen β€” too small clips reliable bits, too large wastes resolution on unreliable bits.

Practical Constraints
  • β€’

    LLR quantisation typically 5-8 bits in hardware decoders

  • β€’

    Clipping range must balance saturation vs. resolution

  • β€’

    4-bit quantisation incurs 0.2-0.5 dB loss; 6-bit costs < 0.1 dB

Block Code

A mapping from kk-bit messages to nn-bit codewords (n>kn > k). A linear block code forms a kk-dimensional subspace of {0,1}n\{0,1\}^n under modulo-2 arithmetic.

Related: Generator Matrix and Parity-Check Matrix, Generator Matrix and Parity-Check Matrix, Hamming Distance

Hamming Distance

The number of positions in which two binary strings of equal length differ. The minimum Hamming distance of a code determines its error detection and correction capability.

Related: Block Code, Minimum Distance, Error Detection and Correction Capability

Coding Gain

The reduction in required Eb/N0E_b/N_0 to achieve a given BER when using channel coding versus uncoded transmission. Measured in dB.

Related: Rate, Minimum Distance

Parity-Check Matrix

An (nβˆ’k)Γ—n(n-k) \times n binary matrix H\mathbf{H} that defines a linear code as its null space: C={c:HcT=0}\mathcal{C} = \{\mathbf{c} : \mathbf{H}\mathbf{c}^T = \mathbf{0}\}. Used for syndrome-based error detection and decoding.

Related: Generator Matrix and Parity-Check Matrix, Syndrome, Block Code