FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Hamming_code

Hamming code

Contents
        Two-out-of-five code
        Repetition
    General algorithm
Hamming codes with additional parity (SECDED)
[7,4] Hamming code
    Encoding

''r''</sup> − 1}} where {{Math|''r'' ≥ 2}}"},"message_length":{"wt":"{{Math|2<sup>''r''</sup> − ''r'' − 1}}"},"rate":{"wt":"{{Math|1 − {{Sfrac|''r''|(2<sup>''r''</sup> − 1)}}}}"},"distance":{"wt":"{{Math|3}}"},"alphabet_size":{"wt":"{{Math|2}}"},"notation":{"wt":"{{Math|[2<sup>''r''</sup> − 1, 2<sup>''r''</sup> − ''r'' − 1, 3]<sub>2</sub>}}-code"},"properties":{"wt":"[[perfect code]]"}},"i":0}}]}'>
Binary Hamming codes
The Hamming(7,4) code (with r = 3)
Named afterRichard W. Hamming
Classification
TypeLinear block code
Block length2 − r − 1
Rate2
Notationn = 2 − 1 and message length ''r''</sup> − ''r'' − 1"}},"i":0}}]}'/>k = 2 − r − 1. Hence the rate of Hamming codes is ''r''</sup> − 1)"}},"i":0}}]}'/>R = k / n = 1 − r / (2 − 1), which is the highest possible for codes with minimum distance of three (i.e., the minimal number of bit changes needed to go from any code word to any other code word is three) and block length ''r''</sup> − 1"}},"i":0}}]}'/>2 − 1. The parity-check matrix of a Hamming code is constructed by listing all columns of length

Parity adds a single bit that indicates whether the number of ones (bit-positions with values of one) in the preceding data was even or odd. If an odd number of bits is changed in transmission, the message will change parity and the error can be detected at this point; however, the bit that changed may have been the parity bit itself. The most common convention is that a parity value of one indicates that there is an odd number of ones in the data, and a parity value of zero indicates that there is an even number of ones. If the number of bits changed is even, the check bit will be valid and the error will not be detected.

Moreover, parity does not indicate which bit contained the error, even when it can detect it. The data must be discarded entirely and re-transmitted from scratch. On a noisy transmission medium, a successful transmission could take a long time or may never occur. However, while the quality of parity checking is poor, since it uses only a single bit, this method results in the least overhead.

Two-out-of-five code

edit
(53)=10 possible combinations, enough to represent the digits 0–9. This scheme can detect all single bit-errors, all odd numbered bit-errors and some even numbered bit-errors (for example the flipping of both 1-bits). However it still cannot correct any of these errors.

Repetition

edit
n = 3 repetition code will send 111. If the three bits received are not identical, an error occurred during transmission. If the channel is clean enough, most of the time only one bit will change in each triple. Therefore, 001, 010, and 100 each correspond to a 0 bit, while 110, 101, and 011 correspond to a 1 bit, with the greater quantity of digits that are the same ('0' or a '1') indicating what the data bit should be. A code with this ability to reconstruct the original message in the presence of errors is known as an error-correcting code. This triple repetition code is a Hamming code with k − 1 errors.

Hamming was interested in two problems at once: increasing the distance as much as possible, while at the same time increasing the code rate as much as possible. During the 1940s he developed several encoding schemes that were dramatic improvements on existing codes. The key to all of his systems was to have the parity bits overlap, such that they managed to check each other as well as the data.

General algorithm

edit

The following general algorithm generates a single-error correcting (SEC) code for any number of bits. The main idea is to choose the error-correcting bits such that the index-XOR (the XOR of all the bit positions containing a 1) is 0. We use positions 1, 10, 100, etc. (in binary) as the error-correcting bits, which guarantees it is possible to set the error-correcting bits so that the index-XOR of the whole message is 0. If the receiver receives a string with index-XOR 0, they can conclude there were no corruptions, and otherwise, the index-XOR indicates the index of the corrupted bit.

An algorithm can be deduced from the following description:

  1. Number the bits starting from 1: bit 1, 2, 3, 4, 5, 6, 7, etc.
  2. Write the bit numbers in binary: 1, 10, 11, 100, 101, 110, 111, etc.
  3. All bit positions that are powers of two (have a single 1 bit in the binary form of their position) are parity bits: 1, 2, 4, 8, etc. (1, 10, 100, 1000)
  4. All other bit positions, with two or more 1 bits in the binary form of their position, are data bits.
  5. Each data bit is included in a unique set of 2 or more parity bits, as determined by the binary form of its bit position.
    1. Parity bit 1 covers all bit positions which have the least significant bit set: bit 1 (the parity bit itself), 3, 5, 7, 9, etc.
    2. Parity bit 2 covers all bit positions which have the second least significant bit set: bits 2–3, 6–7, 10–11, etc.
    3. Parity bit 4 covers all bit positions which have the third least significant bit set: bits 4–7, 12–15, 20–23, etc.
    4. Parity bit 8 covers all bit positions which have the fourth least significant bit set: bits 8–15, 24–31, 40–47, etc.
    5. In general each parity bit covers all bits where the bitwise AND of the parity position and the bit position is non-zero.

If a byte of data to be encoded is 10011010, then the data word (using _ to represent the parity bits) would be __1_001_1010, and the code word is 011100101010.

The choice of the parity, even or odd, is irrelevant but the same choice must be used for both encoding and decoding.

This general rule can be shown visually:

Bit position 1234567891011121314151617181920 ...
Encoded data bits p1 p2d1 p4d2d3d4 p8d5d6d7d8d9d10d11 p16d12d13d14d15
Parity
bit
coverage
p1

Shown are only 20 encoded bits (5 parity, 15 data) but the pattern continues indefinitely. The key thing about Hamming codes that can be seen from visual inspection is that any given bit is included in a unique set of parity bits. To check for errors, check all of the parity bits. The pattern of errors, called the error syndrome, identifies the bit in error. If all parity bits are correct, there is no error. Otherwise, the sum of the positions of the erroneous parity bits identifies the erroneous bit. For example, if the parity bits in positions 1, 2 and 8 indicate an error, then bit 1+2+8=11 is in error. If only one parity bit indicates an error, the parity bit itself is in error.

With 2m−m−1 bits remain for use as data. As n=2m−1

(2m−m−1)/(2m−1)

Hamming codes with additional parity (SECDED)

edit

Hamming codes have a minimum distance of 3, which means that the decoder can detect and correct a single error, but it cannot distinguish a double bit error of some codeword from a single bit error of a different codeword. Thus, some double-bit errors will be incorrectly decoded as if they were single bit errors and therefore go undetected, unless no correction is attempted.

To remedy this shortcoming, Hamming codes can be extended by an extra parity bit. This way, it is possible to increase the minimum distance of the Hamming code to 4, which allows the decoder to distinguish between single bit errors and two-bit errors. Thus the decoder can detect and correct a single error and at the same time detect (but not correct) a double error. If the decoder does not attempt to correct errors, it can reliably detect triple bit errors. If the decoder does correct errors, some triple errors will be mistaken for single errors and "corrected" to the wrong value. Error correction is therefore a trade-off between certainty (the ability to reliably detect triple bit errors) and resiliency (the ability to keep functioning in the face of single bit errors).

For k data bits, a SECDED scheme requires:

This extended Hamming code was popular in computer memory systems, starting with IBM 7030 Stretch in 1961, where it is known as SECDED (or SEC-DED, abbreviated from single error correction, double error detection). Common forms for memory systems include (39,32) and (72,64). (While it is more efficient to use a codeword length in the form of 2 - 1, existing computer data word sizes being powers of 2 preclude this choice, though communication and data storage system do take advantage.) Server computers in 21st century, while typically keeping the SECDED level of protection, no longer use Hamming's method, relying instead on the designs with longer codewords (128 to 256 bits of data) and modified balanced parity-check trees. The (72,64) Hamming code is still popular in some hardware designs, including Xilinx FPGA families.

[7,4] Hamming code

edit
𝐆:=(Ik−AT) is called a (canonical) generator matrix of a linear (n,k) code,

and 𝐆 and the parity-check matrix 𝐇:=(110110010110100111001)3,7.

Finally, these matrices can be mutated into equivalent non-systematic codes by the following operations:

  • Column permutations (swapping columns)
  • Elementary row operations (replacing a row with a linear combination of rows)

Encoding

edit
Example

From the above matrix we have 2 = 2 = 16 codewords. Let x→ for any of the 16 possible data vectors a→=[1,0,1,1]. Using the generator matrix 𝐆:=(11100001100110010101010111010010)4,8

and


View original on Wikipedia | Back | FazBrowse Home