D1212 of 14
0 XP
  1. Hook
  2. Play
  3. Predict
  4. Name it
  5. Check
  6. Explain

D12 · Lesson 12 · Error control

Catching corrupted frames with a cyclic redundancy check, correcting single errors with the Hamming (7,4) code and its syndrome, minimum distance and what it buys, convolutional codes with Viterbi decoding, and comparing coded and uncoded links at the same energy per bit

However good the receiver, noise will sometimes flip a bit. A link has two defenses. Detection adds a checksum so the receiver knows a frame is damaged and can ask for it again; the CRC on every Ethernet frame, USB packet and Wi-Fi frame does this. Correction adds enough structured redundancy that the receiver can work out which bits were flipped and fix them on the spot, which matters when there's no time or no way to ask again: space probes, broadcast, storage.

  • The chance that a 4-bit word arrives wrong over BPSK, sent plainly or as a Hamming (7,4) codeword that corrects any single error, against Eb/N0.
  • The code spends 7 channel bits per 4 data bits, so each channel bit gets only 4/7 of the energy and is more often wrong. Correction more than makes up for it once the SNR is moderate.
  • At 10 dB the coded word error rate is 5.6 times lower; at low SNR the two meet, since too many bits are wrong for one correction to help.

Predict

A frame is corrupted by a long burst of random errors. What's the chance its 16-bit CRC still checks out?

Name it

The CRC

Treat the message bits as a polynomial and divide it by a generator polynomial in arithmetic modulo 2 (XOR without carries); the remainder is the CRC. CRC-16/CCITT uses x16+x12+x5+1 (0x1021). In software it's a 16-bit shift register: XOR each byte into the top, then shift eight times, XORing in 0x1021 whenever a 1 falls off. The receiver runs the same register over the message and the CRC together and expects 0.

Hamming codes

Three parity bits protect four data bits, each covering a different subset, so every single-bit error upsets a different combination of checks. The three failed checks, read as a binary number, the syndrome, are the position of the flipped bit.

Distance

The minimum distance d of a code is the fewest bits in which two codewords differ. It detects up to d − 1 errors, or corrects up to ⌊(d − 1)/2⌋. Hamming (7,4) has d = 3: it corrects 1, or detects 2.

Convolutional codes

A convolutional encoder slides a short shift register over the bit stream and sends two parity bits per input bit (rate 1/2). The classic K = 3 code with generators 111 and 101 turns 1, 0, 1, 1 into 11 10 00 01. Its free distance is 5. The Viterbi algorithm decodes it by tracking, for each of the 4 register states, the most likely path into it, and it works naturally with soft decisions, using the received analog values along with their signs. The asymptotic coding gain is 10log10⁡(Rdfree): 4.0 dB for this code, 7.0 dB for the K = 7 code (d = 10) used in Wi-Fi and by deep-space probes. Modern links use turbo, LDPC and polar codes, which come within a decibel of Shannon's limit.

Worked example

A link's channel bits are wrong with probability 0.01. How often is a 4-bit word wrong, sent plainly and with Hamming (7,4)?

Show the solution
  1. Sent plainly. Any of the 4 bits wrong spoils the word: P=1−0.994=3.9%
  2. With Hamming (7,4). A word fails only with two or more errors among 7: P=1−0.997−7(0.01)(0.99)6=0.20%
  3. Compare. That's about 19 times better.
  4. The catch. At the same energy per bit the coded bits are noisier, so the real gain is smaller, as the sim shows.

Answer 3.9% of words are wrong sent plainly, and 0.20% with Hamming (7,4).

Worked example

What CRC does CRC-16/CCITT-FALSE give for the ASCII string 123456789?

Show the solution
  1. Run the CRC over the nine bytes. It gives 0x29B1, the standard check value that every implementation is tested against.
  2. Check the residue. Appending it as the bytes 0x29, 0xB1 and running the CRC over all 11 bytes gives 0.

Answer 0x29B1.

Worked example

A link delivers 1000 frames a second, and one in a hundred has errors. How often does CRC-16 let a bad frame through?

Show the solution
  1. Bad frames per second. 1000×0.01=10
  2. Time between undetected errors. Each bad frame is undetected with probability about 2−16=1.5×10−5: t=21610s≈6600s≈1.8hours
  3. With a 32-bit CRC. t=23210s≈4.3×108s≈14years That's why fast links use CRC-32.

Answer one undetected error every 6600 s or so, about 1.8 hours; a CRC-32 stretches that to about 14 years.

Check

Write a CRC-16 and a Hamming (7,4) encoder and decoder.

Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.

Check

Channel bits are wrong with probability 0.003. How often does a Hamming (7,4) word fail to decode correctly?

Check

A code of rate 0.333 has free distance 5. What's its asymptotic coding gain?

Check

A code's minimum distance is 5. How many bit errors per word can it always correct?

Check

What fraction of badly corrupted frames, with effectively random remainders, does a 16-bit CRC fail to catch?

Check

Channel bits are wrong with probability 0.01. 4-bit words are sent plainly.

(a)

How often is a word wrong?

(b)

How often does a Hamming (7,4) word fail?

Check

A link delivers 100 frames a second, 0.1% of them with errors, checked by a 32-bit CRC.

(a)

How many bad frames slip through per second?

(b)

On average, how many hours between them?

Explain why

How does a Hamming code know which bit to correct?

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.