Lecture-4 (Error Detection and Correction)
Lecture-4 (Error Detection and Correction)
Error Detection
and
Correction
Kyung Hee
University
1
Presentation / Lecture Acknowledgement
Kyung Hee
University
2
Position of the data-link layer
Kyung Hee
University
3
Error Detection and Correction
Note
Data can be corrupted during transmission.
internet model
Kyung Hee
University
4
10.1 INTRODUCTION
Kyung Hee
University
5
10.1 Type of Errors
Kyung Hee
University
6
Type of Errors(cont’d)
Single-Bit Error
Kyung Hee
University
7
Type of Errors(cont’d)
Burst-Bit Error
Error correction
Need to know the exact number of bits that are corrupted
and more importantly, their location in the message.
Kyung Hee
University
10
Modular Arithmetic
In modulo-N arithmetic, we use only the integers in the
range 0 to N −1, inclusive.
We define an upper limit, called a Modulus N.
We then use only the integers 0 to N −1, inclusive.
Kyung Hee
University
11
Modulo-2 Arithmetic
Adding 0+0=0 0+1=1 1+0=1 1+1=0
Kyung Hee
University
12
10.2 BLOCK CODING
Kyung Hee
University
13
Block Coding
Kyung Hee
University
14
BLOCK CODING - Error detection
If the following two conditions are met, the receiver can
detect a change in the original codeword.
The receiver has (or can find) a list of valid codewords.
The original codeword has changed to an invalid one.
Figure 10.6 Process of error detection in block coding
Kyung Hee
University
15
BLOCK CODING - Error detection
Example 10.2
Table 10.1 A code
for error detection
(Example 10.2)
Kyung Hee
University
17
BLOCK CODING - Error Correction
In error correction, the receiver needs to find (or guess)
the original codeword sent.
Kyung Hee
University
18
BLOCK CODING - Error Correction
Example 10.3
Let us add more redundant bits to Example 10.2 to
see if the receiver can correct an error without
knowing what was actually sent. We add 3 redundant
bits to the 2-bit dataword to make 5-bit codewords.
Table 10.2 shows the datawords and codewords.
Assume the dataword is 01. The sender creates the
codeword 01011. The codeword is corrupted during
transmission, and 01001 is received. First, the
receiver finds that the received codeword is not in the
table. This means an error has occurred. The receiver,
assuming that there is only 1 bit corrupted, uses the
following strategy to guess the correct dataword.
Kyung Hee
University
19
BLOCK CODING - Error Correction
Example 10.3 (continued)
1. Comparing the received codeword with the first codeword
in the table (01001 versus 00000), the receiver decides
that the first codeword is not the one that was sent
because there are two different bits.
2. By the same reasoning, the original codeword cannot be
the third or fourth one in the table.
3. The original codeword must be the second one in the table
because this is the only one that differs from the received
codeword by 1 bit. The receiver replaces 01001 with 01011
and consults the table to find the dataword 01.
Table 10.2 A code
for error correction
(Example 10.3)
Kyung Hee
University
20
BLOCK CODING - Hamming Distance
Hamming distance between two words (of the same
size) is the number of difference 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 1s in
the result.
Kyung Hee
University
21
BLOCK CODING - Error Correction
Example 10.4
Let us find the Hamming distance between two pairs
of words.
Kyung Hee
University
22
BLOCK CODING - Minimum Hamming Distance
The minimum Hamming distance is the
smallest Hamming distance between
all possible pairs in a set of words.
Kyung Hee
University
23
BLOCK CODING - Minimum Hamming Distance
Example 10.5
Find the minimum Hamming distance of the coding
scheme in Table 10.1.
Solution
We first find all Hamming distances.
Kyung Hee
University
24
BLOCK CODING - Minimum Hamming Distance
Example 10.6
Find the minimum Hamming distance of the coding
scheme in Table 10.2.
Solution
We first find all the Hamming distances.
Kyung Hee
University
26
BLOCK CODING - Minimum Distance for error detection
Kyung Hee
University
27
BLOCK CODING - Minimum Distance for error detection
Example 10.7
The minimum Hamming distance for our first code
scheme (Table 10.1) is 2. This code guarantees
detection of only a single error. 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. one error : 101 100 (does not match any valid code)
Two errors : 101 000 (errors are not detected)
Kyung Hee
University
30
Linear Block Codes
Example 10.10
Let us see if the two codes we defined in Table 10.1 and
Table 10.2 belong to the class of linear block codes.
1. The scheme in Table 10.1 is a linear block code
because the result of XORing any codeword with any
other codeword is a valid codeword. For example, the
XORing of the second and third codewords creates the
fourth one.
2. The scheme in Table 10.2 is also a linear block code.
We can create all four codewords by XORing two
other codewords. Table10.1 Table10.2
Kyung Hee
University
31
Minimum Distance for Linear Block Codes
The minimum Hamming distance is the number of 1s in
the nonzero valid codeword with the smallest number
of 1s.
Kyung Hee
University
32
Minimum Distance for Linear Block Codes
Example 10.11
In our first code (Table 10.1), the numbers of 1s in the
nonzero codewords are 2, 2, and 2. So the minimum
Hamming distance is dmin = 2. In our second code
(Table 10.2), the numbers of 1s in the nonzero
codewords are 3, 3, and 4. So in this code we have
dmin = 3.
Table10.1 Table10.2
Kyung Hee
University
33
Linear Block Codes-Simple parity-Check Code
In Simple parity-check code, a k-bit dataword is
changed to an n-bit codeword where n=k+1.
Kyung Hee
University
35
Minimum Distance for Linear Block Codes
Kyung Hee
University
36
Minimum Distance for Linear Block Codes
Example 10.12
Let us look at some transmission scenarios. Assume
the sender sends the dataword 1011. The codeword
created from this dataword is 10111, which is sent to
the receiver. We examine five cases:
1. No error occurs; the received codeword is 10111.
The syndrome is 0. The dataword 1011 is created.
2. One single-bit error changes a1 . The received
codeword is 10011. The syndrome is 1. No dataword
is created.
3. One single-bit error changes r0 . The received
codeword is 10110. The syndrome is 1. No dataword
is created.
Kyung Hee
University
37
Minimum Distance for Linear Block Codes
Example 10.12 (continued)
4. An error changes r0 and a second error changes a3 .
The received codeword is 00110. The syndrome is 0.
The dataword 0011 is created at the receiver. Note
that here the dataword is wrongly created due to
the syndrome value.
5. Three bits—a3, a2, and a1—are changed by errors.
The received codeword is 01011. The syndrome is 1.
The dataword is not created. This shows that the
simple parity check, guaranteed to detect one single
error, can also find any odd number of errors.
Kyung Hee
University
38
Note
Kyung Hee
University
39
LINEAR BLOCK CODES - Two-dimensional parity Check Code
Kyung Hee
University
40
LINEAR BLOCK CODES - Two-dimensional parity Check Code
Kyung Hee
University
41
LINEAR BLOCK CODES - Two-dimensional parity Check Code
Kyung Hee
University
42
LINEAR BLOCK CODES - Two-dimensional parity Check Code
Kyung Hee
University
43
10.4 CYCLIC CODES
b1 = a 0, b2 = a 1, b3 = a 2, b 4 = a 3, b5 = a 4, b 6 = a 5, b0 = a 6
In the right most equation, the last bit of the first word is
wrapped around and becomes the first bit of the second
word.
Cyclic Redundancy Check (CRC) is used in networks
such as LANs and WANs.
Kyung Hee
University
45
Cyclic Redundancy Check
Kyung Hee
University
46
Cyclic Redundancy Check
CRC(Cyclic Redundancy Check)
Kyung Hee
University
48
Cyclic Redundancy Check
Figure 10.15 Division in CRC encoder
Kyung Hee
University
49
Cyclic Redundancy Check
Figure 10.16 Division in the CRC decoder for two cases
Kyung Hee
University
50
Cyclic Redundancy Check
Note
In a cyclic code,
If s(x) ≠ 0, one or more bits is corrupted.
If s(x) = 0, either
a. No bit is corrupted. or
b. Some bits are corrupted, but the
decoder failed to detect them.
* S(X) = Syndrome
Kyung Hee
University
51
Cyclic Code
Advantages of Cyclic Codes
Cyclic codes have a very good performance in detecting
single-bit errors, double errors, an odd number of errors,
and burst errors.
They can easily be implemented in hardware and
software.
They are especially fast when implemented in hardware.
This has cyclic codes a good candidate for many
networks.
Kyung Hee
University
52
10.5 CHECKSUM
Kyung Hee
University
53
Checksum
Like linear and cyclic codes, the checksum is based on
the concept of redundancy.
Kyung Hee
University
54
Idea - Checksum
Example 10.18
Suppose our data is a list of five 4-bit numbers that
we want to send to a destination. In addition to
sending these numbers, we send the sum of the
numbers. For example, if the set of numbers is (7,
11, 12, 0, 6), we send (7, 11, 12, 0, 6, 36), where 36 is
the sum of the original numbers. The receiver adds
the five numbers and compares the result with the
sum. If the two are the same, the receiver assumes
no error, accepts the five numbers, and discards
the sum. Otherwise, there is an error somewhere
and the data are not accepted.
Kyung Hee
University
55
Idea - Checksum
Example 10.19
We can make the job of the receiver easier if we
send the negative (complement) of the sum,
called the checksum. In this case, we send (7,
11, 12, 0, 6, −36). The receiver can add all the
numbers received (including the checksum). If
the result is 0, it assumes no error; otherwise,
there is an error.
Kyung Hee
University
56
One’s Complement - Checksum
In one’s Complement arithmetic, We can represent
unsigned numbers between 0 and 2n -1 using only n
bits.
If the number has more than n bits, the extra left most
bits need to be added to the n rightmost bits (wrapping).
A negative number can be represented by inverting all
bits (changing a 0 to a 1 and a 1 to a 0).
This is the same as subtracting the number from 2n -1.
Kyung Hee
University
57
One’s Complement - Checksum
Example 10.20
How can we represent the number 21 in one’s
complement arithmetic using only four bits?
Solution
The number 21 in binary is 10101 (it needs five bits).
We can wrap the leftmost bit and add it to the four
rightmost bits. We have (0101 + 1) = 0110 or 6.
Kyung Hee
University
58
Detection
Kyung Hee
University
59
Detection(cont’d)
Example 7 ( at a sender)
16 bits block 8 bits checksum
10101001
00111001
--------------
11100010 Sum
00011101 Checksum
Sending bits
8 bits sum
10101001
00111001
00011101
---------------
11111111 Sum
Complement of Sum
00000000 Complement : It means No error
Kyung Hee
University
61
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
1 ← carry from 8th column
10 ← carry from 6th column
1 ← carry from 5th column
10 ← carry from 4th column
1 ← carry from 3rd column
1 ← carry from 2nd column
1 ← carry from 1st column
10101111
11111001
00011101
Partial Sum 1 11000101
Carry 1
Sum 11000110
Complement 00111001 the pattern is corrupted.
Kyung Hee
University
62
One’s Complement
Example 10.21
How can we represent the number −6 in one’s complement
arithmetic using only four bits?
Solution
In one’s complement arithmetic, the negative or
complement of a number is found by inverting all bits.
Positive 6 is 0110; negative 6 is 1001. If we consider
only unsigned numbers, this is 9. In other words, the
complement of 6 is 9. Another way to find the
complement of a number in one’s complement
arithmetic is to subtract the number from 2n − 1 (16 − 1
in this case).
Kyung Hee
University
63
One’s Complement
Example 10.22
Let us redo Exercise 10.19 using one’s complement
arithmetic. Figure 10.24 shows the process at the
sender and at the receiver. The sender initializes the
checksum to 0 and adds all data items and the
checksum (the checksum is considered as one data
item and is shown in color). The result is 36. However,
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. In the figure, we have shown the details in
binary. The sum is then complemented, resulting in the
checksum value 9 (15 − 6 = 9). The sender now sends
six data items to the receiver including the checksum 9.
Kyung Hee
University
64
One’s Complement
Kyung Hee
University
65
Internet Checksum
Checksum Generator
Kyung Hee
University
66
Internet Checksum
Note
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.
Kyung Hee
University
67
Internet Checksum
Note
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.
Kyung Hee
University
68
One’s Complement
Figure 10.24 Example 10.22
1 1
1 0
Kyung Hee
University
69
Q&A
Kyung Hee
University
70