Presentation is loading. Please wait.

Presentation is loading. Please wait.

Error Detection and Correction

Similar presentations


Presentation on theme: "Error Detection and Correction"— Presentation transcript:

1 Error Detection and Correction
Parity and Hamming Code

2 Data Transmission and Interference

3 Causes of Electrical Interference

4 The Effect of Errors Hi Dave you’re the best. Hi Dove you’re the belt.
LDA #0 .loop INC CMP #10 BNE loop LDA #0 .loop DEC CMP #10 BNE loop USB Error rate 1 in 10,000,000,000 bits (this one might not quite be true!)

5 Parity Bits – The Solution
ASCII code characters only uses 7 of the 8 bits in a byte so the most signifcant bit (MSB) can be often used as a parity bit. Two systems: Odd parity – each byte should contain an odd number of ones. Even parity – each byte should contain an even number of ones. Example – sending an “S” character using even parity: ASCII code of “S” Receiver counts odd number of 1s, error detected! 1 1 Sender sets parity bit to 0 Interference changes bit

6 Parity Bit Exercise All these exercises assume an even parity system is in use. (1) Work out the parity bits for these two examples: 1 1 1 1 1 1 1 1 (2) Which of these bytes have been received correctly? 1 1 1 1 1 X 1 1 1 1 Q

7 Parity Bits – NOT The Solution
Receiver counts odd number of 1s, error detected! BUT which bit is wrong, and how can it be fixed? 1 1 Sender sets parity bit to 0 Interference changes bit Receiver counts even number of 1s, error NOT detected! 1 1 1 1 1 Most errors are burst errors so pretty useless. Interference changes 2 bits Sender sets parity bit to 0 No mechanism to detect errors with even number of bits or to correct any errors 

8 Hamming Codes – The Solution
Hamming codes make use of multiple parity bits to enable single bit error correction and two-bit error detection. HAMMING CODE = DATA BITS + PARITY BITS Within a Hamming code: Bits at positions that are powers of 2 are used as parity bits. Bits at other positions are used to store data bits. To transmit an 8-bit byte using Hamming code, 12 bits are required: Bits at positions 1, 2, 4, 8 are used as parity bits. Bits at other positions are used to store the data to send. This sounds more complex than just putting all of the parity bits at the end of the data bits, but it has a reason which we will see later. Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 The bits are usually labelled with letters and numbers to indicate their type (D for Data, P for Parity) and position within the bits of this type. e.g. “D5”

9 Hamming Codes – Bit Positions
Each parity bit is calculated based upon the values at certain positions within the Hamming code. The rule to determine which bits to include in the calculation of parity bit number x at bit position n is: Px: Skip n-1 bits from left, where n is the bit position of Px then include n bits in the check then miss out the next n bits and so on. For a 12-bit Hamming code the data bits checked by each parity bit are: KEY POINT: Each data bit is checked by a unique combination of parity bits. e.g. data bit D7 is checked by parity bits P1, P2 and P4 and not P3. Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 Included in P1: Included in P2: Included in P3: Included in P4:

10 Hamming Code - Transmission
Transmitting the byte : The data bits are copied into positions D8 down to D1. Each parity bit (P1 to P4) is calculated in turn, using even parity. The parity bits and data bits combine to make the Hamming code, so the Hamming code for is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is

11 Exercise: Transmission
Transmitting the byte : Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Original Data 2. Calculate P1 3. Calculate P2 4. Calculate P3 5. Calculate P4 Hamming Code Is The Hamming code for is Q

12 Hamming Code – No Error The Hamming code 001010011100 is received.
The parity bits are all recalculated from the data bits (recalculated parity bits shown in blue text): Each of the four recalculated parity bits (blue) match the received parity bits (red) so the Hamming code is valid. The received data value, read off from the data bits is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü

13 Hamming Code – 1 Bit Error
The Hamming code is transmitted but the code is received because interference has corrupted the bit at position 5, changing it from a 1 to a 0. The parity bits are all recalculated from the data bits (recalculated parity bits shown in blue text): Recalculated parity bits P3 and P1 at bit positions 4 and 1 do not match the received parity bits. An error has been successfully detected! Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü x

14 Hamming Code – Correction
Now the magic bit! The two parity bits with errors are P1 and P3. The only bit that is checked by both these parity bits and only these two parity bits is D2, so this is where the error is. This can be worked out more easily using the bit positions (this is why the parity bits weren’t all put at the end). The parity bits with errors are at bit positions 1 and 4. Add these two numbers together to give the answer 5, which is the bit position where the error is. Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü x

15 Hamming Code – Correction
Now we know the error is at bit position 5 which has been received as a 0. As the binary system is used, there are only two possible bit values (0 and 1) so if 0 is incorrect, 1 must be correct. Therefore the error can be corrected by simply NOTing the bit value at the error position: The data value received, after correction, is which is the value that was sent, despite the interference having occurred. Error corrected! Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü x 7. Calculate position of error Parity bits at bit positions 1 and 4 do not match so error position is 1+4=5 8. Flip error bit 9. Corrected code is

16 Exercise: Received Correctly?
The Hamming code is received, that appears to contain the data value What data value was transmitted? Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü x Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? x ü Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? x ü 7. Calculate position of error Parity bits at bit positions 1 and 8 do not match so error position is 1+8=9 8. Flip error bit 9. Corrected code is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? x ü 7. Calculate position of error Parity bits at bit positions 1 and 8 do not match so error position is 1+8=9 8. Flip error bit 9. Corrected code is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü x Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? x ü 7. Calculate position of error Parity bits at bit positions 1 and 8 do not match so error position is 1+8=9 8. Flip error bit 9. Corrected code is Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü x Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? ü x Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? x Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? x Q The data value that was transmitted is The transmission was corrupted but the original data value was recovered by error correction.

17 Hamming Code – 2 Bit Error
You won’t need to be able to do this for the exam but Hamming codes can also detect 2-bit errors, but cannot correct them: Hamming Code is transmitted but received as : Bit Position 12 11 10 9 8 7 6 5 4 3 2 1 Data/Parity D8 D7 D6 D5 P4 D4 D3 D2 P3 D1 P2 P1 1. Received Data 2. Recalculate P1 3. Recalculate P2 4. Recalculate P3 5. Recalculate P4 6. Do parity bits match? x ü 7. Calculate position of error Parity bits at positions 2,4 and 8 do not match so error at bit position 14 The calculated bit position of the error is 14, but there are only 12 bits. The error has been detected but cannot be corrected.

18 Comparing Parity and Hamming
A simple parity system with one parity bit can detect single bit errors but cannot correct them. The advantages of Hamming codes over a simple parity system are that they can correct a single bit error and can also detect 2-bit errors. The major disadvantage of Hamming codes is that some of the bandwidth of the transmission medium is used to send the parity bits. In our example, to send an 8-bit byte, 12 bits were required. So, one third of the bandwidth was used sending error correction data. For a communication channel with a bit rate of 600Mbit/second, this would effectively be slowed to 400Mbit/second.

19 For The Exam You need to:
be able to calculate parity bits using odd and even parity. know the role of the sending and receiving devices when a parity system is used. be able to calculate Hamming codes. be able to detect and correct an error using a Hamming code. know the advantages and disadvantages of Hamming codes when compared to a simple parity bit system. You don’t need to: know the causes of interference. know how to detect 2-bit errors.

20 A Bit More... Hamming codes and parity bits are typically used on small amounts of data e.g. single bytes. More advanced techniques such as cyclic redundancy checks and checksums are used on bigger blocks of data such as packets transmitted on networks and sectors saved on disks. These involve calculating a hash value from all of the data in the block – you can find out lots more about these online.


Download ppt "Error Detection and Correction"

Similar presentations


Ads by Google