Hamming Distance



  • The Hamming distance between two words (of the same size) is the number of differences between the corresponding bits. We show the Hamming distance between two words x and y as d(x, y).


  • The Hamming distance can easily be found if we apply the XOR operation (⊕)on the two words and count the number of 1's in the result. Note that the Hamming distance is a value greater than zero.


  • Example :The Hamming distance d(000, 011) is 2 because 000 ⊕ 011 is 011 (two 1's)


  • In a set of words, the minimum Hamming distance is the smallest Hamming distance between all possible pairs. We use dmin to define the minimum Hamming distance in a coding scheme.


  • When a codeword is corrupted during transmission, the Hamming distance between the sent and received codewords is the number of bits affected by the error. In other words, the Hamming distance between the received codeword and the sent codeword is the number of bits that are corrupted during transmission.


  • For example , if the codeword 00000 is sent and 01101 is received, 3 bits are in error and the Hamming distance between the two is d(00000, 01101) = 3.


  • Minimum Distance for Error Detection :


    • If "s" errors occur during transmission, the Hamming distance between the sent codeword and received codeword is "s". If our code is to detect up to "s" errors, the minimum distance between the valid codes must be "s + 1", so that the received codeword does not match a valid codeword.


    • In other words, if the minimum distance between all valid codewords is s + 1, the received codeword cannot be erroneously mistaken for another codeword. The distances are not enough (s + 1) for the receiver to accept it as valid. The error will be detected.


    • This is illustrated below.



Q. The minimum Hamming distance for our first code scheme (Table given below) is 2. This code guarantees detection of only a single error.



    DatawordsCodewords
    00000
    01011
    10101
    11110


  • For example, if the third codeword (101) is sent and one error occurs, the received codeword does not match any valid codeword.


  • If two errors occur, however, the received codeword may match a valid codeword and the errors are not detected.



Q. Our second block code scheme (Table below) has dmin = 3.



    DatawordsCodewords
    0000000
    0101011
    1010101
    1111110


  • This code can detect up to two errors. Again, we see that when any of the valid codewords is sent, two errors create a codeword which is not in the table of valid codewords.


  • The receiver cannot be fooled. However, some combinations of three errors change a valid codeword to another valid codeword. The receiver accepts the received codeword and the errors are undetected.



Q. A code scheme has a Hamming distance dmin = 4. What is the error detection and correction capability of this scheme?


  • This code guarantees the detection of up to three errors (s = 3), but it can correct up to one error.


  • In other words, if this code is used for error correction, part of its capability is wasted. Error correction codes need to have an odd minimum distance (3, 5, 7, ... ).


  • To guarantee correction of up to t errors in an cases, the minimum Hamming distance in a block code must be dmin = 2t + 1.