Docsity

Hamming Distance and Error Detection Codes: Parity Codes and Beyond, Study notes of Computer Science

Toggle sidebar
bg1
Information Redundancy
Prof. Naga Kandasamy
ECE Department, Drexel University, Philadelphia, PA 19104.
March 2, 2009
1 Hamming Distance
A fundamental concept in the characterization of both error detecting and error correcting code is the
Hamming distance. Given two binary words, the hamming distance between the two words is the number
of bit positions in which the two words differ. For example, the binary words 0000 and 0001 differ in one
position, and so, have a Hamming distance of 1. The binary words 0010 and 0001 differ in two positions,
and so, have a Hamming distance of 2.
The code distance is the minimum Hamming distance between two valid code words. If a code has a distance
of two, any single-bit error introduced in the code word results in the erroneous word being an invalid code
word. A code distance of three allows us to detect errors in two bit locations, and also allows us to correct a
single-bit error, since the invalid word is a Hamming distance of 1 away from the valid word, and a Hamming
distance of 2 away from all other code words.
In general, a code can correct up to cbit errors and detect up to dadditional bit errors if and only if
2c+d+ 1 ≤Hd
where Hdis the Hamming distance of the code.
Codes can be of two types: separable or non-separable.
2 Parity Codes
Single parity codes require the addition of an extra bit to a binary word such that the resulting code either
has an even number of 1s or an odd number of 1s. If the extra bit results in the total number of 1s in the
code word being even, the code is called even parity. If the extra bit results in the total number of 1s in the
code word being odd, the code is called odd parity. Parity code is a separable code. The single-bit parity
codes (both even and odd) for BCD words are shown in Fig. 1. It can easily seen that the valid code words
have a Hamming distance of 2.
The most common application of parity is to protect the memories of computers used for safety-critical
applications such as those used in planes or cars. Before b eing written to memory, the data word is encoded
to achieve the desired parity. Encoding is the appending of the parity bit to force the result to have the
appropriate number of 1s. When the data word is read from memory, the parity bit is checked to verify that
the data has not been corrupted because of a fault affecting one or more memory cells. Fig. 2 shows this
process. Circuits to generate and check parity bits are fairly simple to design, and one such circuit is shown
in Fig. 3 for a 4-bit data word d3d2d1d0.
There are five basic parity approaches that can be used to detect faults in memory systems, as outlined in
Fig. 4.
•Bit-per-word parity. The simplest parity checking scheme is to assign a single parity bit (either
even or odd) to the data word. This can detect a single bit error. However, certain common types of
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Hamming Distance and Error Detection Codes: Parity Codes and Beyond and more Study notes Computer Science in PDF only on Docsity!

Information Redundancy

Prof. Naga Kandasamy

ECE Department, Drexel University, Philadelphia, PA 19104.

March 2, 2009

1 Hamming Distance

A fundamental concept in the characterization of both error detecting and error correcting code is the Hamming distance. Given two binary words, the hamming distance between the two words is the number of bit positions in which the two words differ. For example, the binary words 0000 and 0001 differ in one position, and so, have a Hamming distance of 1. The binary words 0010 and 0001 differ in two positions, and so, have a Hamming distance of 2.

The code distance is the minimum Hamming distance between two valid code words. If a code has a distance of two, any single-bit error introduced in the code word results in the erroneous word being an invalid code word. A code distance of three allows us to detect errors in two bit locations, and also allows us to correct a single-bit error, since the invalid word is a Hamming distance of 1 away from the valid word, and a Hamming distance of 2 away from all other code words.

In general, a code can correct up to c bit errors and detect up to d additional bit errors if and only if

2 c + d + 1 ≤ Hd

where Hd is the Hamming distance of the code.

Codes can be of two types: separable or non-separable.

2 Parity Codes

Single parity codes require the addition of an extra bit to a binary word such that the resulting code either has an even number of 1s or an odd number of 1s. If the extra bit results in the total number of 1s in the code word being even, the code is called even parity. If the extra bit results in the total number of 1s in the code word being odd, the code is called odd parity. Parity code is a separable code. The single-bit parity codes (both even and odd) for BCD words are shown in Fig. 1. It can easily seen that the valid code words have a Hamming distance of 2.

The most common application of parity is to protect the memories of computers used for safety-critical applications such as those used in planes or cars. Before being written to memory, the data word is encoded to achieve the desired parity. Encoding is the appending of the parity bit to force the result to have the appropriate number of 1s. When the data word is read from memory, the parity bit is checked to verify that the data has not been corrupted because of a fault affecting one or more memory cells. Fig. 2 shows this process. Circuits to generate and check parity bits are fairly simple to design, and one such circuit is shown in Fig. 3 for a 4-bit data word d 3 d 2 d 1 d 0.

There are five basic parity approaches that can be used to detect faults in memory systems, as outlined in Fig. 4.

  • Bit-per-word parity. The simplest parity checking scheme is to assign a single parity bit (either even or odd) to the data word. This can detect a single bit error. However, certain common types of

Fig. 1: Odd and even parity codes for binary coded decimal (BCD) data

Fig. 2: Memory organization that uses a single parity for checking. The parity (even or odd) is generated when the data word is written to memory, and checked when the data is read from memory.

Fig. 3: A parity generation and checking circuit for a 4-bit word.

faults such as the data word becoming all 0s or all 1s cannot be detected. The scheme also cannot detect multiple bit errors.

  • Bit-per-byte parity. This scheme assigns a parity bit to each byte in the data word. If we assign an even parity bit for the first byte and an odd parity bit for the second byte, or vice versa, we can protect against faults in which the data word becomes all 0s or all 1s. This scheme also protects against multiple-bit errors if the errors occur in the different bytes.
  • Interlaced parity. Parity bits are assigned to groups of bits organized in an interlaced fashion. This scheme protects against errors in adjacent bits, caused due to a fault in a memory cell affecting neighboring cells (e.g., bridging faults, shorts, etc).

Fig. 5: Vertical and horizontal parity uses a parity bit for each row and each column.

4 Error Correction using Hamming Codes

Fig. 6 shows a scheme with overlapping parity in which each information bit is assigned to multiple parity bits. In the figure, data bit d 0 is assigned to parity bits P 0 and P 1 , bit d 1 is assigned to parity bits P 0 and P 2 , and so on. The parity bits are generated as follows.

P 0 = d 0 ⊕ d 1 ⊕ d 3 P 1 = d 0 ⊕ d 2 ⊕ d 3 P 2 = d 1 ⊕ d 2 ⊕ d 3

It can be easily seen that a bit error affects a unique set of parity bits, allowing us to localize data-bit failures as well as to correct them.

Fig. 7 show how single-bit errors are localized and corrected using the overlapping parity scheme. First, we read the 4-bit data word as well as the corresponding parity bits (P 0 , P 1 , P 2 ) from memory. Then, the retrieved data word is used to generate parity bits (Pr 0 , Pr 1 , Pr 2 ). These generated parity bits are compared to the stored parity bits to localize and correct single bit errors. For example, assume that data bit 3 was affected by a memory-cell fault causing it to flip from a 1 to 0, or vice versa. This error will result in parity bits (Pr 0 , Pr 1 , Pr 2 ) differing from (P 0 , P 1 , P 2 ) in all three positions. That is, (Pr 0 ⊕P 0 , Pr 1 ⊕P 1 , Pr 2 ⊕P 2 ) = (111). This syndrome signature can be used to correct data-bit 3.

Fig. 6: The overlapping parity scheme assigns each information bit to multiple parity bits.

Fig. 7: An error correction scheme using overlapping parity.

How many parity bits are needed to protect m information bits using the overlapping parity approach? Let k be the number of parity bits required to protect the m information bits. So, the final code word is m + k bits long. In order to be corrected, each bit error that can occur in the code word must produce a unique signature out of the parity bits. Since we have k parity bits, there are 2k^ unique outcomes of the parity-checking process. We must also have a unique result of the parity-checking process when there is no error. So, the relationship between k and m must satisfy

2 k^ ≥ m + k + 1

The percentage of redundancy decreases substantially as the number of information bits increases. For example, to protect 8 information bits, we need 4 parity bits with an overhead of 50%, to protect 16 information bits, we need 5 parity bits with an overhead of 31.25%, and to protect 32 information bits, we need 6 parity bits with an overhead of 18.75%.

A (7, 4) Hamming code word is generated by multiplying the data bits (d 3 , d 2 , d 1 , d 0 ) by a generation matrix G using modulo-2 arithmetic to generate a code word having both data a parity bits. The generation matrix G consists of an identity matrix I and a parity generation matrix A, G = [I|A]. An example generation

Fig. 8: Example circuit that multiplies the data polynomial D(X) with the generator polynomial G(X) = 1+X +X^3.

5 Cyclic Codes

The key feature of cyclic codes is that any end-around shift of a code word will produce another code word. Cyclic codes are often used to protect memories and disks. They are attractive because the encoding and decoding operations can be implemented using simple linear feedback shift registers (or LFSRs).

Cyclic codes depend on the representation of data words by polynomials. Suppose we have the code word v = (v 0 , v 1 ,... , vn− 1 ). This code word corresponds to a code polynomial V (X) where

V (X) = v 0 + v 1 X + v 2 X^2 + · · · + vn− 1 Xn−^1

The code polynomial for a non-separable cyclic code is generated by multiplying a polynomial D(X), rep- resenting the data to be encoded, by another polynomial G(X), the generator polynomial. Any additions required during the multiplication of the two polynomials are performed using modulo-2 addition. For ex- ample, assume we have a generator polynomial G(X) = 1 + X + X^3 and we wish to encode the binary data (1101). This can be represented by the data polynomial D(X) = 1 + X + X^3. The code polynomial is then generated as V (X) = D(X) × G(X) = (1 + X + X^3 )(1 + X + X^3 ) = 1 + X^2 + X^6

In other words, v = (1010001).

Fig. 8 shows a circuit that generates the code word V (X). If we consider the blocks labeled X as multipliers by the factor X, and the addition elements as modulo-2 adders, the circuit performs the multiplication of two polynomials D(X) × G(X). For example, if D(X) = 1, the output V (X) = 1 + X + X^3. Likewise, is D(X) = 1 + X + X^3 , then the output is

V (X) = 1 + X + X^3 + [X^2 (1 + X + X^3 ) + 1 + X + X^3 ]X = 1 + X^2 + X^6

The generation circuit can be implemented in digital hardware using storage elements (flip flops) and XOR gates. Fig. 9 shows the circuit that generates the code word associated with the generator polynomial G(X) = 1 + X + X^3. Initially, the storage elements are loaded with all )s. The data to be encoded appears on the line D(X) serially during the start of each clock cycle.

Let us now consider the decoding process. Since the cyclic code discussed so far is not separable, the decoding process is more than simply picking certain bits from the code word and checking them for correctness. Suppose we wish to check if a code word (r 0 , r 1 , r 2 ,... , rn− 1 retrieved from memory is a valid code word. Let us represent this code word by the polynomial

R(X) = r 0 + r 1 X + r 2 X^2 + · · · + rn− 1 Xn−^1

Fig. 9: Digital circuit comprising storage elements and XOR gates that multiplies the data polynomial D(X) with the generator polynomial G(X) = 1 + X + X^3.

Fig. 10: Digital circuit comprising storage elements and XOR gates that divides the code polynomial V (X) by the generator polynomial G(X) = 1 + X + X^3.

If R(X) is a valid code word, then it was generated as R(X) = D(X)G(X). So, if we write

R(X) = D(X)G(X) + S(X)

then the quantity S(X) should be zero if R(X) is a valid code polynomial. We can divide the polynomial R(X) by the generator polynomial G(X) and check if the remainder of the division is zero. The quantity S(X) is the syndrome polynomial.

The division process turns out to be quite simple when feedback circuits similar to the cyclic-code generator circuits are used. The circuit shown in Fig. 10 is capable of dividing a polynomial by the polynomial

and V (X) is an exact multiple of G(X). Note that multiplication by Xn−k^ can be performed by simply shifting the coefficients of the data polynomial. The addition of the remainder polynomial is equivalent to simply appending the remainder to the polynomial Xn−kD(X).

Suppose we have an arbitrary data polynomial D(X) and a generator polynomial G(X). The code polynomial is given by

V (X) = Xn−kD(X) + R(X)

where R(X) is the remainder obtained when Xn−kD(X) is divided by G(X). So,

Xn−kD(X) = G(X)Q(X) + R(X) Xn−kD(X) − R(X) = G(X)D(X)

where Q(X) is the quotient computed in the division process. Since addition and subtraction operations are identical in modulo-2 arithmetic, we have

Xn−kD(X) − R(X) = Xn−kD(X) + R(X) = G(X)D(X) = V (X)

So, the code polynomial formed as V (X) = Xn−kD(X) + R(X)

is an exact multiple of the generator polynomial G(X).

As an example of constructing a separable (7, 4) cyclic code, consider the data word (1001) and the generator polynomial G(X) = 1 + X + X^3. The corresponding data polynomial D(X) = 1 + X^3. So, Xn−kD(X) = X^3 D(X) = X^3 + X^6. Dividing X^3 + X^6 by G(X) gives us a remainder of R(X) = X^2 + X. Adding the remainder polynomial to X^3 + X^6 results in V (X) = X + X^2 + X^3 + X^6. So, the code word is given by (0111001) where the last four bits of the code word are the coefficients of the original data word and the first three bits are the coefficients of the remainder polynomial.

6 Arithmetic Codes

Arithmetic codes are used to check the correctness of operations such as addition, multiplication, and divi- sion. The data involved in the arithmetic operation is encoded before the operations are performed. After completing the arithmetic operations, the resulting code words are checked to make sure they are valid.

A key requirement of arithmetic codes is that they must be invariant to the underlying set of arithmetic operations. An arithmetic code A has the property that A(x ∗ y) = A(x) ∗ A(y) where x and y are operands and ∗ is some arithmetic operation.

We will discuss AN codes, residue codes, and inverse-residue codes.

AN Codes

The simplest arithmetic code is the AN code, formed by multiplying each data word N by some constant A. The AN codes are invariant to addition and subtraction, but not multiplication and division. If N 1 and N 2 are two operands to be encoded, the resulting code words are AN 1 and AN 2. if the code words are added, the sum is A(N 1 + N 2 ) which is the code word of the correct sum. The operations done under the AN code can be checked by determining if the results are evenly divisible by the constant A. The selection of the constant A is critical to both the achieved fault coverage, as well as to the efficiency of the encoding and decoding operations. First, for binary codes, the constant must not be a power of 2. To see why, suppose we encode the binary number (an− 1 an− 2... a 2 a 1 a 0 by multiplying it with the constant 2a. The resulting code

Fig. 12: The 3N codewords for 4-bit information words.

word is (an− 1 an− 2... a 2 a 1 a 0000... 0) where a 0s have been appended to the original number. The decimal value of the code word is

an− 12 a+n−^1 + · · · + a 22 a+2^ + a 12 a+1^ + a 02 a^ + 02a−^1 + · · · + 02^0

which is evenly divisible by 2a. We can also see that simply changing one coefficient value from 0 to 1, or vice versa, still result in a number evenly divisible by 2a. Thus, an AN code that has A = 2a^ is not capable of detecting single-bit errors.

An example of a valid AN code is a 3N code. If the original data word is n bits long, the 3N code word is n + 2 bits long. Fig. 12 shows the 3N code words corresponding to the 4-bit data words. Fig. 13 shows how 3 N codewords are used to detect SSL faults in a binary adder.

Residue Codes

A residue code is a separable arithmetic code, created by appending the residue of a number to that number. The code word is constructed as D|R where D is the original data word and R is the residue of that data. The encoding operation consists of determining the residue and appending it to the data word, and the decoding process involves simply removing the residue, thus leaving behind the original data word.

Residue codes are invariant to the addition operation, and the residues can be handled separately from the data during the addition process. An adder structure that uses the separable residue code is shown in Fig. 14. The two data words D 1 and D 2 are added to from the sum word S. The residues of D 1 and D 2 which are r 1 and r 2 , respectively, are also added separately using a modulo-m adder where m is the modulus used to encode D 1 and D 2. If the residues rc and rs match, then the addition operation was performed correctly.

If the modulus for the residue code is selected in a special manner, a low-cost residue code is obtained. Low-cost residue codes have a modulus of m = 2b^ − 1, b ≥ 2. The number of extra bits required in a low-cost residue code is equal to b. The main advantage of a low-cost residue code is that the encoding process can be performed quite efficiently. We must determine a reminder to encode information using a residue code, and so a division is necessary. In low-cost residue codes, this division is recast as an addition process. The information bits to be encoded are first divided into groups, where each group contains b bits. The individual

Fig. 15: Calculation of a low-cost residue code using successive addition operations.

Inverse-Residue Codes

Rather than append the residue, in an inverse-residue code, the inverse residue Q = m − r is computed for a data word N where m is the modulus and r is the residue of N. The code word is then N |Q. The inverse-residue codes have been found to have better fault detection capability for repeated-use faults.

7 Algorithm-Based Fault Tolerance

This is a technique that develops fault detection and fault tolerance capabilities specific to the particular algorithm being employed. A majority of the work has dealt with matrix multiplication. Let us discuss a

technique that uses conventional checksums to encode the data contained in each of the two matrices to be multiplied.

Suppose we wish to perform the matrix multiplication

C = AB

where A is an M × N matrix, B is an N × M matrix, and C is the M × M result matrix. To perform error detection during matrix multiplication, the A matrix is augmented with a checksum row and the B matrix is augmented with a checksum column. For example, suppose we have two 2 × 2 matrices A and B given by

A =

[

a 11 a 12 a 21 a 22

]

B =

[

b 11 b 12 b 21 b 22

]

First, we construct the row encoded checksum matrix A′^ as

A′^ =

a 11 a 12 a 21 a 22 a 31 a 32

where

a 31 = a 11 + a 21 a 32 = a 12 + a 22

So, a 31 and a 32 are simply the checksums of columns 1 and 2, respectively, of the original A matrix.

Next, we generate the column encoded checksum matrix B′^ as

B′^ =

[

b 11 b 12 b 13 b 21 b 22 b 23

]

where

b 13 = b 11 + b 12 b 23 = b 21 + a 22

So, b 13 and b 23 are the checksums of rows 1 and 2, respectively, of the original B matrix.

Performing the multiplication C′^ = A′^ × B′, we get

C′^ =

c 11 c 12 c 13 c 21 c 22 c 23 c 31 c 32 c 33

a 11 a 12 a 21 a 22 a 31 a 32

[

b 11 b 12 b 13 b 21 b 22 b 23

]