You are on page 1of 20

Error Detection and Correction

• Two basic strategies to deal with errors:


1. Include enough redundant information to enable
the receiver to deduce what the transmitted data
must have been.
Error correcting codes.
2. Include only enough redundancy to allow the
receiver to deduce that an error has occurred (but
not which error).
Error detecting codes.

The use of error correcting codes is often referred to


as forward error correction.
Error Correcting Codes
• A frame consists of
– Let the total length be n i.e n=m+r
– m data bits (message) and
– r redundant bits (check bits).

• An n-bit unit containing data and check bits is referred to as n-bit


codeword.
Error Correcting Codes
Example
• Transmitted: 10001001
• Received: 10110001
XOR operation gives number of bits that are different.
• XOR: 00111000

• Number of bit positions in which two codeword differ


is called Hamming Distance.

• It shows that two codes are hamming distance d


apart, it will require d errors to convert one into the
other.
Error Correcting Codes
• All 2m possible data messages are legal, but due to
the way the check bits are computed, not all 2n
possible code words are used.
• Only small fraction of 2m/2n=1/2r are possible will be
legal codeword.
• The error-detecting and error-correcting codes of the
block code depend on this Hamming distance.
• To reliably detect d error, one would need a distance
d+1 code.
• To correct d error, one would need a distance 2d+1
code.
Error Correcting Codes
Parity bits:
– A single parity bit is appended to the data.
–The parity bit is chosen so that the number of 1
bits in the codeword is even for even parity and
no.of 1s are odd for odd parity.
–Eg: Consider the codeword 1 0 1 1 0 1 0
–With odd parity, the code word=
1 0 1 1 0 1 0 1(5 ones)
–With even parity, the code word=
1 0 1 1 0 1 0 0 (4 ones)
Error Correcting Codes
Example:
• 4 valid error correcting codeword:
– 0000000000
– 0000011111
– 1111100000
– 1111111111

• This code has a distance 5. Means it can correct double errors.

• If the codeword 0000000111 arrives, the receiver knows that the


original must have been 0000011111

• If however, a triple error changes 0000000000 in to 0000000111,


the error will not be corrected properly.
Hamming Code
• Here the bits of the codeword are numbered
consecutively, starting with bit 1 at the left end, bit 2 to
its immediate right and so on.
• The bits that are powers of 2 (1, 2, 4, 8, 16, …) are Check
bits.
• The rest of bits (3, 5, 6, 7, 9, …) are filled with m data
bits.
• Each check bit forces the parity of some collection of
bits including itself to be even(or odd).
• Eg: 11= 1+2+8 29= 1+4+8+16 (write as sum of powers of 2)
• Here bit 11 is checked by bits 1,2 and 8
• It can usually correct only single errors.
Hamming Code calculation

8
Hamming Code calculation

9
Hamming code calculation

In the previous example, instead of 0 1 1 1 0 0 1 0 1 0 1 0,


If the word received was 0 1 1 1 0 0 1 0 1 1 1 0, then
the receiver could calculate, which bit was wrong and
correct it.
• i.e, verify each check bits.
• Here its clear that check bits 2 and 8 are wrong.
• So 2+8=10th bit is wrong

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Hamming code calculation

Q1: The codeword 1 1 1 1 0 1 0 1 1 0 1 is received using


hamming encoding algm. What was the original code
sent?

Q2: check the correctness of given codeword.


a. 0 1 0 1 0 1 1 0 0 0 1 1
b. 1 1 1 1 1 0 0 0 1 1 0 0

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error-Detecting Codes

1. Parity.
2. Cyclic Redundancy Checks (CRCs).

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error-Detecting Codes

Cyclic Redundancy Checks (CRC): also called Polynomial


code.
• Most powerful error detection technique.
• Based on binary division.
• Here a sequence of redundant bits, called CRC is
appended to the end of data units so that the resulting
data unit becomes exactly divisible by a second,
predetermined binary number.

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
CRC

• Consider the frame T(x)=1101011011


• Let the generator G(x)= x4+x+1= 10011
• Perform T(x)/G(x)
• We get the remainder E(x)= check bits
• Append E(x) at the end of T(x)=> T(x)+E(x)= checksum
• Transmit the appended frame.
• At the receiver, divide the received frame by G(x). i.e
perform (T(x)+E(x))/G(x)
• If the remainder is zero, No error.
• If there is a remainder, there is an error!!

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
CRC

• Here, during calculation, both addition and


subtraction are identical to exclusive OR
• The sender and receiver must agree upon the
generator polynomial G(x).
• Both high and low order bits of generator must be 1.
• If r is the degree of G(x), append r zero bits to the low
order end of the frames T(x)

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Error-Detecting Codes

Example calculation of the CRC


Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Example

a) Send • Receive
– M(x) = 110011  x5+x4+x+1 (6 bits)
– G(x) = 11001  x4+x3+1 11001 1100111001
– Divide xnM(x) by P(x) to find C(x) 11001
11001
100001 11001
11001 1100110000
00000
11001
10000
No remainder
11001  Accept
1001 = C(x)

Send the block 110011 1001

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011
Example

• Calculate the transmitted frame for the data


1 1 0 1 0 1 1 0 1 1 using the generator x4+x+1

– Frame: 1 1 0 1 0 1 1 0 1 1
– Generator: 1 0 0 1 1
– Msg after 4 zero bits are appended: 1 1 0 1 0 1 1 0 1 10000

– Check bits = 1 1 1 0
– Transmitted frame= 1 1 0 1 0 1 1 0 1 1 1 1 1 0
Example

• What is CRC? If the generating polynomial for CRc code


is x3+x+1 & the message word is
1 1 0 1 0 0 1 1 1 0 1 1 0 0 . Determine the check bits and
the encoded word. How does the receiver know that an
error has occurred? What is the result of the receivers
CRC calculations?
End

Computer Networks, Fifth Edition by Andrew Tanenbaum and David Wetherall, © Pearson Education-Prentice Hall, 2011

You might also like