channel coding
Hamming Codes
You should know: error correcting codes, linear independence
Overview
Hamming codes are a family of linear error-correcting codes invented by Richard Hamming in 1950. The most common is the [7,4,3] code, which encodes 4 message bits into 7 codeword bits using 3 parity-check bits, achieving single-error correction and double-error detection (SECDED with an extra parity bit). Hamming codes are perfect codes — they achieve the Hamming bound with equality, meaning error spheres of radius 1 tile the space perfectly with no wasted space. For redundancy r bits, the Hamming code has parameters [2^r - 1, 2^r - 1 - r, 3]. They are used in ECC RAM and data storage systems.
Intuition
In the [7,4,3] Hamming code, three parity bits are placed at positions 1, 2, and 4 (powers of 2). Each parity bit covers a specific set of data positions. When a bit error occurs, exactly the parity checks covering that position will fail. The binary pattern of failing parity checks gives the binary address of the error — the 'syndrome' points directly to the corrupted bit. It is like a binary search: three yes/no parity checks locate one error in 7 bits, since 2³ - 1 = 7.
Formal Definition
The [7,4,3] Hamming code is defined by the parity-check matrix H (3×7) whose columns are the binary representations of 1 through 7:
Notation
| Notation | Meaning |
|---|---|
| Parity-check matrix | |
| Syndrome vector s = Hr mod 2 | |
| Hamming code parameters for r parity bits |
Theorems
Worked Examples
- 1
Message bits go to positions 3,5,6,7. Parity bits at positions 1,2,4 must be computed.
- 2
p₁ (position 1) covers positions 1,3,5,7: p₁ ⊕ c₃ ⊕ c₅ ⊕ c₇ = 0, so p₁ = 1⊕0⊕1 = 0.
- 3
p₂ (position 2) covers positions 2,3,6,7: p₂ = c₃ ⊕ c₆ ⊕ c₇ = 1⊕1⊕1 = 1.
- 4
p₄ (position 4) covers positions 4,5,6,7: p₄ = c₅ ⊕ c₆ ⊕ c₇ = 0⊕1⊕1 = 0.
- 5
Codeword: (p₁,p₂,c₃,p₄,c₅,c₆,c₇) = (0,1,1,0,0,1,1).
✓ Answer
Encoded codeword is 0110011.
Practice Problems
Determine the parameters [n, k, d] of the Hamming code with r = 4 parity bits.
Explain why Hamming codes are called 'perfect codes' and what that means geometrically.
Common Mistakes
Thinking the parity-check matrix H and generator matrix G are the same thing.
G (k×n) encodes messages into codewords: c = mG. H ((n-k)×n) verifies codewords: Hc^T = 0. They satisfy GH^T = 0.
Assuming the syndrome tells you which bit was flipped in the original message, not in the codeword.
The syndrome gives the position of the error in the n-bit codeword, not the k-bit message. After correcting the codeword, you extract the message bits.
Quiz
Historical Background
Richard Hamming worked at Bell Labs in the 1940s on electromechanical computers that frequently crashed due to bit errors in punched cards. The weekend batch-job machines would detect errors and restart from scratch rather than fix them. Hamming, frustrated by wasted computation, set out to devise a code that could automatically locate and correct single-bit errors. His 1950 paper introduced what we now call Hamming codes, along with the concept of Hamming distance.
- 1948
Hamming develops his coding idea while working on BSTJ computers at Bell Labs.
Richard Hamming
- 1950
Hamming publishes 'Error Detecting and Error Correcting Codes' in BSTJ.
Richard Hamming
- 1954
Extended Hamming code (SECDED) developed for practical memory applications.
- 1970s
Hamming codes adopted for ECC in computer memory (ECC RAM).
Summary
- Hamming codes [2^r-1, 2^r-1-r, 3] use r parity bits to protect 2^r-1-r message bits, correcting 1 error and detecting 2 errors.
- The syndrome s = Hr^T (mod 2) equals the binary address of the error position — decode by flipping that bit.
- Hamming codes are perfect codes: error spheres of radius 1 partition F₂^n exactly, achieving the Hamming bound with equality.
- The [7,4,3] Hamming code is the most common instance, with rate 4/7 ≈ 57%; used in ECC RAM.
References
- PaperHamming, R.W. (1950). Error Detecting and Error Correcting Codes. Bell System Technical Journal, 29(2), 147-160.
- BookMacKay, D.J.C. (2003). Information Theory, Inference, and Learning Algorithms. Cambridge University Press. Ch. 1.
- WebsiteWikipedia — Hamming code
Mathematics