Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

Lecture-4 (Error Detection and Correction)

Chapter 10 discusses error detection and correction in data transmission, focusing on the types of errors, redundancy, and the differences between detection and correction methods. It covers block coding, including error detection and correction techniques, Hamming distance, and minimum Hamming distance for effective error handling. The chapter concludes with an explanation of linear block codes and simple parity-check codes, highlighting their roles in identifying and correcting transmission errors.

Uploaded by

mdpolas360
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Lecture-4 (Error Detection and Correction)

Chapter 10 discusses error detection and correction in data transmission, focusing on the types of errors, redundancy, and the differences between detection and correction methods. It covers block coding, including error detection and correction techniques, Hamming distance, and minimum Hamming distance for effective error handling. The chapter concludes with an explanation of linear block codes and simple parity-check codes, highlighting their roles in identifying and correcting transmission errors.

Uploaded by

mdpolas360
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Chapter 10

Error Detection
and
Correction
Kyung Hee
University
1
Presentation / Lecture Acknowledgement

Professor Choong Seon Hong, Ph.D.


Networking Lab,
Kyung Hee University, Republic of Korea.

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.

 Some applications require that errors be detected


and corrected.
 Error Detection and Correction are implemented

at the data link layer and the transport layer of the

internet model

Kyung Hee
University
4
10.1 INTRODUCTION

Let us first discuss some issues related, directly or


indirectly, to error detection and correction.

Topics discussed in this section:


Types of Errors
Redundancy
Detection Versus Correction
Forward Error Correction Versus Retransmission
Coding
Modular Arithmetic

Kyung Hee
University
5
10.1 Type of Errors

Kyung Hee
University
6
Type of Errors(cont’d)
Single-Bit Error

 In a single-bit error, only 1 bit in the data unit has


changed.

Kyung Hee
University
7
Type of Errors(cont’d)
Burst-Bit Error

 A burst error means that 2 or more bits in the data unit


have changed.
 The length of the burst is measured from the 1st corrupted bit
to the last corrupted bit.
 Some bits in between may not have been corrupted.
Kyung Hee
University
8
Redundancy
 The central concept in detecting or correcting errors is
Redundancy.

 Instead of repeating the entire data stream, a shorter


group of bits may be appended to the end of each unit.
→ This technique is called Redundancy.
 These extra bits are discarded as soon as the accuracy
of the transmission has been determined.

To detect or correct errors, we need to send


extra (redundant) bits with data.
Kyung Hee
University
9
Error Detection Vs Correction
Error detection
 looking only to see if any error has occurred.

Error correction
 Need to know the exact number of bits that are corrupted
and more importantly, their location in the message.

The correction of errors is more difficult than the


detection.

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

Subtracting 0-0=0 0-1=1 1-0=1 1-1=0

Figure 10.4 XORing of two single bits or two words

Kyung Hee
University
12
10.2 BLOCK CODING

In block coding, we divide our message into blocks,


each of k bits, called datawords. We add r redundant
bits to each block to make the length n = k + r. The
resulting n-bit blocks are called codewords.

Topics discussed in this section:


Error Detection
Error Correction
Hamming Distance
Minimum Hamming Distance

Kyung Hee
University
13
Block Coding

Figure 10.5 Datawords and codewords in 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)

Let us assume that k = 2 and n = 3. Table 10.1 shows the


list of datawords and codewords. Later, we will see
how to derive a codeword from a dataword.

Assume the sender encodes the dataword 01 as 011 and


sends it to the receiver. Consider the following cases:

1. The receiver receives 011. It is a valid codeword. The


receiver extracts the dataword 01 from it.
Kyung Hee
University
16
BLOCK CODING - Error detection
Example 10.2 (continued)
2. The codeword is corrupted during transmission, and
111 is received. This is not a valid codeword and is
discarded.

3. The codeword is corrupted during transmission, and


000 is received. This is a valid codeword. The receiver
incorrectly extracts the dataword 00. Two corrupted
bits have made the error undetectable.

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.

We need more redundant bits for error correction than


for error detection.
Figure 10.7 Structure of encoder and decoder in error correction

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.

1. The Hamming distance d(000, 011) is 2 because

2. The Hamming distance d(10101, 11110) is 3 because

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.

We use dmin to define the minimum Hamming distance in a


coding scheme.

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.

The dmin in this case is 2.


Table 10.1 A code
for error detection
(Example 10.2)

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.

The dmin in this case is 3.

Table 10.2 A code


for error correction
(Example 10.3)
Kyung Hee
University
25
BLOCK CODING - Hamming Distance
Three parameters
A coding scheme C is written as C(n,k) with a separate
expression for dmin .
For example, we can call our first coding scheme c(3,2) with
dmin =2 and our second coding scheme c(5,2) with dmin =3.

Hamming distance and Error


The Hamming distance between the received cordword and the
sent codeword is the number of bits that are corrupted during
transmission.
For example : 3 bits are in error and the hamming distance
between the two is d(00000, 01101) = 3

Kyung Hee
University
26
BLOCK CODING - Minimum Distance for error detection

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.
so that the received codeword does not match a valid
codeword.

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)

Table 10.1 A code


for error detection
(Example 10.2)
Kyung Hee
University
28
BLOCK CODING - Minimum Distance for error detection
Example 10.8
Our second block code scheme (Table 10.2) has dmin =
3. 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.

Table 10.2 A code


for error correction
(Example 10.3)
Kyung Hee
University
29
10.3 LINEAR BLOCK CODES

Almost all block codes used today belong to a subset


called linear block codes. A linear block code is a
code in which the exclusive OR (addition modulo-2)
of two valid codewords creates another valid
codeword.

Topics discussed in this section:


Minimum Distance for Linear Block Codes
Some Linear Block Codes

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.

The extra bit, called the parity bit, is selected to make


the total number of 1s in the codeword even or odd.

This code is a single-bit error-detecting code; it cannot


correct any error.

A simple parity-check code is a


single-bit error-detecting
code in which
n = k + 1 with dmin = 2.
Kyung Hee
University
34
Minimum Distance for Linear Block Codes
Table 10.3 Simple parity-check code C(5, 4)

Kyung Hee
University
35
Minimum Distance for Linear Block Codes

Figure 10.10 Encoder and decoder for simple parity-check code

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

A simple parity-check code can detect an


odd number of errors.

Kyung Hee
University
39
LINEAR BLOCK CODES - Two-dimensional parity Check Code

In Two-dimensional parity-check code, the data code is


organized in a table (rows and columns).
In fig.10.11, the data to be sent, five 7bit bytes, are put in
separate rows.
For each row and each column, 1 parity-check bit is
calculated.
The whole table is then sent to the receiver, which finds
the syndrome for each row and each column.
As Fig.10.11 shows, the two-dimensional parity check
can detect up to three errors that occur anywhere in the
table.

Kyung Hee
University
40
LINEAR BLOCK CODES - Two-dimensional parity Check Code

Figure 10.11 Two-dimensional parity-check code

Kyung Hee
University
41
LINEAR BLOCK CODES - Two-dimensional parity Check Code

Figure 10.11 Two-dimensional parity-check code

Kyung Hee
University
42
LINEAR BLOCK CODES - Two-dimensional parity Check Code

Figure 10.11 Two-dimensional parity-check code

Kyung Hee
University
43
10.4 CYCLIC CODES

Cyclic codes are special linear block codes with


one extra property. In a cyclic code, if a codeword
is cyclically shifted (rotated), the result is another
codeword.
Topics discussed in this section:
Cyclic Redundancy Check
Hardware Implementation
Polynomials
Cyclic Code Analysis
Advantages of Cyclic Codes
Other Cyclic Codes
Kyung Hee
University
44
Cyclic Redundancy Check
In a Cyclic Code, if a codeword is cyclically shifted , the
result is another codeword.
For example, if 1011000 is a codeword and we cyclically
left-shift, then 0110001 is also a codeword.

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

Table 10.6 A CRC code with C(7, 4)

Kyung Hee
University
46
Cyclic Redundancy Check
CRC(Cyclic Redundancy Check)

~ is based on binary division.

○ CRC must have 2 qualities


- It must have exactly one less
bit than the divisor
- Resulting bit sequence (Data+CRC)
exactly divisible by the divisor.
Kyung Hee
University
47
Cyclic Redundancy Check
Figure 10.14 CRC encoder and decoder

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

The last error detection method we discuss here is


called the checksum. The checksum is used in the
Internet by several protocols although not at the data
link layer. However, we briefly discuss it here to
complete our discussion on error checking

Topics discussed in this section:


Idea
One’s Complement
Internet Checksum

Kyung Hee
University
53
Checksum
Like linear and cyclic codes, the checksum is based on
the concept of redundancy.

Several protocols still use the checksum for error


correction, although the tendency is to replace it with a
CRC.

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

Original data : 10101001 00111001

 1’s complement addition

10101001

00111001

--------------

11100010 Sum

00011101 Checksum

 Sending bits

10101001 00111001 00011101  transmitting


Kyung Hee
University
60
Detection(cont’d)
Example 8 ( at a receiver)
 No errors:

Received data : 10101001 00111001 00011101

 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

Example 10.22 (continued)


The receiver follows the same procedure as the
sender. It adds all data items (including the
checksum); the result is 45. The sum is wrapped and
becomes 15. The wrapped sum is complemented and
becomes 0. Since the value of the checksum is 0,
this means that the data is not corrupted. The
receiver drops the checksum and keeps the other
data items. If the checksum is not zero, the entire
packet is dropped.

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

You might also like