1234567P1234567P124result–d1–d2–d3–d4–1import numpy as np2H = np.array([[1,0,1,0,1,0,1],3 [0,1,1,0,0,1,1],4 [0,0,0,1,1,1,1]])5r = np.array([0,1,1,0,1,1,1])6s = H @ r % 2010101010101010101010101010101010101010101010101010101
00.020.040.060.080.100.10.20.30.4p (chance one bit flips)block errorCHANCE 4 DATA BITS ARRIVE WRONG4 bare bitsHamming(7,4)p = 0.01: 3.9% vs 0.20%
Coloured parts: what the current step is about; everything else rests in whiteLamps: one bit each (lit = 1); pink lamps are parity bits, green lamps data bitsRed band: the noisy link · dashed rings: the group a parity bit checksTokens carry the bits across; the plot below shows how often a block arrives wrongHamming(7,4): the data 1011 is sent as 0110011; noise flips slot 5; the failed checks give the syndrome 101 = 5, and flipping slot 5 back recovers 1011. Richard Hamming published these codes at Bell Labs in 1950 (Bell System Technical Journal 29(2)). Most ECC memory uses a Hamming-type code with one extra parity bit (SECDED).

Bits go wrong

  1. Send four data bits, 1011, over a noisy link. Noise (random voltage added on the way) can push a bit past the receiver's cut-off between 0 and 1, so a 0 arrives as a 1. The receiver gets 1111 and cannot tell.

Building a Hamming code

Finding and fixing

Limits and code

The working

# step 1/11 · flip

sent      1011
noise     flips one bit (slot 5 here)
received  1111

1111 is also a valid message,
so nothing looks wrong.

why bits flip: the AWGN lesson
(noise + picking the nearest level)

The data 1011, the flipped slot 5 and the flip chance 1 in 100 are chosen examples. Every bit, check and percentage in the figure is computed from this model. The percentages assume each bit flips on its own with the same chance p (a binary symmetric channel). Real links also suffer bursts of errors in a row; the CRC lesson handles those.