D4 · Lesson 8 · Error-correcting codes
Adding redundant bits so the receiver can find and fix errors, code rate and minimum distance, how many errors a code corrects, the repetition code that does worse than nothing, the Hamming (7,4) code, Reed–Solomon codes for bursts, and the modern codes that approach Shannon's limit
In 1947 Richard Hamming, frustrated that a relay computer at Bell Labs kept stopping over the weekend at the first error it detected, asked why it couldn't find and fix the error itself. His answer, a few extra parity bits computed so that any single flipped bit leaves a unique signature, began coding theory. Codes are now everywhere: in every disk, memory chip, QR code and radio link. They're how real systems approach the Shannon limit of lesson 6, by spending a little of the bandwidth on redundancy that lets the receiver correct what noise breaks.
- Bit error rates against for uncoded BPSK, a 3× repetition code with majority vote, and the Hamming (7,4) code, all with hard decisions.
- Coded bits get less energy each, since the same energy per information bit is shared among more transmitted bits, so the raw error rate p rises before decoding repairs it.
- The repetition code repairs too little to pay for its 3× overhead and stays worse than sending nothing extra. Hamming's code wins at high .
Predict
Each bit is sent three times and the receiver takes a majority vote. At the same energy per information bit, is this better or worse than sending each bit once?
Splitting the energy three ways makes each copy much more likely to flip: at 10 dB, p rises from 3.9 × 10⁻⁶ uncoded to 4.9 × 10⁻³ per copy. The vote fails when two or three copies flip, = 7.2 × 10⁻⁵, about 19 times worse than not coding at all. Good codes add far less redundancy per error they correct.
Name it
Rate and distance
An (n, k) block code turns k information bits into n coded bits: its rate is , and the link's data rate falls by that factor. The minimum distance is the fewest bits in which two codewords differ. A code can
- detect up to errors, and
- correct up to errors, by choosing the nearest codeword.
Energy per coded bit
At a fixed energy per information bit, each coded bit gets , so with BPSK the raw error rate before decoding is . A code helps only if its correction more than makes up for that.
Hamming codes
With m parity bits, and : (7,4), (15,11), (31,26). Each corrects one error ( = 3): the parity checks that fail, read as a binary number, point to the flipped bit. For small p, the (7,4) code's decoded bit error rate is about .
Stronger codes
- Reed–Solomon codes work on bytes and fix bursts: RS(255,223) corrects any 16 wrong bytes in 255. CDs, QR codes and deep-space links use them.
- Convolutional codes with Viterbi decoding, and soft decisions that pass the receiver's confidence along with each bit, gain about 2 dB more.
- Turbo and LDPC codes, decoded iteratively, operate within a decibel of Shannon's limit; LDPC codes are in Wi-Fi, 5G and DVB-S2.
Worked example
At = 10 dB, compare uncoded BPSK with the Hamming (7,4) code.
Show the solution
- Uncoded. The bit error rate is .
- Coded bits. They get 4/7 of the energy:
- After decoding.
- Compare. That's three times better, at the cost of sending 7 bits for every 4.
Answer the Hamming code gives 1.2 × 10⁻⁶ against 3.9 × 10⁻⁶ uncoded.
Worked example
How many errors can a code with = 7 correct? What's the rate of RS(255,223)?
Show the solution
- Errors corrected. errors, or 6 detected.
- Rate of RS(255,223).
- What RS(255,223) corrects. byte errors.
Answer it corrects 3 errors (or detects 6), and RS(255,223) has rate 0.875 and corrects 16 byte errors.
Worked example
A CRC-16 checks every frame. If 1000 frames a day arrive with random errors, how often does a bad frame slip through undetected?
Show the solution
- Chance a bad frame passes. A good 16-bit CRC passes a random error pattern with probability about
- Per day. That's 0.015 bad frames a day, about one every 66 days.
- A 32-bit CRC. With in place of , a bad frame slips through about once in 12,000 years.
Answer about one bad frame every 66 days.
Check
A code has minimum distance 5. How many errors per codeword can it always correct?
Check
A Hamming code has 4 parity bits. What's its rate?
Check
Each copy of a bit sent three times flips with probability 0.05. How often does the majority vote come out wrong?
Check
A rate-0.75 code sends BPSK at = 4 dB per information bit. What's the raw error rate of each coded bit before decoding?
Check
A block code has minimum distance 5.
(a)
How many errors can it correct?
(b)
How many can it detect, if it corrects none?
Check
A CRC of 16 bits checks frames; 100 frames a day arrive with random errors.
(a)
What fraction of bad frames slip through?
(b)
How many undetected bad frames is that per day?
Explain why
Why can a repetition code make a link worse, while a well-designed code makes it better?
At a fixed energy per information bit, every redundant bit a code adds takes some of that energy, so each transmitted bit is weaker and more likely to be flipped by noise. A code helps only if its ability to correct errors outweighs the extra errors this creates. Repeating each bit three times spends two thirds of the energy on redundancy and corrects only a single error per three bits, which is not enough to make up for the much higher raw error rate. A good code spreads a small amount of redundancy across many bits, so that each parity bit protects many data bits and the code corrects many errors per unit of overhead, giving a net gain.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.