430 likes | 1.17k Views
Error Detection and Correction. 10.1 Introduction. Data can be corrupted Single-bit error: Burst error:. Redundancy. Extra information (redundant bits) can be used to “detect” and “correct” errors Coding (to add redundant bits). Encoding. Decoding. 10.2 Block Coding.
E N D
10.1 Introduction • Data can be corrupted • Single-bit error: • Burst error:
Redundancy • Extra information (redundant bits) can be used to “detect” and “correct” errors • Coding (to add redundant bits) Encoding Decoding
10.2 Block Coding • Coding schemes can be divided into two broad categories: block coding and convolution coding • Background • Modular arithmetic (modulus N): Use only a limited number of integers [0, 1, 2, …, N-1] • E.g., 7 + 6 in modular-9 arithmetic is 4, or “(7+6) % 9 = 4” • Exclusive OR (XOR) = modular-2 arithmetic
Block Coding • Datawords: messages divided into k-bits blocks • Codewords: k-bit datawords + r-bits redundancy • We have 2n codewords, but use only 2k datawords • There are 2n – 2k invalid codewords (i.e., unused codewords)
Example of Error Detection • Datawords and codewords • Example: sender encodes dataword 01 as 011 • If receiver receives 011, decodes it to 01 • If receiver receives 111 (i.e., there is a single bit error), which is not a valid codeword, detects the error • If receiver receivers 000 (i.e., there are two bits error), decodes it to 00 undetectable errors
Example of Error Correction • Datawords and codewords • Example: sender encodes dataword 01 as 01011 • Receiver received 01001 • Finds the codeword that is closest to 01001 • 01011 has a single-bit difference • 00000 2-bit difference, …, 11110 3-bit difference • Decodes it to 01
Hamming Distance • Hamming distance between two words is the number of differences between corresponding bits • Minimum hamming distance (dmin) is the “smallest” Hamming distance between all possible pairs in a set of words 111 100 000
Hamming Distance for Detection • To guarantee detectionof up to “s” errors, we should have dmin > s
Hamming Distance for Correction • To guarantee correction of up to “t” errors, we should have dmin > 2t
Example • Minimum Hamming distance? • How many bit errors can be detected? • How many bit errors can be corrected?
10.3 Linear Block Codes • Precise definition is out of scope • Informally, in a linear block code, XOR of any two valid codewords creates another valid codeword • Previous two sets of codewords are linear block codes • Minimum Hamming distance of linear block codes is the minimum number of 1’s in a non-zero codeword
Simple Parity-Check Code • A k-bit dataword is encoded into (k+1)-bit codeword • The extra bit is chosen to make the number of 1’s in the codeword “even” • Simple parity-check code is a single-bit error-detecting code, with dmin = 2 The last bit (0 or 1) is added
Implementation of Simple Parity-Check Code • s0 = b3 + b2 + b1 + b0 + q0 (modulo 2) • If s0 is 1, discard the received codeword
Two-Dimensional Parity Check • Example: four 7-bit datawords become five 8-bit codewords • Can detect up to 3 errors Cannot detect 4 errors
Hamming Codes • We consider hamming codes with dmin = 3 • Detect two errors, or correct one single error • Choose a number m ≥ 3, then • Codeword length n = 2m – 1 • Dataword length k = n – m • Number of check bits r = m • Example: m = 3, n = 7 (=23–1), k = 4 (=7–3) • Dataword “a3a2a1a0” Codeword “a3a2a1a0 + r2r1r0” • r0 = a2 + a1+ a0 (modulo-2) • r1 = a3 + a2+ a1 (modulo-2) • r2 = a1 + a0+ a3 (modulo-2) Each bit (e.g., a0) is covered by two parity bits (e.g., r0 and r2)
Hamming Codes • r0 = a2 + a1+ a0 (modulo-2) • r1 = a3 + a2+ a1 (modulo-2) • r2 = a1 + a0+ a3 (modulo-2) • Calculation of syndrome • s0= b2+ b1+ b0 + q0(modulo-2) • s1= b3+ b2+ b1 + q1 (modulo-2) • s2= b1+ b0+ b3 + q2 (modulo-2) • Decision to correct a single-bit error
Hamming Codes • Example • Received codeword 0100011 and syndrome is 000, what is the dataword? • Received codeword 0011001 and syndrome is 011, what is the dataword?
Hamming Codes • Detect a burst error
10.4 Cyclic Codes • Linear block codes with the following property • If a codeword is cyclically shifted, the result is another codeword • Our discussion is limited to a typical example, called Cyclic Redundancy Check (CRC) shift
Implementation • Case of CRC with 4-bit dataword, 7-bit codeword
CRC Encoder Result of XOR
CRC Decoder Non-corrupted bits Corrupted bits The same divider as encoder
Hardware Design • CRC encoder and decoder can be easily implemented using shift registers • Encoder example: divisor = 1011 It takes n-k times to get the result
CRC Encoder using Shift Registers • Divisor = 1011
Polynomials • A pattern can be considered as coefficients of a polynomial • Adding and subtracting are done between the coefficients of the same power • Ex:
Division using Polynomials • Encoder = 1001 1011 =
Cyclic Code Analysis • Dataword d(x), codeword c(x), divisor g(x), syndrome s(x), error e(x) • At receiver, received codeword = c(x) + e(x) • After decoding, we have • An error cannot be detected if e(x) is divisible by g(x)
Design of Divisor • Single-bit error: e(x) = xa for some a • Divisor has more than one term and the least coefficient (i.e., of x0) is 1 • Two-bit error: e(x) = xa + xb for some a, b • Divisor should not divide xt+1 • Odd numbers of errors • Divisor should have the factor (x+1) • Burst errors: e(x) = xa (1+ … + xb ) for some a, b • All burst errors of b-a+1 <= r will be detected • All other errors will be detected with probability 1-(1/2)r-1-(1/2)r
10.5 Checksum • Often used in the Internet protocols • Idea • For data (7, 11, 12, 0, 6), • send (7, 11, 12, 0, 6, -36), where 36 = 7+11+12+0+6 • Receiver checks error by adding all elements • One’s complement • For the case, when the addition results in a large number more than n bits
Checksum Procedure One’s complement for 4-bit binary 1 1 1 1 0 0 0 0 1 0 0 1 9 = – 6 in one’s complement representation