190 likes | 207 Views
Learn how to apply Hamming distance, parity check, LRC, CRC in detecting and correcting errors in digital communication channels to ensure data integrity.
E N D
Practical Session 10 Error Detecting and Correcting Codes
Error detection and correction • communication channels are subject tochannel noise, and thus errors may be introduced during data transmission • we need techniques that enable reliable delivery of digital data over unreliable communication channels • detecting errors • reconstructing the original data
Error detection and correction • General idea: add some redundancy (i.e. some extra data) to a message • This extra data is used • to check consistency of the delivered message • to recover data determined to be corrupted
Hamming Distance • Hamming distance (d) between two code words of equal length is an amount of 1-bit changes required to reach from one word to the other • number of 1’s in the XOR between the words 000 011 d(000, 011) = 2 10101 11110 d(10101, 11110) = 3
Hamming Distance • Minimum Hamming distance is thesmallest Hamming distance between all possible pairs in a set of words. Example Given the following coding scheme, let’s find the minimum Hamming distance. 00000 01011 10101 11110 d(00000,01011)=3 d(00000,10101)=3 d(00000,11110)=4 d(01011,10101)=4 d(01011,11110)=3 d(10101,11110)=3 minimum Hamming distance is d=3
Hamming Distance - Error Detection Minimum Hamming Distance: d Can detect (at least)d-1 errors Example 00000 01011 10101 11110 d=3 3 errors can take us from one legal code word to another 00000 01000 01010 01011 01011
Hamming Distance - Erasures Fixing Minimum Hamming Distance: d Can fix (at least)d-1 erasures Example 00000 01011 10101 11110 d=3 3 erasures can take us from one legal code word to another 00000 0_000 0_0_0 0_0__ 01011
Hamming Distance - Error Correction Minimum Hamming Distance: d Can correct (at least) errors Example 00000 01011 10101 11110 d=3 00000 01000 01010 2 errors can take us from two different legal code words to the same illegal word 11110 01110
Hamming Distance - Example • Given fourdata words, can we use 5-bit code words for fixing1 error? • Answer: yes. We need a hamming distance d=3 to fix 1 error. We can create code words with independent graphs of a single error code words. d(00000,11100)=3 d(11100, 10111)=3 d(10111, 01011)=3 d(00000,10111)=4 d(11100, 01011)=4 d(00000,01011)=3
Parity Check • Given a data word, a code word is created by adding a parity bit to the end of the data word • d=2 (why?) • Can detect odd number of errors (1,3,5,…) 0001 1 1101 1 send: or 0011 1 receive: 1 or 3 errors occur
Longitudinal Redundancy Checking (LRC) • Adds an additional character called Block Check • Character (BCC) to a data word. • determine vertical and horizontal parity bits • Even parity calculated for each row (1 if number of ‘1’ bits is 1,3,5,7,…) • Odd parity calculated for each column (1 if number of ‘1’ bits is 0,2,4,6,…) • calculate BCC character • 1st bit of BCC number of 1’s in the 1st bit of characters • 2nd bit of BCC number of 1’s in the 2ndt bit of characters • … • 8’th bit of BCC number of 1’s in the parity bits column Example suppose a data word “DATA” Letter D A T A BCC ASCII 1000100 1000001 1010100 1000001 1101111 Parity bit 0 0 1 0 0 a code word is “DATA”11011111
Longitudinal Redundancy Checking (LRC) • Adds an additional character called Block Check • Character (BCC) to a data word. • d=2 (why?) Letter D A T A BCC ASCII 1000100 1000001 1010100 1000001 1101111 Parity bit 0 0 1 0 0 Letter D A T A BCC ASCII 1000101 1000001 1010101 1000001 1101111 Parity bit 1 0 0 0 0 2 errors occurred These two errors would not change BCC character
Cyclic Redundancy Check • CRC is an error-detecting code • Given a data, its non trivial (cryptographic) challenge to find another data with the same CRC code. CRC can protect data (even from deliberate damage)
Sending – Calculation Steps • Generatoris chosen • sequence of bits, of which the first and last are 1 • CRC check sequence is computed by long-division of message by generator • check sequence has 1 fewer bits than generator • Check sequence is appendedto the original message
Sending – Calculation Steps Compute 8-bit CRC a message ‘W’ (0x57). • Select Generator: CRC-8-ATM • x8 + x2 + x + 1 = 100000111 • ‘W’ is 01010111= x6 + x4 + x2 + x + 1 • Extend ‘W’ with 8 bits: 0101011100000000 • Perform XOR of the word get in step (3) by generator • CRC code is the remainder • Append CRC code to ‘W’
Generating CRC Codelong-division of message by generator 0101011100000000 100000111 Each time apply XOR on the extended message, when place a generator from the left-most ‘1’ bit of the extended message xor 100000111 001011011000000 xor 100000111 0011010110000 xor 100000111 01010101100 xor 100000111 0010100010 • Stop when CRC code has 1 fewer bits than generator CRC Code: 10100010
Receiving – Calculation Steps • Append CRC code to the message: 0101011110100010 • Perform long division by the generator • If the reminder is not 0: an error occurred 0101011110100010 100000111 xor 100000111 There is no errors in received message. result: 00000000