DC Module3 - Error Detection
DC Module3 - Error Detection
• Some applications can tolerate a small level of error. For example, random
errors in audio or video transmissions may be tolerable, but when we
transfer text, we expect a very high level of accuracy.
• Whenever bits flow from one point to another, they are subject to
unpredictable changes because of interference (change the shape of the
signal).
• To be able to detect or correct errors, we need to send some extra bits with
our data.
• These redundant bits are added by the sender and removed by the receiver.
Their presence allows the receiver to detect or correct corrupted bits.
example
10.5
Redundancy
• Redundancy is achieved through various coding schemes.
• Parity check
• Checksum
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.
Since n > k, the number of possible codewords is larger than the number of possible
datawords
Question
1) For each of the following sets of codewords, please give the appropriate (n,k)
designation where n is number of bits in each codeword and k is the number of
message bits transmitted by each code word.
{111, 100, 001, 010}
2^k =2^2=4
• n=5 k=2
2^k =2^2=4
BLOCK CODING
Error Detection
• Enough redundancy is added to detect an error.
• The receiver knows an error occurred but does not know which bit(s) is(are) in error.
• Has less overhead than error correction.
Error Correction
Detection versus Correction
• In error detection, we are only looking to see if any error has occurred.
• We are not even interested in the number of corrupted bits.
• In error correction, we need to know the exact number of bits that are
corrupted and, more importantly, their location in the message.
Error Detection
How can errors be detected by using block coding? If the following two conditions
are met, the receiver can detect a change in the original codeword.
Codeword (011)
Sender Receiver
1. The receiver receives 011. It is a valid codeword. The receiver extracts the dataword
01 from it.
2. The codeword is corrupted during transmission, and 111 is received (the leftmost bit
is corrupted). This is not a valid codeword and is discarded.
3. The codeword is corrupted during transmission, and 000 is received (the right two
bits are corrupted). This is a valid codeword. The receiver incorrectly extracts the
dataword 00. Two corrupted bits have made the error undetectable.
Error Detection
Let us add more redundant bits to Example 10.1 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.
Table 10.2
Error Detection
Codeword (01011)
Sender Receiver
01001
1. Comparing the received codeword (01001) 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.
10.14
Hamming Distance
• The Hamming distance between two words (of the same size) is the number
of differences between the corresponding bits
• The Hamming distance between the received codeword and the sent codeword
is the number of bits that are corrupted during transmission
• 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.
• 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.
(00000 ⊕ 01101 =01101) =3 (three one’s)
Note
• “If the Hamming distance between the sent and the received
codeword is zero”, the codeword is not corrupted during
transmission.
• “If the Hamming distance between the sent and the received
codeword is not zero”, the codeword has been corrupted
during transmission.
10.
Minimum Hamming Distance for Error Detection
The minimum Hamming distance is the smallest Hamming distance between
all possible pairs of codewords
n=5 , k=2 , d =1
Question
1) For each of the following sets of codewords, please give the appropriate (n,k,d)
designation where n is number of bits in each codeword, k is the number of message bits
transmitted by each code word and d is the minimum Hamming distance between
codewords.
Example: If the codeword 00000 is sent and 01101 is received, S=3 bits are
in error and the Hamming distance between the two is d(00000, 01101) = S=3
(00000 ⊕ 01101 =01101) =3 (three one’s)
Minimum Hamming 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.
The minimum Hamming distance for our first code scheme 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.
If our system is to detect up to s errors, the minimum distance between the valid
codes must be (s + 1), so that the received codeword does not match a valid
codeword.
Minimum Hamming Distance for Error Detection
• Our second block code scheme 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.
For example, if the second codeword (01011) is sent and one error occurs, the
received codeword does not match any valid codeword. If two errors occur, the
received codeword does not match any valid codeword. If three errors occur the
received codeword may match a valid codeword (01011 – 00000, instead of 01
the data 00 will be considered) and the errors are not detected.
Figure 10.8 Geometric concept for finding dmin in error detection
Let us assume that the sent codeword x is at the center of a circle with radius s.
All received codewords that are created by 0 to s errors are points inside the circle or
on the perimeter of the circle.
All other valid codewords must be outside the circle. This means that dmin must be an
integer greater than s or dmin = s + 1.
Question
• A code scheme has a Hamming distance dmin = 10. What is the
error detection capability of this scheme?
dmin = s + 1 =9+1=10
Question
• A code scheme has a Hamming distance dmin = 4. What is the
error detection capability of this scheme?
Question
• A code scheme has a Hamming distance dmin = 4. What is the
error detection capability of this scheme?
dmin = s + 1
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.
The numbers of 1s in the nonzero codewords are 3, 3, and 4. So in this code we have dmin = 3.
Parity-Check Code
• This 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, called the parity bit, is selected to make the total number of 1s in
the codeword even.
Table 10.3 Simple parity-check code C(n=5, k=4)
r0 = a3 + a2 + a1 + a0 (modulo-2)
s0 = b3 + b2 + b1 + b0 + q0 (modulo-2)
• If the syndrome is 0, there is no detectable error in the received codeword; the data
portion of the received codeword is accepted as the dataword;
• If the syndrome is 1, the data portion of the received codeword is discarded. The
dataword is not created.
Encoder and decoder for simple parity-check code
Let us look at some transmission scenarios.
Codeword: 10111
Sender Receiver
Dataword: 1011
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. Note that although none of the dataword
bits are corrupted, no dataword is created because the code is not sophisticated
enough to show the position of the corrupted bit.
Encoder and decoder for simple parity-check code
Let us look at some transmission scenarios.
Codeword: 10111
Sender Receiver
Dataword: 1011
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. The
simple parity-check decoder cannot detect an even number of errors.
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. But cannot detect an even number of errors
Note
0101 1111
1010 1010
1111 0101
Cyclic shifting:
• In a cyclic code, if a codeword is cyclically shifted (rotated), the
result is another codeword.
Dataword:1001000
Divisor: 1011
Modulo 2 (XOR)
10.
Figure 10.16 Division in the CRC decoder for two cases
10.
Assume the data to be transmitted is
Data: 100100
Divisor:1101
Sender 100100 000 (one number less than the divisor)
111101
1101 100100000
1101
1000
1101 Sender sends the codeword to receiver:
1010 100100001
1101
1110
1101
0110
0000
1100
1101
001
Assume the data to be transmitted is
Data: 100100
Divisor:1101
Receiver received 100100001
111101
1101 100100001
1101
1000
1101
1010
1101
1110
1101
0110
0000
1101
1101
Syndrome=0 ---- no errors
0000
CRC encoder and decoder
• The dataword has k bits (4 here); the codeword has n bits (7 here).
• The size of the dataword is augmented by adding n − k (3 here) 0s to the right hand side
of the word. The n-bit result is fed into the generator.
• The generator uses a divisor of size n − k + 1 (4 here), predefined and agreed upon.
• The generator divides the augmented dataword by the divisor (modulo-2 division).
• The quotient of the division is discarded; the remainder (r2r1r0) is appended to the
dataword to create the codeword.
Question
A bit stream 10011101 is transmitted using the standard CRC
method. The divisor is 1001.
• What is the actual bit string transmitted?
Polynomials
• We can use a polynomial to represent a binary word.
Note
• The degree of a polynomial is the highest power in the polynomial. For example, the
degree of the polynomial x^6 + x + 1 is 6. Note that the degree of a polynomial is 1 less
than the number of bits in the pattern.
Addition: x5 + x4 + x2 Multiplication: x3 × x4 is x7
x6 + x4 + x2
x6 + x5 Division: x6/x3, or x3
Polynomials
1. The information sequence (x) =100100000. Write the corresponding polynomial
equation.
The divisor in a cyclic code is normally called the generator polynomial g(x) or
simply the generator.
Let Divisor / g(x)=x^3 + x+1. Consider the information sequence:1001000
1001000=x^6 +X^3
Sender
X^3+x
Note: we continue to divide until the degree of the remainder is less than the degree of
the divisor.
Let g(x)=x^3 + x+1. Consider the information sequence:1001011
1001011=x^6 +X^3
Receiver
X^3+x^1
0
Does CRC detect all errors (1 bit, 2bits and burst errors) ?
Divisor: 1 0 0
Message received = 1 0 1 0 1 1 0 0
Message received = message transmitted + error polynomial, i.e.,
1 0 1 0 1 1 0 0= 1 0 1 0 1 0 0 0 + 0 0 0 0 0 1 0 0
100 ) 1 0 1 0 1 1 0 0
000
• Clearly both are divisible by the divisor 1 0 0. In general, if the error polynomial is
divisible by the divisor, then such errors are undetected by the receiver. The receiver
wrongly concludes that there is no error in transmission
If the divisor is 1 0 1, then both errors are detected by the receiver. Thus,
choosing an appropriate divisor is crucial in detecting errors at the
receiver if any during the transmission.
Cyclic Code Analysis
• We can analyze a cyclic code to find its capabilities by using polynomials.
We define the following, where f(x) is a polynomial with binary
coefficients.
Dataword: d(x) Codeword: c(x) Generator: g(x) Syndrome: s(x) Error: e(x)
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.
Cyclic Code Analysis
In our analysis we want to find the criteria that must be imposed on the
generator, g(x) to detect the type of error we especially want to be detected.
The received codeword is the sum of the sent codeword and the error.
Received codeword = c(x) + e(x)
The receiver divides the received codeword by g(x) to get the syndrome.
In a cyclic code, those e(x) errors that are divisible by g(x) are not caught.
• Single-Bit Error
• Two Isolated Single-Bit Errors
• Odd Numbers of Errors
• Burst Errors
Note on Polynomials
• If a polynomial has no factors other than 1 and itself, it is a prime
polynomial or an Irreducible Polynomial.
https://www.ece.unb.ca/tervo/ee4253/polytable.shtml
http://www.ee.unb.ca/cgi-bin/tervo/factor.pl?binary=11000001
Cyclic Code Analysis
If the generator has more than one term and the coefficient of x0 is 1,
all single errors can be caught.
Solution
a. No xi can be divisible by x + 1. In other words, xi/(x + 1) always has a
remainder. Any single-bit error can be caught. Also, (x + 1) is irreducible.
b. xi/1
All values of i make xi divisible by g(x). No single-bit error can be caught. This
g(x) is useless.
In another way,
If we make G(x) not prime but a multiple of (x+1), then E(x) can't be divided by G(x). can
detect all odd no. of errors.
• We can show this type of error as e(x) = x^j + x^i. The values of i and j
define the positions of the errors, and the difference j − i defines the
distance between the two errors,
If g(x) has more than one term and one term is x^0, it cannot divide x^i, as we saw in
the previous section. g(x) = more than one term +1 xi / (more than one term + 1)
Solution
a. This generator cannot detect two errors that are four
positions apart. The two errors can be anywhere, but if their distance is 4,
they remain undetected.
• where L is the length of the error. All burst errors with length
smaller than or equal to the number of check bits r will be
detected
Burst Errors
Standard polynomials
The divisor polynomials are such that it detects almost all odd bit errors and a few even
bit errors. The commonly used polynomials in the literature are
Note
• Asynchronous Transfer Mode and refers to a communication protocol which can be used to
transfer data, videos and speech.
• ATM adoption layer is basically a software layer that accepts user data, which may be digitized
voice, video or computer data, and makes them suitable for transmission over an ATM network.
• HDLC is a group of data link (Layer 2) protocols used to transmit synchronous data packets
between point-to-point nodes.
Note: Ethernet Header
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.
36 - 100100 45 – 101101
0100 1101
10 Binary addition 10
0110 =6 1111=15
Instead of sending 36 as the sum, we can send 6 as the sum (7, 11, 12, 0, 6, 6).
CHECKSUM
What is the reason for wrapping (the extra leftmost bits need to be added to the m
rightmost bits)?
CHECKSUM
• At the source, the message is first divided into m-bit units. The generator then creates an extra
m-bit unit called the checksum, which is sent with the message.
• At the destination, the checker creates a new checksum from the combination of the message
and sent checksum.
• If the new checksum is all 0s, the message is accepted; otherwise, the message is discarded
Internet Checksum
Advantages:
– Fast checking
– Small number of bits required
Disadvantages:
For example, if the value of one word is incremented and the value of another word is
decremented by the same amount, the two errors cannot be detected because the sum
and checksum remain the same.
– Not robust
– Also, if the values of several words are incremented but the sum and the
checksum do not change, the errors are not detected.
Note
Other Approaches to the Checksum
• Fletcher and Adler have proposed some weighted checksums that eliminate the first
problem. However, the tendency in the Internet, particularly in designing new
protocols, is to replace the checksum with a CRC.
• Fletcher Checksum is a block code technique that was devised by John G. Fletcher
in 1970s at Lawrence Livermore Labs, USA.
• (212)10 = D4
Simulate the Fletcher algorithm to calculate the checksum of the following
bytes: (2B)16 , (3F)16, (6A) (AF)16. Also show that the result is a weighted
16,
checksum
Di R=0 L=0
Step1 2B 2B 2B
Step2 3F 6A 95
Step3 6A D4 69
Step4 AF 83 EC
CHEKSUM = L R = EC 83
Checksum= (EC X 256) + 83
= 236 X 256 = 60416 = (3776 )16
3776+ 83 = (37F9) 16
Step2:
2B = 2x16^1 + Bx16^0 = 32+11=43
3F = 48 + 15 =63 Step3:
R= 43+63= 106 = (6A)16 R= 6A + 6A = 106 + 106 =212 = (D4)16
L= 2B+6A = 43+106 =149 =(95)16 L= 95 + D4 = 149 +212 = 361 mod 256 =105 = (69)
Step4:
R=AF+D4 = 175+212 =387 mod 256 = 131 = 83
L= 69 + 83 = 105 + 131 = 236 =EC
Simulate the 8-bit Fletcher algorithm to calculate the 16-bit checksum of the
following bytes: (2A)16 , (3B)16,
Di R=0 L=0
Step1
Step2
CHEKSUM = L R =
Simulate the Fletcher algorithm to calculate the checksum of the
following bytes: (2B)16 , (3F)16, (6A) (AF)16. Also show that the
16,
L R EC 83
Fletcher Checksum (16 bit)
• The second, 16-bit Fletcher, calculates on 16-bit data items and creates a
32-bit checksum.
• The 16-bit Fletcher checksum is similar to the 8-bit Fletcher checksum, but
it is calculated over 16-bit data items and creates a 32-bit checksum. The
calculation is done modulo 65,536.
Adler Checksum
• The Adler checksum is a 32-bit checksum
• We need to correct the error or reproduce the packet immediately. Several schemes have
been designed and used in this case that are collectively referred to as forward error
correction (FEC) techniques.
• Forward error correction works by adding redundant bits to a bitstream to help the
decoder detect and correct some transmission errors without the need for retransmission.
The name forward stems from the fact that the flow of data is always in
the forward direction (i.e., from encoder to decoder).
• 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.
(00000 ⊕ 01101 =01101) =3 (three one’s)
10 10011 1 4 2
11 01111 2 1 3
2 3 3
Data: 01 00 01 11 10 00 01
5 2 2
00 11
00
01 00 01 Resend 10 10
Undetectable error has transmitted. Three bit error is not possible to detect in this example.
We can make it robust by having longer codewords!
Forward Error Correction using Hamming Distance
• We said that to detect s errors, the minimum Hamming distance should be
dmin = s + 1
• For error detection, we definitely need more distance. It can be shown that
to detect t errors, we need to have dmin = 2t + 1
• To give an example, consider the famous BCH code. In this code, if data is
99 bits, we need to send 255 bits (extra 156 bits) to correct just 23 possible
bit errors. Most of the time we cannot afford such a redundancy
Questions
(It can be shown that to detect t errors, we need to have dmin = 2t + 1)
Pi = P1 ⊕ P2 ⊕ … ⊕ R ⊕ … ⊕ PN
• If we apply the exclusive OR operation on N data items (P1 to PN), we can recreate
any of the data items by exclusive-ORing all of the items, replacing the one to be
created by the result of the previous operation (R).
• We can divide a packet into N chunks, create the exclusive OR of all the chunks and
send N + 1 chunks. If any chunk is lost or corrupted, it can be created at the receiver
site.
Data: 0011 0100 0000 0011 || 0100
0011 0011
⊕ 0100 0100
0111 0111
⊕ 0000 0100
0111 0011
⊕ 0011 0011
R=0100 0000
Forward Error Correction using chunk Interleaving
• we can divide each packet into 5 chunks (normally the number is much larger). We
can then create data chunk by chunk (horizontally), but combine the chunks into
packets vertically. In this case, each packet sent carries a chunk from several
original packets. If the packet is lost, we miss only one chunk in each packet, which
is normally acceptable in multimedia communication.
5+4+3+2+1=15 15-1=14-2=12=12-4=8-5=3
Forward Error Correction using –
Combining Hamming Distance and Interleaving
• Hamming distance and interleaving can be combined.
• We can first create n-bit packets that can correct t-bit errors. Then we
interleave m rows and send the bits column by column.
• In this way, we can automatically correct burst errors up to m × t-bit errors.
Forward Error Correction using –
Compounding High- and Low-Resolution Packets