Вы находитесь на странице: 1из 46

Handout 11

Error Detection and Correction


Course Name: Data Communication Fundamentals

Course Code: COMP 1219

Notes appended and modified by K. Al-Ansari


to those accompanying
“Data Communications and Networking”, Behrouz A.
Forouzan, 5th Ed., McGraw Hill, 2013, Ch. 10

E-mail: kalansari1@georgebrown.ca

1
Reminder!

Event: Final Test (40% of your final mark)

Material: Based on weeks 1 – 12 (Focus mainly on weeks 7 - 12)

Date: Jan. 18, 2018

Time Duration: Around 80 Minutes

Test Pattern: Mostly MCQs

2
Chapter 10: Outline

10.1 INTRODUCTION

10.2 BLOCK CODING

10.3 CYCLIC CODES

3
10-1 INTRODUCTION

Let us first discuss some issues related,


directly or indirectly, to error detection
and error correction.

4
• The data link layer is responsible for node-to-node (hope-to-hope) delivery of
data. Responsibilities of the data link layer include framing, flow control, error
control and media access control.

• The data link layer adds reliability to the physical layer through a mechanism to
detect and retransmit damaged, duplicate or lost frames.

• Data can be corrupted during transmission.

• Some applications tolerate a small amount of transmission errors to occur, such


as in audio or video transmission.

• Some other applications require that errors be detected and corrected, such as in
text transmission.

5
• When transmitting a given data unit (such as a byte) a single-bit transmission
error means that only one bit in the data unit is inverted.

6
• A burst of noise can cause a burst of errors in the transmitted data.

• As an example, a noise burst of 0.01 s can affect 10 bits if the data rate was 1
kbps. Whereas, the same noise burst can affect 10000 bits if the data rate
was 1 Mbps.
7
• A burst of noise is more likely to occur than a single-bit error.

• Transmission errors can be detected and corrected by transmitting extra bits


(referred to as redundant bits) with the original data stream. This principle is
called redundancy.

8
Error Control

• There are two types of error control:

 Error detection:

Detect the occurrence of errors in a transmitted unit of data without


determining which bits are corrupted.

 Error correction:

Determine which bits are corrupted in a transmitted unit of data and


correct them.

9
• Error correction can be classified into two categories:

 Forward error correction:

The receiver uses the redundant bits to allocate the corrupted bits and
correct them.

 Retransmission:

Retransmission of the data is required when transmission errors are


detected by the receiver. Timer-based mechanisms and/or
Acknowledgement schemes are employed in this case.

10
Block Coding
• At the receiver redundant bits are added such that to create a relationship
between the data bits and the redundant bits. The receiver checks the
relationship between the received redundant bits and the received data bits to
detect transmission errors and correct them.

• In block coding, the message is divided into blocks called data-words. Each
data-word has “k” bits. A number of “r” redundant bits are added to each
data-word to make a code-word with length “n = k + r”.

11
• With “k” bits there is a combination of 2 k data-words.

With “n” bits there is a combination of 2 n code-words.

Therefore, there are 2n  2k of unused code-words.

• Unused code-words are referred to as invalid or illegal code words.

Example
In the 4B/5B block coding, k = 4 and n = 5. Therefore, there are:

2k  2 4  16 data - words
2n  25  32 code - words

Only 16 out of 32 code-words are used for message transfer and the rest are
either used for other purposes or unused.
12
Error Detection In Block Coding
• The sender creates code-words out of data-words. At the receiver, if the
received code-word matches one of the valid code-words, the data-word is
extracted from the code-word. Otherwise, if the received code-word is invalid, it
is discarded.

• Two or more errors in a code-word may remain undetected if the received


codeword still matches a valid codeword.

13
Example
Assume k = 2 and n = 3 for a block coding scheme with the data-words to code-
words conversion table given below.

Assume the sender


encodes the data-word
“01” into “011” code-word.

• If “011” is received, the data-word “01” is extracted.

• If “001” is received, the code-word is not valid and is discarded.

• If “000” is received, the wrong data-word “00” is extracted.


14
Error Correction In Block Coding
• More redundant bits are needed to achieve error correction as compared to
error detection.

• In error correction, the receiver needs to detect the correct code-word sent.

15
Example
Assume k = 2 and n = 5 for a block coding scheme with the data-words to code-
words conversion table given below.

Assume the sender


encodes the data-word
“01” into “01011” code-word.

Assume a transmission error happens in the second bit from right. That is,
“01001 is received.

The receiver compares the received code-word with the valid code-words in the
above table and decides that it matches the second code-word because there
is a difference in only one bit between them. Whereas, there is a difference in
more than one bit between the received code-word and any other valid cod-
word.
16
Hamming Distance
• The Hamming distance “d” between two words w1 and w2 is the number of
differences between their corresponding bits.

• The Hamming distance d ( w1 , w2 ) can be found by counting the 1s resulting


from XORing the bits of w1 with the corresponding bits of w2 . That is:

d (w1 , w2 )  number of 1s inw1  w2 

• Examples of the Hamming distance:

d (000,011)  number of 1s in 000  011


 number of 1s in 011  2

d (10101,11110)  number of 1s in 10101  11110


 number of 1s in 01011  3
17
• The minimum Hamming distance is the smallest Hamming distance between
all possible pairs in a set of words.

Example
Find the minimum Hamming distance for the coding scheme in table below.

Minimum Hamming
distance : d min  2

d (000,011)  2 d (000,101)  2 d (000,110)  2


d (011,101)  2 d (011,110)  2
d (101,110)  2
18
Example
Find the minimum Hamming distance for the coding scheme in table below.

d (00000,01011)  3 d (00000,10101)  3 d (00000,11110)  4


d (01011,10101)  4 d (01011,11110)  3
d (10101,11110)  3

Minimum Hamming distance : d min  3


19
Minimum Hamming Distance
For Error Detection and Correction

• To allow the detection for up to “s” transmission errors per unit of data, the
minimum Hamming distance between the valid code-words must be:

d min  s  1

• To allow the correction for up to “t” transmission errors per unit of data, the
minimum Hamming distance between the valid code-words must be:

d min  2t  1

20
Geometric concept for finding dmin in error detection

21
Geometric concept for finding dmin in error correction

22
Example
Find the error detection and correction capability for the coding scheme in table
below.

d min  s  1  3  s2

d min  2t  1  3  t 1

Thus, this scheme is capable of detecting up to 2 transmission errors per word,


and it is capable of detecting and correcting only 1 error per word.
23
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.

24
Example 10.1
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.
Table 10.1: A code for error detection in Example 10.1

25
Example 10.2
Let us find the Hamming distance between two pairs of
words.

26
Example 10.3
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.

Table 10.1: A code for error detection in Example 10.1

27
Example 10.4
A code scheme has a Hamming distance dmin = 4. This code
guarantees the detection of up to three errors (d = s + 1 or
s = 3).

Note: 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 or s = dmin - 1

28
Example 10.5
The code 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.

Table 10.1: A code for error detection in Example 10.1

29
Example 10.6
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.

Table 10.1: A code for error detection in Example 10.1

30
Table 10.2: Simple parity-check code C(5, 4)

Simple parity-check code is a linear block code. In this code, a


k-bit dataword is changed to an n-bit codeword where n = k + 1.

The extra bit is called parity bit, is selected to make the total
number of 1s in the codeword even.

31
Figure 10.4: Encoder and decoder for simple parity-check code

32
Example 10.7
Let us look at some transmission scenarios. Assume the
sender sends the dataword 10110. The codeword created
from this dataword is 10111, which is sent to the receiver.
We examine five cases:

33
10-3 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. For example, if 1011000 is a
codeword and we cyclically left-shift,
then 0110001 is also a codeword.

34
10.3.1 Cyclic Redundancy Check

We can create cyclic codes to correct errors.


However, the theoretical background required is
beyond the scope of this book. In this section, we
simply discuss a subset of cyclic codes called the
cyclic redundancy check (CRC), which is used in
networks such as LANs and WANs.

35
Table 10.3: A CRC code with C(7, 4)

36
Cyclic Redundancy Check (CRC):

 This is an extremely effective method of detecting error bursts.


Error usually occurs in bursts which normally affects 2, 3, 4, 5, or
more bits in a row.

 The efficiency of CRC-12 has been determined to be 99.95% in


detecting error bursts of up to 12 bits in length. Although the
technique is primarily used for binary data, the underlying concept is
first explained using decimal numbers.

 Suppose the message to be transmitted is 348697 decimal. The


transmitter and the receiver first agree on a common divider, say 9.

 The transmitter divides the message by 9 and includes the


remainder in the message as the last digit as shown in Fig. A.

37
Figure A Decimal CRC example.

The receiver receives the message and performs division by 9.


Then compares the remainder with the remainder received with the
message . If the remainders match no error occurred.

38
Figure 10.5: CRC encoder and decoder

39
Figure 10.6: Division in CRC encoder

40
Figure 10.7: Division in the CRC decoder for two cases

41
The CRC is a mathematical technique that is used in synchronous data
transmission.
In this technique, each string of bits is represented by a polynomial function.
The technique is done by division. It is illustrated as follows:
M ( x)
 Q ( x)  R ( x)
G ( x)
where M(x) is the binary data, called the message function, and G(x) is a special
code for which the message function is divided, called the generating function.
The process yields a quotient function, Q(x), and a remainder function, R(x).
The quotient is not used, and the remainder, which is the CRC block check code
(BCC), is attached to the end of the message.
At the receiver, the message and CRC check character pass through its block
check register (checker). If the register’s content is zero, then the message
contains no errors.
CRC codes are easy to implement, requiring only the use of shift registers, XOR
gates, and feedback paths.

42
Hardware implementation of the CRC technique:

 This apparently complex mathematical technique requires


extremely simple hardware for its implementation. A careful analysis
of the previously described division process indicate that the process
consists of simply a series of shifting to the right and EX-ORing
operations. To implement this process only shift registers and EX-OR
gates are required. The shift register contains flip-flops. The number
of flip-flops required is equal to the highest power of G(x). The EX-OR
gates are placed after each “x” term in G(x). The message is fed to the
first EX-OR gate on the right. The other input of the first EX-OR gate of
the right is connected to the output of the last FF. The output of the
first EX-OR gate is fed back to the inputs of other EX-OR gates as well
as to the input of the first FF. Output of each FF is connected to the
input of the next EX-OR gate or to the input of the following FF.

 Let us apply this technique to our G(x) = x4 + x3 + x1 +1 as follows:


43
4. Also connect the output of the FF’s to one of the input of the
following Ex-OR gate (if they exist) or the succeeding FF input. With
an Ex-OR gate between any two FF connect the output of the Ex-OR
gate to the next FF input, as shown above.

44
5. Connect the message polynomial M(x) to the first Ex-OR gate on the right
and connect the output of the first EX-OR gate on the right to the 2nd
inputs of all EX-OR gate as well as to the input of first FF on the left, i.e.,
FF # 1.

The number of clock pulses required to generate the remainder in the shift
register is equal to the number of message bits. In our case, it will take 8 clock
pulses (because the message is 11001101, 8 bits) to generate the R(x) in the
shift register. Four additional clock pulses will piggyback R(x) on the M(x).
The complete T(x) will be shifted out of the first Ex-OR gate (on the right) at
the end of the 12th clock pulse. Figure 10 shows the generation of R(x) in the
shift register step by step after each clock pulse is applied for a G(x) = x3 + x +
1 and M(x) = 101001. 45
Figure 10

Note: Remainder available in the shift register after 6th clock


46
pulse.