CS485 Sylabus

### Error Detection and Correction at the Physical Layer

• Errors at the Physcial Layer:

• Common causes of transmission errors:

 Noise: this will usually cause single bit errors Weather condition (storm): a thunder bolt will usually cause multiple consecutive bit errors

• Error rate due to noise:

 The likelihood of errors due to noise depends on the transmission medium Twisted pairs is pretty "noisy" and has an error rate of about 1 bit in every few 1000 bits transmitted. Optical fibers are very "noiseless" and can have 1 bit in several 1,000,000 bits may be in error....

• Why detect errors

 Garbage in, garbage out: processing corrupted intermediate data will always result in incorrect final outcome The sooner we can detect an error, the less computation resources we will waste Transmission errors can be detected at various levels

• Question we study here:

 How can we tell if there are errors at the physical (signal) level ?

• Detecting errors at physical level (signals): error detection and correction codes

• Principe to detect/correct errors in a "sequence of bits":

 Embed extra bits into the transmitted message to conforms to a certain (mathematical) property The receiver checks for this property in the received sequence The mathematical theory that deal with this subject is called coding theory.

• Commonly used error detection/correction schemes

• Commonly used schemes:

• Error detection schemes:

 Parity checks Cyclic Redundancy Check (CRC)

• Error Correction Schemes:

 Hamming's code (can correct 1 bit error) Solomon-Reed's code (can correct 2 bit error)

• One-dimensional Parity Scheme

• Even and Odd Parity:

• Even parity:

 Add one extra bit to the message so that the total number of 1's in the message is always even

• Odd parity:

 Add one extra bit to the message so that the total number of 1's in the message is always odd

• Examples:

 ``` Transmitted data (unprotected): 1111000 1010101 1111111 Even parity: 11110000 10101010 11111111 Odd parity: 11110001 10101011 11111110 ```

• Error Checking:

 When the received message does not have an even (or odd number of 1's in the even (or odd) parity method, the receiver will assume that the message is corrupted

• Properties:

• Parity checks can detect all odd number of bit errors

• Parity checks can not detect even number of bit errors

Example:

 ``` Transmitted data (unprotected): 1111000 Even parity: 11110000 Received with 2 errors: 11010100 ===> 2 errors results in even parity !!! (error cannot be detected) ```

• Two-dimensional parity

• Two-dim Parity = Generalization of the simple (one-dim) parity scheme:

 Form an MxN matrix of bits, then Add a (even or odd) parity bit to each row and to each column

• Example:

 ``` Transmitted data (unprotected): 1111000 1010101 1111111 Two dimensional (even) parity: 11110000 10101010 11111111 10100101 ```

• Properties:

• Two-dimensional parity scheme can correct all 1 bit errors

Example:

 ``` Transmitted data: 11110000 10101010 11111111 10100101 Received one bit in error: 11110000 10101010 11011111 <---- odd parity 10100101 ^ | odd parity ```

In the example, the receiver can take the initiative and correct (change) the received message !

• Two-dimensional parity scheme can detect all 2 bit errors but cannot correct the error

Example:

 ``` Transmitted data: 11110000 10101010 11111111 10100101 Received one bit in error: 11110000 10111010 <---- odd parity 11011111 <---- odd parity 10100101 ^^ || odd parity ```

The errors can be detected.

But the receiver cannot correct the error because of ambiguity:

 ``` Transmitted data: 11110000 10011010 11111111 10100101 Received one bit in error: 11110000 10111010 <---- odd parity 11101111 <---- odd parity 10100101 ^^ || odd parity ```

The receiver cannot tell which of these 2 cases is actually happening....

• A Famous Error Correction codes: The Hamming Code

• Hamming Code:

• Hamming code is a linear error-correcting code named after its inventor, Richard Hamming.

• The Hamming code can:

 Detect and correct all 1 bit errors Detect most 2 bit errors, but does not detect all 2 bit errors

• Also: It uses a minimum number of extra bits to achieve these properties

• Encoding procedure: by example

1. Insert extra bit positions at locations: 20, 21, 22, ..., 2k

Stop inserting when there are no data bits prior to the 2k+1 position

Example: 101010

The data bits are copied into the positions from right to left, but skipping over the inserted positions

2. Compute the values of the bits at the inserted positions by:

 Converting the index of the 1 bit locations into a binary number Perform the XOR operations on all resulting binary numbers

Example:

3. Distribute the computed (check) code into the inserted bit positions

Example:

• Summary (of the above):

 If the sender wants to transmit 101010 using Hamming Code,              it will transmit: 1011010000

• Decoding a Hamming coded message

• Checking the correctness of a received message:

• Converting the index of the 1 bit locations into a binary number

• Perform the XOR operations on all resulting binary numbers

• If the result = 0 then the messages (most likely) contains no error

 The decoded message consists of the received bits minus the bits at at positions: 20, 21, 22, ..., 2k

• If the result <= length of the message then the messages (most likely) contains 1 error

 Change the value of the bit at the position given by "result" (computed above) The decoded message consists of the received bits minus the bits at at positions: 20, 21, 22, ..., 2k

• If the result > length of the message then the messages (most likely) contains multiple errors

 The receiver cannot perform correction It will reject the message as corrupted

• Example: 101010

From the discussion above:

we know that the sender will transmit: 1011010000

Case 1: no error in message

Received message = 1011010000

Decode:

Case 2: one error in message

Received message = 1010010000

Decode:

Case 3: detectable two bits error in message

Received message = 1110010000

Decode:

Case 4: undetectable two bits error in message

Received message = 1010110000

Decode:

• Better error detection codes

• Facts:

• Detecting an error is much easier than correcting the error

• In most communications, the sender can retransmit a message if so requested

(Some communications where that is not possible are: space missions where pictures are sent back to earth for analysis)

• The most commonly used error detection code in use today are the

 Cyclic Redundancy Check (CRC) codes.

CRCs are popular because they are simple to implement in hardware, and are very good at detecting common errors caused by noise in transmission channels.

• The CRC method is also known as

 polynomial code checksum

When people use the term "check sum" in a message, the check "sum" is most likely computed with the CRC procedure

• Cyclic Redundancy Check (CRC) codes

• Protecting a message with CRC codes:

• Sender and receiver must use the same generator polynomial to encode and decode messages.

• The CRC code computed on the transmitted message and is appended to the end of a message:

 ``` Original message: xxxxxxxxxxxxxxxxxx Protected message: xxxxxxxxxxxxxxxxxxccccc <---> CRC ```

• The length of the CRC code depends on the length of the generator polynomial of the code.

• The CRC encoding procedure:

 Let N = length of the generator polynomial Append N-1 ZERO's to the end of the message. Divide the messages + (N-1) ZEROs by the generator polynomial.              Use XOR operation as the subtract operation in the division Append the remainder of the division to the original message The resulting message is the CRC protected message

• Example computing the CRC:

 ``` Generator polynomial: 1101 (Math. notation: 1×x3 + 1×x2 + 0×x1 + + 1×x0) N = 4 (Generator polynomial has 4 terms, or bits in "1001") Sample message: 10001 1. Message + 3 (=(N-1)) ZEROs = 10001000 2. Compute CRC by dividing "message + 3 zeros" by generator polynomial: 00011 ---------------- 1101 / 10001000 1101 <----- 1000 < 1101 ---- (XOR) 1011 1101 ---- (XOR) 1100 1101 ---- (XOR) 000100 <---- remainder = 100 CRC = 100 3. Encoded message = 10001100 ```

• NOTE:

• The division uses the XOR operation as subtraction

• You can divide when the divided number contain N digits and the leading digit = 1

Example:

 ``` 1 ------------ 1101 / 10001000 1101 ----- 0101 ```

• Decoding a CRC protected message

• Checking for error:

• The entire received message is divided by the generator polynomial

(Using the same division process as in the encoding step)

NOTE: do not add N+1 zeros to the received message in the decode step

• If the remainder of the dvision is equal to ZERO, the received message is most likely correct

• Otherwise, the received message is most likely corrupted

 Receiver will reject messages that are likely to be corrupted (And will ask for retransmission - but that is discussed later when we talk about the data link layer)

• CRC Decoding Example 1: no error

 ``` Generator polynomial: 1101 (Math. notation: 1×x3 + 1×x2 + 0×x1 + + 1×x0) N = 4 (Generator polynomial has 4 terms, or bits in "1001") 1. Received message = 10001100 2. Check CRC by dividing "received message" by generator polynomial: 00011 ---------------- 1101 / 10001100 1101 ---- (XOR) 1011 1101 ---- (XOR) 1101 1101 ---- (XOR) 000000 <---- remainder = 000 3. Received message is likely to be correct Actual message = 10001 (removed CRC) ```

• CRC Decoding Example 2: two bits error

 ``` Generator polynomial: 1101 (Math. notation: 1×x3 + 1×x2 + 0×x1 + + 1×x0) N = 4 (Generator polynomial has 4 terms, or bits in "1001") 1. Received message = 11101100 2. Check CRC by dividing "received message" by generator polynomial: 00011 ---------------- 1101 / 11101100 1101 ---- (XOR) 01111 1101 ---- (XOR) 1000 1101 ---- (XOR) 0101 <---- remainder = 101 3. Received message is likely to be corrupted Reject the message ! ```

• Designing CRC polynomials

• There is a rich Mathematical theory on how to design CRC polynomials with desirable properties

• Some desirable properties:

• CRC code can detect all errors affecting an odd number of bits.

This is the Parity property

(A generator polynomial containing the factor "x+1" can detect all errors affecting an odd number of bits)

• Another well-know property:

 A generator polynomial containing an primitive polynomial of degree r-1 can generate CRC code that will detect k consecutive bit errors where k ≤ r.

• Designing CRC polynomial is a highly Mathematical topic and it is outside the scope of this course....

• Commonly used (international standard) generator polynomials

• Some commonly used CRC generator polynomials:

Name Generator polynomial
CRC-CCITT 10001000000100001
CRC-16 11000000000000101
CRC-32 100000100110000010001110110110111

• NOTE:

• A well-formed CRC generator polynomial always has the property that:

 the first bit = 1 and            last bit = 1

• Hardware CRC implementation

• Circuit construction for any CRC generator polynomial:

• Use (N-1) D-flipflops (memory elements) to store the remainder of the division.

(Recall that N = length of the generator polynomial)

• Put the (N-1) Dffs in a row.

Connect the output of the ith Dff to the input of the i+1th Dff

• The input of the first Dff will receive the bits in the received message

• Read the CRC generator polynomial in the reverse order.

For bit i in the (reversed ordered) CRC generator polynomial:

• if bit i = 1 bit is 1, then:

 add an XOR gate before the ith Dff and Send the output of the last Dff as the second input to the ith Dff             (I.e., the output of the last Dff is fed back into the ith Dff)

• Example: circuit for generator polynomial 1001

• N = 4

Put the 3 Dffs in a row.

Connect the output of the ith Dff to the input of the i+1th Dff:

• Add feed backs:

Quick example: generator polynomial = 1101

Circuit:

• How does the circuit computes the CRC code for a message:

 Reset all the Dffs (memory elements) to ZERO Present the first bit of the message Give the Dff a clock signal Present the second bit of the message Give the Dff a clock signal And so on, untill all bits in the message are processed Present (N-1) ZEROs to the circuit and give the Dff a clock signal for each bit. Now the output of the Dff from right to left, is the remainder of the division !!!

• Example Program: (Circuit for generator polynomial 1101)

How to use it:

 Run: logic-sim   CRC1.logic-sim Make 2:Clr = 1 (filled) to run circuit Toggle 0:Input to the next bit in input Press 1:Clk to give circuit a clock signal.

This is a logic-sim program from my CS355 class...