230 likes | 441 Views
Error detection and correction. How can the receiver determine if there was an error in the message the sender sent? How can these errors be fixed?. Types of errors. Single-bit : Only one bit is changed. Very rare. Burst : Many bits are changed over a duration of time. More common.
E N D
Error detection and correction How can the receiver determine if there was an error in the message the sender sent? How can these errors be fixed?
Types of errors • Single-bit: Only one bit is changed. Very rare. • Burst: Many bits are changed over a duration of time. More common
Block coding • In block coding, we convert chunks of k bits, called datawords, into somewhat longer chunks of n words, called codewords. • Just like when we did line coding at the physical layer to give ourselves synchronization, the fact that there are more codewords than datawords means that some are valid and some are not.
Hamming distance • Researchers who try to develop better and more efficient error detection schemes use the Hamming distance to measure how different two words of equal bit length are. • We use XOR to calculate the difference. • When designing a particular coding scheme, what we use is the minimum Hamming distance between all possible pairs of codewords (dmin).
dmin and error detection • What qualifies as a good dmin? • In order to detect up to s errors in a transmission, dmin must equal s + 1. • If it is only s, then the received codeword could be mistaken for a valid one. If it is s + 1, it never can be. • Since error correction requires more information, it requires a bigger dmin. 2s, to be precise.
Linear block codes • Linear block codes are specially designed codes where the XOR of any two codewords yields another valid codeword. • To find dmin for any block code, find the valid codeword with the least number of 1s (that has at least 1). dmin is the number of 1s in that codeword.
Simple parity • The simplest linear block code is the parity check. • n = k + 1. • The extra bit simply encodes whether the number of 1’s in the data word is odd (parity=0) or even (parity=1). • The idea is that the total number of 1’s in the codeword is even. • What is dmin?
Two-dimensional parity • Extends the idea of parity to allow for detection of larger errors. • Datawords are organized into a table. Parity bits are calculated for each row and column in the table. If the table is k x r bits, the codeword is (k+1) x (r+1) bits.
Hamming codes • Designed so that dmin = 3, meaning they can detect two bit errors or correct one bit errors. • The relationship between n and k is defined such that n = 2m - 1, and k = n - m. m is the number of check bits we want to have. • Our discussion will focus on C(7, 4).
Generating the Hamming code • The top four bits of the codeword are the dataword. • The bottom three bits are calculated as follows: • r0= a2+ a1 + a0 • r1= a3 + a2 + a1 • r2 = a1 + a0 + a3
Checking the Hamming code • The receiver gets the codeword and uses it to calculate three syndrome bits: • s0 = b2 + b1 + b0 + q0 • s1 = b3 + b2 + b1 + q1 • s2 = b1 + b0 + b3 + q2 • The pattern of syndrome bits tells us what bit was in error, so the receiver can fix it.
Cyclic codes • Cyclic codes are special linear block codes with the property that if you bit shift any codeword, you get a new valid codeword. • Used exclusively for error detection, but use is very widespread because they are very easy to implement in hardware.
Cyclic Redundancy Check (CRC) • Once again, for C(7,4)…. • Encoding: • The dataword becomes the top four bits of the codeword. • The bottom three bits are calculated as follows: • Take the dataword and tack three 0’s onto the end. • This is divided by a pre-arranged divisor. • The remainder becomes the bottom three bits • Decoding: • Divide the codeword by the divisor. • If the remainder is 0, the dataword is good. If not, there was an error.
Choosing a divisor • How good a given CRC is at detecting errors depends on the divisor that is chosen. • Think of a bit pattern in terms of polynomials, so the pattern 100101 would be x5 + x2 + 1. • Now let’s analyze what happens in terms of polynomial functions. The codeword received is equal to the sent codeword, c(x), plus the error, e(x). • To extract the dataword from the codeword, we divide by the divisor, g(x), so:
By definition, c(x)/g(x) has no remainder. • So, if Codeword/g(x) has a remainder, there must be an error. • If it has no remainder, one of two things is true: • Either e(x) = 0 (good!) • Or e(x)/g(x) has no remainder (bad!) • So, we need to pick our divisor, g(x), such that it will only very infrequently lead to the second case.
Single bit errors. • Any single bit error is xi. • Any polynomial of the form xk + 1 will always have a remainder when dividing with xi. • Isolated single bit errors • e(x) = xj + xi= xi(xj-i + 1) • Odd numbers of errors: Make x - 1 one of the factors • Burst errors: • e(x) = xj + … + xi =xi(xj-i +… + 1) • We are worried about if (xj-i +… + 1)/(xr + … + 1) has a remainder or not. • If j-i < r, the remainder will never be 0. (L ≤ r) • If j-i = r, the remainder can be 0 with a probability of (1/2)r-1 • If j-i > r, the remainder can be 0 with a probability of (1/2)r