Error Control Coding — Block codes, Hamming, CRC, Convolutional & Viterbi

← Home

Encode and decode block codes (Hamming 7,4 / extended Hamming 8,4 / repetition / even-parity), see the G and H matrices, the minimum distance dmin, and the error-correction capability. Demo single-bit error correction with syndrome lookup. Compute CRC-4/8/CCITT/16 with the LFSR state trace. Run a (7,5) convolutional encoder + Viterbi decoder on a trellis, see the survivor paths. BER vs Eb/N0 for coded vs uncoded BPSK over AWGN.

📡 EMFT Hub 📻 Modulation 📶 Digital Mod ⚡ Line Codes 🎚️ PCM / ADC 📊 Info Theory 🛡️ Error Coding ← Home

Block code

0.10

Hamming demo

(−1 = no error)

CRC

Convolutional / Viterbi

6.0
⚠ Common confusion: Block code (Hamming, BCH, RS) operates on fixed-size blocks of k bits → n bits. Convolutional code is a sliding window — output depends on the last K input bits, no block boundary. The Viterbi decoder is the optimal decoder for convolutional codes.
① Block code (G, H, dmin, BER curves)
Pick a code from the left. The generator matrix G (k × n) maps a k-bit message to an n-bit codeword: c = m · G (mod 2). The parity-check matrix H ((n-k) × n) is used for decoding: the syndrome s = r · HT is zero iff the received codeword r is a valid codeword. The minimum distance dmin is the smallest Hamming weight of any non-zero codeword; the code can correct ⌊(dmin−1)/2⌋ errors and detect dmin−1.
BER vs Eb/N0 for coded (Hamming 7,4) vs uncoded BPSK over AWGN (hard-decision). Coding gain: at BER = 10−3, the coded curve sits ≈ 2-3 dB to the left of uncoded. Below the code's error-correction threshold, coding helps; above it, the curves converge (we're running at the channel capacity limit).
Uncoded BPSK (theory: Q(√(2·Eb/N0))) Coded BPSK (Monte-Carlo sim with hard-decision Viterbi for the convolutional code, syndrome for the block code) current Eb/N0

📖 Deep-dive blog (planned)

  • Shannon's channel-coding theorem — for any rate R < C, there exists a code with BER → 0; for R > C, BER → ½. Capacity-approaching codes (LDPC, Turbo, Polar) approach this limit.
  • Hamming codes — the first non-trivial ECC (1950). Why 2r−1 codeword length for r parity bits, and the geometric interpretation of dmin = 3.
  • CRC design — how to pick a polynomial (irreducible, primitive, with good burst-error coverage). The 16 standard CRC polynomials and their use cases.
  • Convolutional codes — state, trellis, and the connection to linear time-invariant systems over GF(2). Why (7,5) is the canonical K=3 code.
  • Viterbi algorithm — derived from dynamic programming. ACS (add-compare-select) at each trellis step. Survivor-path memory and traceback depth.
  • Soft-decision Viterbi — replacing Hamming distance with Euclidean distance. ~2 dB coding gain over hard-decision at the same complexity.
  • Coding gain at low BER — the (7,5) code at BER = 10−5 gives ≈ 4 dB coding gain. Turbo codes (1993) get within 0.5 dB of capacity; LDPC codes (1962, rediscovered 1995) match that.
Status: scaffold shipped (engine + page). Blog content to follow.

Block code (live)

Code parameters
Code:
(n, k):
Rate R = k/n:
dmin:
t = ⌊(d−1)/2⌋ (correct):
d−1 (detect):

Hamming demo (live)

Encode / decode
Message m:
Codeword c:
Received r:
Syndrome s:
Decode status:
Corrected c':

CRC (live)

Polynomial
Poly:
Hex:
Init:
Computation
Message length:
CRC (hex):
CRC (bits):

Convolutional / Viterbi (live)

Encoder
Generators:
Constraint K:
Input length:
Output length:
Viterbi
States:
Final path metric:
Bit errors:
BER:
🚫 Pitfall: Don't trust the Hamming demo for double errors. The (7,4) code can correct 1 error or detect 2; the syndrome for a 2-bit error pattern is the sum (XOR) of two single-bit syndromes, which can match another single-bit syndrome. Result: wrong correction, no warning.
⚠ Soft vs hard decision: This page uses hard-decision Viterbi (input bits, not LLRs). Real systems (5G, satellite) use soft-decision Viterbi or BCJR with LLR inputs — ≈ 2 dB additional coding gain at the same code.