Self correcting codes are constructed by combining data bits with a number of redundant check-bits, which together are referred to as codewords. By adding a single bit (as in Parity Checking) along with a given number of data-bits, half of the possible codewords become valid and half invalid. This is referred to as a code that has Hamming Distance 2 (two single bit flips are required to get from one calid code to another). This is insufficient for correcting invalid codes since it is impossible to determine whether the original valid codeword was the valid codeword one bit difference preceding the invalid one or one bit difference following the invalid one. In codes with Hamming Distance 3, every valid codeword has two unique invalid codewords exactly one bit different from itself. No valid codeword shares one-bit different invalid codes with any other valid code. Because of this, any given invalid codeword can be assumed (if we assume the possibility of only one bit-error per codeword) to be representative of the corresponding valid codeword with a single bit error. This particular approach, using Haming Distance 3, is the minimum requirement for self-error correction and is commonly referred to as a Hamming Code.
In 1948, Claude Shannon, of Bell Laboratories, published his paper "Mathematical Theory of Communication" and opened the door to the problem of digital communication error. Shortly afterward Richard Hamming, also of Bell Laboratories, discovered and implemented a concise and efficient algorithm for single-bit error correction codes. A decade later, among others, Irving Reed and Gustave Solomon, discovered algorithms which could be used for multiple error correction. Since that time, further research was made into multiple-bit error detection and recovery and it was discovered that some of these algorithms are in fact variations of some of Euclid's findings from 300 BC.
Firstly, the minimum number of check-bits required to implement a Hamming Code is given by the inequalitywhere d is the number of data-bits per codeword and c is the number of check-bits.d + c + 1 <= 2c
A codeword which satisfies the equationis know as a perfect Hamming Code and represents the most efficient combination of data-bits and check-bits which provide Hamming Distance 3.d + c + 1 = 2cConstructing a Hamming Codeword
We'll proceed by outlining how we construct a Hamming codeword with 11 data-bits and 4 check-bits (a perfect codeword). This specific combination of data and check bits is referred to as a (15,11) code for its 15 total bits of which 11 are real data. (Note that the choice of a (15:11) code is completely arbitrary and that this algorithm can be used for any number of data bits)Verifying a Hamming Codeword1) We label the check-bits with increasing powers of two:
C1, C2, C4, and C8
and interleave these with the given data-bits, giving:
C1, C2, D3, C4, D5, D6, D7, C8, D9, D10, D11, D12, D13, D14, D152) Each check bit is assigned the even parity value of the set of bits formed in the following way:
- given that p is the label of the particular check-bit
- including the first p-1 bit(s) starting with bit p+1, excluding the next p bit(s), including the next p bit(s), etc...C1 = D3(whereD5
D7
D9
D11
D13
D15
C2 = D3D6
D7
D10
D11
D14
D15
C4 = D5D6
D7
D12
D13
D14
D15
C8 = D9D10
D11
D12
D13
D14
D15
is the exclusive-or operator)
For example, the codeword for the data-bits 10010110011 would constructed as follows:
C1 C2 D3 C4 D5 D6 D7 C8 D9 D10 D11 D12 D13 D14 D15 ? ? 1 ? 0 0 1 ? 0 1 1 0 0 1 1 C1 = 1The codeword is then:0
1
0
1
0
1 = 0
C2 = 10
1
1
1
1
1 = 0
C4 = 00
1
0
0
1
1 = 1
C8 = 01
1
0
0
1
1 = 0
C1 C2 D3 C4 D5 D6 D7 C8 D9 D10 D11 D12 D13 D14 D15 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 This is where it pays of to have formed the codeword in such a specific manner.
The following is first calculated:S1 = D3D5
D7
D9
D11
D13
D15
C1
S2 = D3D6
D7
D10
D11
D14
D15
C2
S3 = D5D6
D7
D12
D13
D14
D15
C4
S4 = D9D10
D11
D12
D13
D14
D15
C8
If S1=S2=S3=S4=0, the codeword is valid, otherwise the number formed by taking S1 through S4 indicates the bit position of the bit which cause the codeword to be invalid. Obviously by complementing this bit, we form the original valid codeword (again assuming that only a single bit-error was possible).For example, the full codeword 001100100110011 of the previous example is verified by the following:
C1 C2 D3 C4 D5 D6 D7 C8 D9 D10 D11 D12 D13 D14 D15 0 0 1 1 0 0 1 0 0 1 1 0 0 1 1 S1 = 1Since all S's are 0, the codeword is deemed valid.0
1
0
1
0
1
0 = 0
S2 = 10
1
1
1
1
1
0 = 0
S3 = 00
1
0
0
1
1
1 = 0
S4 = 01
1
0
0
1
1
0 = 0
If we flip one of the bits in the full codeword, we'll see that the code is invalid and that the offending bit can be identified.
We'll take, for example, the codeword 001100100100011 (in which we flipped bit 11 from the previous example):
C1 C2 D3 C4 D5 D6 D7 C8 D9 D10 D11 D12 D13 D14 D15 0 0 1 1 0 0 1 0 0 1 0 0 0 1 1 S1 = 1This indicates an error. Furthermore, since S=1011 indicates position 11, we should flip bit 11. Making the correction gives us 001100100110011, the correct original codeword.0
1
0
0
0
1
0 = 1
S2 = 10
1
1
0
1
1
0 = 1
S3 = 00
1
0
0
1
1
1 = 0
S4 = 01
0
0
0
1
1
0 = 1
It should be noted that this algorithm works only for single-bit errors. Two-bit errors would be incorrectly mapped to a different original codeword and a three-bit error would not be cought. However, a two bit-error is detected (just not corrected properly), therefore this algorithm could be used for single and two-bit error detection (but not correction). To provide detection and correction for more bit errors, a code of higher Hamming Distance must be chosen and implemented accordingly.
| Overview of Forward Error Correction | An overview of Forward Error Correction at the WPI EE535 Telecommunications and Transmission Technologies Course Homepage. |
| ECC FAQs | A good overview of error correcting codes offered by ECC Technologies. |
| Communication Systems IV - Lecture 3 | An good description of basic error detection/correction as well as discussion of efficiency and probabilities associated with each. |
| Error Correction and the Hamming Code | A good description, including examples, of Hamming codewords. |
| Hamming Codes and Error Correction | A nice java applet demonstrating Hamming error correction at Math Alive from Princeton University. |
| ECC in Computer Memory | Another example of the application of Hamming Codes. Corsair Microsystems' description of the necessity and method of implementation of error-correction codes in RAM. |
| PDC Teletext description | An example of the application of Hamming Codes. PDC Live's description of the Teletext transmission system. |
| Bell Labs Museum - Hamming | If you want to see a picture of Richard Hamming... |
Any comments or criticisms are welcome.