0% found this document useful (0 votes)
77 views27 pages

Error Detection and Correction

The document discusses error detection and correction techniques. It introduces parity, which can detect single bit errors but not locate them. Cyclic redundancy checks (CRCs) provide more robust error detection by using polynomial arithmetic. Hamming codes add redundant check bits to words to allow for both error detection and correction. The minimum Hamming distance of a code determines its error detecting and correcting capabilities.

Uploaded by

iole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views27 pages

Error Detection and Correction

The document discusses error detection and correction techniques. It introduces parity, which can detect single bit errors but not locate them. Cyclic redundancy checks (CRCs) provide more robust error detection by using polynomial arithmetic. Hamming codes add redundant check bits to words to allow for both error detection and correction. The minimum Hamming distance of a code determines its error detecting and correcting capabilities.

Uploaded by

iole
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

Chapter 2.

7
Error Detection and
Correction
2.7 Error Detection and Correction
• It is physically impossible for any data recording or transmission
medium to be 100% perfect 100% of the time over its entire
expected useful life.
• As more bits are packed onto a square centimeter of disk storage,
as communications transmission speeds increase, the likelihood of
error inevitably increases.
• Thus, error detection and correction is critical to accurate data
transmission, storage and retrieval.
• Check digits, appended to the end of a long number, can provide
some protection against data input errors.
– The last characters of ISBNs and UP student numbers are check digits.

more packed 1 cramped systems are the


more
errors occur
2
2.7 Parity

• The simplest error detection method is that of parity.


– Given a bit string of length N
• We rather transmit a string of length N+1
• The highest order bit, the parity bit, is used to store additional
information about the lower order bit.
– Two options
• Odd parity:
• If the number of 1’s in the N-bits is odd then the parity bit is 0, else 1
• Even Parity:
• If the number of 1’s in the N-bits is even then the parity bit is 0, else 1

3
2.7 Parity

• Assume even parity is being used: do


• Original string: 111 0101 yoodd
– # of 1’s is odd so parity bit is 1
want

I
• Sent string is: 1111 0101
– Observe that the number of 1’s are now even.

what
mould odd d
do if
agro
aol.ua wanna i
paries
Ol t
wer od
4
2.7 Parity

• While the use of a parity bit is simple it has two major


issues:
– It can only usually detect at most 1 error!
– It only tells that an error occurred, not where the
error occurred. Le

5
2.7.1 Cyclic Redundancy Check
once
again doesn't say
where just
that
• A cyclic redundancy check (CRC) is a type of checksum that is used
in error detection for large blocks of data.
• Checksums and CRCs are examples of systematic error detection.
• In systematic error detection a group of error control bits is
appended to the end of the block of transmitted data.
– This group of bits is called a syndrome.
– Original information is unchanged by the addition of the error-checking
bits.
• CRCs use polynomials over the modulo 2 arithmetic field.

The mathematical theory behind modulo 2 polynomials is


beyond our scope. However, we can easily work with it
without knowing its theoretical underpinnings.

6
2.7.1 Cyclic Redundancy Check
• Modulo 2 arithmetic works like clock arithmetic. wrap aroad
• In clock arithmetic, if we add 2 hours to 11:00, we get 1:00. 12 D l
• In modulo 2 arithmetic if we add 1 to 1, we get 0. The addition
rules couldn’t be simpler:

0+0=0 0+1=1 t

f
1+0=1 1+1=0

• Example: Find the sum of 10112 and 1102 modulo 2. subtract


1011
0 1 1 0 +( mod 2)
---------
fpyiejd.se
1101
aka bit
7 Lp modulo 2
Fy
2.7.1 Cyclic Redundancy Check

• Example: Find the quotient


and remainder when 1111101
is divided by 1101 in modulo 2
arithmetic.
– As with traditional division, we
o
note that the dividend is divisible
once by the divisor.
– We place the divisor under the
dividend and perform modulo 2
subtraction.

8
2.7.1 Cyclic Redundancy Check

• Find the quotient and remainder


when 1111101 is divided by
1101 in modulo 2 arithmetic… i
– Now we bring down the next bit
of the dividend.
0
– We see that 00101 is not divisible
II
b
by 1101. So we place a zero in I
the quotient.

9
2.7.1 Cyclic Redundancy Check

• Find the quotient and remainder Quotient


when 1111101 is divided by
1101 in modulo 2 arithmetic…
– 1010 is divisible by 1101 in
modulo 2.
– We perform the modulo 2
subtraction.

10
2.7.1 Cyclic Redundancy Check

• Find the quotient and remainder


when 1111101 is divided by
1101 in modulo 2 arithmetic…
– We find the quotient is 1011, and
the remainder is 0010.
• This procedure is very useful to
us in calculating CRC
syndromes.

O
Note: The divisor in this example corresponds T ede
to a modulo 2 polynomial: X 3 + X 2 + 1. Renninger
ht
11 ie
2.7.1 Cyclic Redundancy Check
• How do we use this to perform error detection? no
• Both parties decide on a CRC-Polynomial ( ) sonar ur
• The algorithm is then as follows for sender: enodbi n
– 1) Given a information block , Left shift | | 1 bits.
– 2) Perform modulo 2 division of by
string
• Find the remainder,
– 3) Set = + (normal binary addition)
• The algorithm is the as follows for a receiver
– 1) Receive
– 2) Perform modulo 2 division of by
– 3) If = 0 then transmission was successful
– 4) Else there was an error.

Is T.EE
bragiii
12
2.7.1 Cyclic Redundancy Check
(example) ffYidnpa
infostrinos
• = 1001011 and = 1011
i
cigar.cat wow
bits
• = 3 = 1001011000 IN I shift
• Module 2 divide by
– = 1010100 and = 100 (check at home)
• = + R= 1001011100
• Transmit.
– Then if Module 2 divide by results in =
0, transmission successful.
– If 0 at least 1 bit error occurred.

13
2.7.1 Cyclic Redundancy Check

• Questions to think about


– If P=11, how does CRC relate to parity?

14
2.7 Error Detection and Correction
e correction
• Data transmission errors are easy to fix once an error is detected.
– Just ask the sender to transmit the data again.
• In computer memory and data storage, however, this cannot be done.
– Too often the only copy of something important is in memory or on disk.
• Thus, to provide data integrity over the long term, error correcting
codes are required.
– We want to be able to detect and correct.

• Hamming codes and Reed-Solomon codes are two important error


correcting codes. meh

15
2.7.2 Hamming Codes
• Hamming codes are code words formed by adding redundant check
bits, or parity bits, to a data word.
• The memory word itself consists of m bits, but r redundant bits are
added to allow for error detection and/or correction.
• The Hamming distance between two code words is the number of bits
in which two code words differ (3 in example). only diff nodes

• The minimum Hamming distance for a code is the smallest Hamming


distance between all pairs of words in the code.
• Example:
– Assume memory with 2 data bits and 1 parity bit (appended at the end)
that uses even parity (number of 1s in code word must be even).
– Possible words in the code: 000, 011, 101, 110 (other possible bit
patterns are invalid).
Tm
– What is the minimum Hamming distance for this code? i
16
i

2.7.2 Hamming Codes


• The minimum Hamming distance for a code, D(min), determines
its error detecting and error correcting capability.
• For a single-parity bit code:
– Only single-bit errors can be detected, because D(min) is 2 (two bit
errors can convert a valid code into another valid code).
• In general (for detection):
– For any code word, X, to be interpreted as a different valid code
word, Y, at least D(min) single-bit errors must occur in X.
– Thus, to detect k (or fewer) single-bit errors, the code must have a
Hamming distance of D(min) = k + 1.
– Conversely, Hamming codes can always detect D(min) – 1 errors.
• For correction: rounded down

– Hamming codes can correct errors. 2u D


– Or, the Hamming distance of a code must be at least 2k + 1 for it to
be able to correct k errors.
17
Even with k errors, the word will still be closest to the original word.
sina.io
a
Example 2.41
• Suppose we have the following code:
00000
01011
D
10110
11101 check all
ifthis
• What is D(min)? difference happens

vectors Inmon
– Answer: D(min) = 3 it is
invalid
because
• How many single-bit errors can be detected? minimal
– Answer: up to 2 single-bit errors DCmin 1 distanceis

• How many single-bit errors can be corrected?


– Answer: 1 single-bit errors can be corrected
• What is the correct code of the invalid code word 10000?
– Difference vector to all code words: [1, 4, 2, 3], so correction is 00000
(closest code word). Assumption: the minimum number of possible errors
has occurred. Correction might not be correct! minimal a80000
humming
• What is the correct code of the invalid code word 11000?
18
0 O
Distance vector: [2, 3, 3, 2]. Cannot make the correction.
L_equally be
2.7.2 Hamming Codes
Single bit correction
• Suppose we have a set of n-bit code words consisting of m data
bits and r (redundant) check bits. 0
• How many legal code words?
– Answer: 2m not Walid
Taka
• How many illegal code words at a Hamming distance of 1 from
each valid code word (i.e. bit strings with single-bit errors)?
– Answer: n (an error can occur in any of the n bit positions)
• How many total bit patterns (valid and invalid) possible?
• Answer: 2n or 2(m+r)
• For each valid codeword, we have (n+1) bit patterns (1 legal and
n illegal). This gives us the inequality:
(n + 1) 2m 2 n

invalidcodewords eachvalid code word


19
distant
n
2.7.2 Hamming Codes
• From previous slide:
(n + 1) 2 m 2 n
• Because n = m + r, we can rewrite the inequality as:
(m + r + 1) 2 m 2 m + r
or (m + r + 1) 2 r
• This inequality gives us a lower limit on the number of check bits
that we need to construct a code with m data bits and r check bits
that corrects all single-bit errors.
• For example, say we have data words of length 4. What is the
minimum number of check bits needed for correcting single-bit
errors?
4 21 1 7 5 4
(4 + r + 1) 2 r
41 91 1 8
r must be greater than or equal to 3. 23 8
• We should always use the smallest value of r that makes the
inequality true.

20
2.8 Error Detection and Correction
• For example, say we have data words of length 8. What is the
minimum number of check bits needed for correcting single-bit
errors?
(8 + r + 1) 2 r 8 41 1 13 E 29 Elf
r must be greater than or equal to 4.
• How long will the resulting code words be?
Answer: 12
• So how do we assign values to check bits so that we can
achieve detection and correction?

21
The Hamming Algorithm
1. Determine the number of check bits, r, necessary for the code
and then number the n bits, right to left, starting with 1 (not 0).
2. Each bit whose bit number is a power of 2 is a parity bit
(positions 1,2,4,8,etc) and the others are data bits (positions
3,5,7,9,10,etc).
3. Each parity bit calculates the parity of some of the bits in the
code word. The position of the parity bit determines the
sequence of bits that it alternately checks and skips:
Position 1: check 1 bit, skip 1 bit, check 1 bit, skip 1 bit, etc. (1, 3, 5, 7, 9, …)
Position 2: check 2 bits, skip 2 bits, check 2 bits, etc. (2,3,6,7,10,11,…)
Position 4: check 4 bits, skip 4 bits, check 4 bits, etc. (4,5,6,7,12,13,14,15,20,...)
…and so on.
4. Set each parity bit to 1 if the number of 1’s in the positions it
checks is odd, or to 0 if the number of 1’s in the position it
checks is even (even parity).

22
2.7.2 Hamming Codes
• Consider the example with words of length 4, with 3 check bits.
• Code words will be of length 7 (white cells are data and green cells
are parity bits):

7 6 5 4 3 2 1
– The set of bits using parity bit 1: 1, 3, 5, 7 (check 1, skip 1, …)
– The set of bits using parity bit 2: 2, 3, 6, 7 (check 2, skip 2, …)
– The set of bits using parity bit 4: 4, 5, 6, 7 (check 4)

1 Notice that the parity bits (1, 2, 4) are


each only in one set.
3
5 Bit position 7 is in all three sets.
7 2 Using this system, if a bit changes, it
6 can be deduced which one changed.
4
23
2.7.2 Hamming Codes
• Example: Determine the Hamming code word for 4-bit data 1101.
• Code words will be of length 7 (white cells are data and green cells
are parity bits):
1 1 0 1
7 6 5 4 3 2 1
– The set of bits using parity bit 1: 1, 3, 5, 7 (check 1, skip 1, …)
– The set of bits using parity bit 2: 2, 3, 6, 7 (check 2, skip 2, …)
– The set of bits using parity bit 4: 4, 5, 6, 7 (check 4)
• Determine the parity bit values: 1
– Parity bit 1: value is set to 0 (since 3=1, 5=0, 7=1) 3
– Parity bit 2: value is set to 1 (since 3=1, 6=1, 7=1) 5 7
– Parity bit 4: value is set to 0 (since 5=0, 6=1, 7=1) 2
• Hamming code word: 1100110 4 6
• How to determine where an error occurred?
– Add the positions of parity bits that produce the error!
24
2.7.2 Hamming Codes
• What is the Hamming code of data word 1101 0110?
• Data word of length 8 requires 4 parity bits.
• Which will be the check (parity) bits?

• What is the full Hamming code?

25
2.7.2 Hamming Codes Akel bit 5

7
we art even
WAS
the
r
• There is an error in the code word above. Correct it.
– Bit 1 checks 1, 3, 5, 7, 9, and 11. (1,0,0,0,1,1)
• This is incorrect as we have a total of 3 ones (which is not even parity). correct

– Bit 2 checks bits 2, 3, 6, 7, 10, and 11. (0,0,1,0,0,1)


1 • The parity is correct.
know the e aint an error the
– Bit 4 checks bits 4, 5, 6, 7, and 12. (1,0,1,0,1)
error
4 • This parity is incorrect, as we 3 ones.
– Bit 8 checks bit 8, 9, 10, 11, and 12. (1,1,0,1,1)
It • This parity is correct.

S – The common elements in the two sets are 5 and 7, but 7 is part
of bit 2 check, so cannot be the problem.
can
also – Therefore, the bit that changed was 5, so flip the bit in position 5.
do 26 – Alternatively, simply add 1 + 4 = 5, and flip bit 5.
does
e
where we cannot make a correction

You might also like