32
ERROR DETECTION AND CORRECTION

ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Embed Size (px)

Citation preview

Page 1: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

ERROR DETECTION AND CORRECTION

Page 2: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

10.1 Introduction• Data can be corrupted

• Single-bit error:

• Burst error:

Page 3: 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

Page 4: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

Page 5: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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)

Page 6: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Example of Error Detection• Datawords and codewords

• Example: sender encodes dataword 01 as 0111. If receiver receives 011, decodes it to 01

2. If receiver receives 111 (i.e., there is a single bit error), which is not a valid codeword, detects the error

3. If receiver receivers 000 (i.e., there are two bits error), decodes it to 00 undetectable errors

Page 7: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

Page 8: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

000

100

Page 9: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Hamming Distance for Detection• To guarantee detection of up to “s” errors, we should

have dmin > s

Page 10: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Hamming Distance for Correction• To guarantee correction of up to “t” errors, we should

have dmin > 2t

Page 11: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Example

• Minimum Hamming distance?• How many bit errors can be detected?• How many bit errors can be corrected?

Page 12: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

Page 13: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

Page 14: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Implementation of Simple Parity-Check Code

• s0 = b3 + b2 + b1 + b0 + q0 (modulo 2)• If s0 is 1, discard the received codeword

Page 15: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Two-Dimensional Parity Check• Example: four 7-bit datawords become five 8-bit

codewords

• Can detect up to 3 errors

Cannot detect 4 errors

Page 16: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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)

Page 17: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Hamming Codes

Page 18: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Hamming Codes• 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

r0 = a2 + a1+ a0 (modulo-2)r1 = a3 + a2+ a1 (modulo-2)r2 = a1 + a0+ a3 (modulo-2)

Page 19: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst 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?

Page 20: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Hamming Codes• Detect a burst error

Page 21: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: 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

Page 22: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Implementation• Case of CRC with 4-bit dataword, 7-bit codeword

Page 23: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

CRC Encoder

Result of XOR

Page 24: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

CRC Decoder

The same divider as encoder

Corrupted bitsNon-corrupted bits

Page 25: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

Page 26: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

CRC Encoder using Shift Registers• Divisor = 1011

Page 27: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Polynomials• A pattern can be considered as coefficients of a

polynomial

• Adding and subtracting are done between the coefficients of the same power• Ex:

Page 28: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Division using Polynomials• Encoder

1011 =

= 1001

Page 29: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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)

Page 30: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

Page 31: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

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

Page 32: ERROR DETECTION AND CORRECTION. 10.1 Introduction Data can be corrupted Single-bit error: Burst error:

Checksum Procedure

One’s complement for

4-bit binary

9 = – 6 in one’s complement

representation

1 1 1 10 0 0 01 0 0 1