You are on page 1of 40

Data Communication &

Networking

Data Communication & Computer Networks

Lecture 17
Error Detection
and
Correction
Data can be corrupted during transmission.
For reliable communication, errors must be
detected and corrected.
Network must be able to transfer data from one
device to another with acceptable accuracy.

For most application, a system must guarantee that


the data received are identical to the data transmitted.

An electromagnetic signal is subject to interference


from heat, magnetism, and other forms of electricity
Types of Error
1. Single-Bit Error
2. Burst Error
Single-Bit Error
only one bit in the data unit has
changed.
Single-bit error: 0  1 or 1  0

The least likely type of error in serial


transmission. Why ?

Single-bit error can happen in parallel


transmission
Burst Error
2 or more bits in the data unit have
changed.

Burst error does not necessarily mean that the errors occur in
consecutive bits
Most likely to happen in a serial transmission
Number of bits affected depends on the data rate and duration of
noise If the data is sent at 1 kbps, a noise of 1/100 s can affect 10
bits.
If the data is sent at 1 Mbps, a noise of 1/100 s can affect
10000 bits.
Redundancy

Error detection uses the concept of


redundancy, which means adding extra bits
for detecting errors at the destination.
Error Detection and Correction
 Detection vs. Correction
 Detection: error ? yes or no
 Correction: Need to know the exact number of bits that are corrupted, and
their location in the message
 Ex : one error in 8 bits sequence – 8 possible location.
 Ex : 10 errors in 1000 bits sequence ?

 Forward Error Correction vs. Retransmission


 2 main methods of error correction :
 Forward Error Correction – the receiver tries to guess the message by using
redundant bits (in the case the number of errors is small).
 Retransmission – the receiver detects the occurrence of an error and ask the
sender to resend the message. This process is repeated until a message
arrives that the receiver believes is error-free.
Error Detection and Correction
 Hamming Distance
 The Hamming distance between two words is the number of differences
between corresponding bits.
 Easily found by applying the XOR operation on the two words and count the
number of 1s in the result.
 Ex : Hamming distance d (000,011) = 2
 Ex : Hamming distance d (10101, 11110) = 3

 Minimum Hamming Distance


 The minimum Hamming distance is the smallest Hamming distance between
all possible pairs in a set of words
 Ex : Find the minimum Hamming distance of the coding scheme in below
table.
Sol: = 2
Error Detection and Correction
 Relation between Hamming Distance and Error
 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.
 Ex : 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 the received codeword is s.
 To guarantee the detection of up to s errors in all cases, the
minimum Hamming distance in a block code must be dmin = s + 1.
Detection methods
Simple Parity-Check Code
 A k-bit dataword is changed to an n-bit codeword where n = k + 1.
 The extra bit (called the parity bit), is selected to make the total number
of 1s in the codeword even.
 The minimum Hamming distance dmin = 2, which means that the code
is a single-bit error-detecting code.
 Example of parity-check code with k = 4, n = 5; C (5,4) :
Even-parity concept
A parity bit is added to every data unit so
that the total number of 1s is even
(or odd for odd-parity).
Encoder and Decoder for Parity-Check
Code
Encoder and Decoder for Parity-Check Code
 The encoder uses a generator that takes a copy of a 4-bit dataword (a0,
a1, a2 and a3) and generates a parity bit r0.
 The dataword bits and the parity bit create the 5-bit codeword.
 The parity bit that is added make the number of 1s in the codeword
even.
 This is done by adding the 4 bits of the dataword, where the result is
the parity bit.
r0 = a3 + a2 + a1 + a0
 The sender sends the codeword which may be corrupted during
transmission and the receiver receives a 5-bit word.
 The checker at the receiver does the same thing as the generator at the
sender, but the addition is done over all 5 bits.
s0 = b3 + b2 + b1 + b0 + q0
 The result which is called the syndrome, is just 1 bit.
 The syndrome is passed to the decision logic analyzer.
 If the syndrome = 0 = no error in the received codeword; the data
portion of the received codeword is accepted as the dataword.
 If the syndrome = 1 = error in the received codeword; the data portion
of the received codeword is discarded and no dataword is created
Example 1
Suppose the sender wants to send the word world. In
ASCII the five characters are coded as
1110111 1101111 1110010 1101100 1100100
The following shows the actual bits sent
11101110 11011110 11100100 11011000 11001001
Example 2
Now suppose the word world in Example 1 is received by
the receiver without being corrupted in transmission.
11101110 11011110 11100100 11011000 11001001
The receiver counts the 1s in each character and comes up
with even numbers (6, 6, 4, 4, 4). The data are accepted.
Example 3
Now suppose the word world in Example 1 is corrupted
during transmission.
11111110 11011110 11101100 11011000 11001001
The receiver counts the 1s in each character and comes up
with even and odd numbers (7, 6, 5, 4, 4). The receiver
knows that the data are corrupted, discards them, and asks
for retransmission.
Simple parity check can detect all
single-bit errors. It can detect burst
errors only if the total number of
errors in each data unit is odd.
Two-dimensional parity
A block of bits is divided into rows and a
redundant row of bits is added to the whole block.
Two-dimensional parity-check code
Two-dimensional parity-check code
Error Detection & Correction Common Techniques

 Error Correcting Code : Hamming Codes C (7,4)


Error Detection & Correction Common Techniques
 Encoder and decoder for a Hamming Code
Error Detection & Correction Common Techniques

Examples:
dataword 0100  codeword received 0100011  syndrome = 000
no errors
0111  0111001  received 0011001  syndrome 011 (b2) flip
b2  error is corrected
Dataword 1101  1101000  received 0001000  syndrome 101
(b0) flip b0  0000 wrong data word

Hamming code can only correct a single error or


detect a double errors
Error Detection & Correctioon Common Techniques
 The use of Hamming Code in burst error correction
 A Hamming code can only correct a single error and detect a double error.
 But there is a way to make it detect a burst error :

When a burst of error of size 4 corrupts the frame, only 1 bit from
each codeword is corrupted – the corrupted bit can be easily be
corrected at the receiver
Error Detection & Correction Common Techniques

 Cyclic Codes
 Cyclic codes are special linear block code – if a codeword is cyclically shifted
(rotated), the result is another codeword
 Ex : 1011000 is a codeword and if cyclically left-shifted, the result 0110001 is
also a codeword.
Error Detection & Correction Common Techniques
 Cyclic Redundancy Check
 The use of cyclic codes to detect and correct error
 CRC encoder and decoder
CRC generator and checker
Error Detection & Correction Common Techniques

 CRC encoder and decoder


 In the encoder, the dataword has k
bits (4 bits)
 The size of dataword is augmented
(increased) by adding n – k (3 bits)
0s to the right-hand side of the word.
 The n-bits is then fed to the
generator.
 The generator uses a pre-defined
divisor to divide the dataword
(modulo-2 division).
 The quotient of the division is
discarded, the remainder (r2r1r0) is
appended to the dataword to create
the codeword.
Error Detection & Correction Common Techniques

 CRC encoder and decoder


 The decoder receives the possibly
corrupted codeword.
 A copy of all n bits is fed to the
checker to do the same step as the
generator.
 The remainder produced by the
checker is a syndrome of n – k (3
bits) which is fed to the decision
logic analyzer.
 If the syndrome bits are all 0s, the 4
leftmost bits of the codeword are
accepted as a dataword.
 Otherwise, the 4 bits are discarded
(error).
Error Detection & Correction Common Techniques
 Example : Division in CRC Encoder
Error Detection & Correction Common Techniques
 Example : Division in CRC Decoder
Checksum
The receiver follows these steps: The sender follows these steps:
1. The unit is divided into k 1. The unit is divided into k sections,
sections, each of n bits. each of n bits.
2. All sections are added using 2. All sections are added using one’s
one’s complement to get the complement to get the sum.
sum. 3. The sum is complemented and
3. The sum is complemented. becomes the checksum.
4. If the result is zero, the data 4. The checksum is sent with the
are accepted: otherwise, data.
rejected
Example
Suppose the following block of 16 bits is to be sent using a
checksum of 8 bits.
10101001 00111001
The numbers are added using one’s complement
10101001
00111001
------------
Sum 11100010
Checksum 00011101
The pattern sent is 10101001 00111001 00011101
Example
Now suppose the receiver receives the pattern sent in Example 7
and there is no error.
10101001 00111001 00011101
When the receiver adds the three sections, it will get all 1s, which,
after complementing, is all 0s and shows that there is no error.
10101001
00111001
00011101
Sum 11111111
Complement 00000000 means that the pattern is OK.
Example
Now suppose there is a burst error of length 5 that affects 4 bits.
10101111 11111001 00011101
When the receiver adds the three sections, it gets
10101111
11111001
00011101
Partial Sum 1 11000101
Carry 1
Sum 11000110
Complement 00111001 the pattern is corrupted.
 implementation of checksum
 The sender initializes the checksum to 0 and adds all data items and the
checksum.
 36 cannot be expressed in 4 bits. The extra two bits are wrapped and
added with the sum to create the wrapped sum value 6.
 The sum is then complemented, resulting in the checksum value 9 (15 − 6
= 9).

11 1
1
Error Detection & Correction Common Techniques
 Internet checksum
 Sender site:
 1. The message is divided into 16-bit words.
 2. The value of the checksum word is set to 0.
 3. All words including the checksum are added using one’s complement
 addition.
 4. The sum is complemented and becomes the checksum.
 5. The checksum is sent with the data.
 Receiver site:
 1. The message (including checksum) is divided into 16-bit words.
 2. All words are added using one’s complement addition.
 3. The sum is complemented and becomes the new checksum.
 4. If the value of checksum is 0, the message is accepted; otherwise, it is
rejected.
Error Detection & Correction Common Techniques

 Internet checksum : Example

You might also like