You are on page 1of 36

COMSATS Institute of Information Technology (CIIT), Abbottabad

Department of Electrical Engineering

EEE-354: Telecommunication
Systems Engineering

Lecture 4: Error Detection and Correction

© 2013-14 Khurram Aziz CIIT Department of Electrical Engineering EEE-354: Telecommunication Systems Engineering
What’s In This Lecture
• Channel coding
• Code rate and redundancy
• Effect of bit-errors
• Hamming distance
• Error detection and correction
• Error detecting and correcting codes
– Parity
– Rectangular
– Hamming
– Cyclic redundancy check (CRC)

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Channel Coding
• Signals transmitted over real-life channels are
prone to errors due to noise and interference
• Channel coding, also called error control coding, is
used to correct these errors
• In source coding, we remove (or reduce)
redundancy from the transmitted data
• On the contrary, a channel coder adds redundancy
to the transmitted data
• This redundancy is used to detect and correct
errors at the receiver

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Channel Coding
• Given:
– ‘k’ data bits
– ‘r’ redundant bits
– Total bits n = k + r
• Problem:
– Design a mapping from the original k-bit symbol to
an n-bit symbol that will allow detection and/or
correction of maximum number of errors

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Code Rate and Redundancy
• When a code transforms k bit data blocks into n bit blocks, it is
referred to as an (n,k) code
• The r = n–k bits added are called redundant, parity or check bits
• Ratio of redundant bits to data bits is called the redundancy of
the code
– Redundancy = (n–k)/k = r/k
• Ratio of data bits to total bits is called the code rate or coding
efficiency
– Code rate = k/n
• Ratio of total bits to data bits is called the bandwidth expansion
– Bandwidth expansion = n/k

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Error Detection
• Given k message bit, an error detection code is the
mapping or function that produces an n bit codeword
– The codeword contains k message bits and (n-k) parity bits
• The function is known at both the sender and the
receiver
• The sender appends the (n-k) parity bits to the
message (e.g., a packet)
• The receiver applies the same function to the message
– If the output of the function at the receiver matches the
parity bits contained in the codeword, there is no error
– Otherwise, an error is detected

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Error Detection

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Code Rate and Redundancy
• Example:
– What are the number of check bits, redundancy,
code-rate and bandwidth expansion of a (4,3) code

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Code Rate and Redundancy
• Example:
– What are the number of check bits, redundancy,
code-rate and bandwidth expansion of a (4,3) code
• Answer:
– Given, n=4 and k=3
– No. of check bits r = n – k = 1
– Redundancy = r/k = 1/3 = 33%
– Code rate = k/n = 3/4
– Bandwidth expansion = n/k = 4/3

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Effect of Bit-Errors
• Consider the following codewords 000, 001,
010 and 100.
– A single bit-error may transform one codeword into
another
– We are looking for a mapping in which one
codeword doesn’t get mapped to another codeword
due to a few-bit errors
– Larger the number of bit-errors required to
transform one codeword into another, the better
the code

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Effect of Bit-Errors
• If we want to transmit 2 bits (k=2) and you are
allowed to choose any two of the following
codewords which ones would you chose?
11010
01011
00101
11001

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Effect of Bit-Errors
• If we want to transmit 2 bits (k=2) and you are
allowed to choose any two of the following
codewords which ones would you chose?
11010
01011
00101
11001
– Codewords chosen would need to have all 5 bits
inverted, in order to transform from one to another

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Hamming Distance
• For better codes, we want a larger Hamming
distance between codewords
– Given two codewords, x and y, their Hamming
distance, d(x,y), is the number of bits that differ
between the two codewords
• Example:
– Hamming distance of the following codewords is 3
11010010
01001010

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Hamming Weight and Distance
• Hamming weight w(U) of a codeword U is the
number of non-zero elements in U
• Hamming distance between two codewords
d(U,V) is the number of elements in which they
differ
• Hamming distance between two codewords is
equal to the Hamming weight of their sums
d(U,V) = w(U+V)

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Hamming Weight and Distance
• For the codewords:
U = 11010110
V = 10110101
• Hamming distance = d(U,V) = 4
• (modulo-2) U+V = 01100011
– w(U+V) = 4
• Hence, d(U,V) = w(U+V)

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Types of Errors
• Single bit errors
– One bit is altered during transmission
– Adjacent bits are not affected
– Generally caused by white noise

• Burst errors
– Contiguous sequence of B bits in which first, last and any
number of intermediate bits in error
– Generally caused by impulse noise, interference and fading
in wireless channels
– Burst errors are more likely at higher data rates

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Error Detection
• Errors can be detected as long as they do not
change one codeword into another
• Hence, if dmin is the minimum distance between
any two codewords, the number of errors that
can be detected are dmin – 1
• Example:
– How many errors can be detected if the following
codewords are used: 0000 0011 1100 1111

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Error Detection
• Errors can be detected as long as they do not
change one codeword into another
• Hence, if dmin is the minimum distance between
any two codewords, the number of errors that
can be detected are dmin – 1
• Example:
– How many errors can be detected if the following
codewords are used: 0000 0011 1100 1111
– Answer: Minimum distance = 2
– Number of Errors that can be detected = 1
© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Minimum Distance Decoding (MDD)
• At the receiver, the channel decoder maps the received
vector to a valid codeword with which the vector has
the minimum Hamming distance
– In case of no error, the minimum Hamming distance will be
zero
• This is called minimum distance decoding (MDD)
• Example:
– Consider a received vector r and valid codewords w and x.
Will an MDD receiver map r to w or x?
r = 00101 w = 00000 x = 11111

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Minimum Distance Decoding (MDD)
• At the receiver, the channel decoder maps the received
vector to a valid codeword with which the vector has
the minimum Hamming distance
– In case of no error, the minimum Hamming distance will be
zero
• This is called minimum distance decoding (MDD)
• Example:
– Consider a received vector r and valid codewords w and x.
Will an MDD receiver map r to w or x?
r = 00101 w = 00000 x = 11111
– Answer: d(r,w) = 2, d(r,x) = 3, Hence r will be mapped to w

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Error Correction
• The codeword is decoded correctly only if the
number of errors are less than dmin/2
• A code with a minimum distance of dmin can correct
‘t’ errors as long as:
dmin = 2t + 1
• Example:
– How many errors can be detected and corrected if the
following codewords are used: 0000 1111
– Answer: Minimum distance = 4
– Number of errors that can be detected = 3
– Number of errors that can be corrected ≤ 1.5 i.e. 1 error

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Error Detecting and Correcting Codes
• Error detecting codes
– Parity
• Odd
• Even
– Cyclic Redundancy Check (CRC)
• Error correcting codes
– Rectangular parity
– Hamming codes

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Parity Codes
• Single parity check code (odd or even)
– Add a parity bit such that the total number of 1’s is odd
for odd parity, or even for even parity
Number of 1-bits Type of parity Added bit
Odd Odd 0
Even Odd 1
Odd Even 1
Example: Apply even parityEven
Even 0

Data Block: 1011011


Answer: 10110111

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Probability of Undetected Error
• Assuming all bit errors are equally likely, the probability
of j errors occurring in a block of n symbols is:

where:
p = Probability that a channel symbol is received in
error

Exercise: Determine the probability of a single bit error


in the previous example. Also determine the probability
of an undetected error. Assume p = 0.001

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Rectangular Codes
• Add parity check horizontally and vertically to
an M x N block of message bits
Example: Add odd parity
1 0 1 1 0 0 Horizontal parity
0 1 1 0 1 0
Data block
1 1 1 0 0 0

0 1 1 0 0 1
Vertical parity

1 0 1 0 0 0

Note: The corner check digit is the parity check for both the row and column of check digits
© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Rectangular Codes
Exercise: Previous example showed a message
block with M = 4 rows and N = 5 columns,
encoded with an odd parity rectangular code.
What is the redundancy and code rate of this
code? How many errors can the code correct?
Write an expression for the probability of an
uncorrected error (known as a message error
PM). Find the value of PM for p = 10-5

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Hamming Codes
• For a code to correct all single-bit errors, the minimum
distance between them should be 3
• Hamming codes can be characterized by the structure:

• The relationship between data and redundancy bits is


given by the relation:

• Redundancy bits r1, r2, r4, … will use parity as follows:


r1 1, 3, 5, 7, …
r2 2, 3, 6, 7, …
r4 4, 5, 6, 7, …
© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Hamming Code
Example: When 3 redundant bits are used, what is the
maximum data length that Hamming code can be
applied to. What is the output when Hamming code
is applied to the bit stream 1011.
Answer: 4 data bits
1 0 1 0 1 0 1 data
d d d r4 d r2 r1
7 6 5 4 3 2 1 bit position

Output: 1010101

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Hamming Code
Exercise: If the received bit stream is 1011101, show
how Hamming code will correct this

Exercise: Find the output for the bit-stream 1001011


if Hamming code is used. If the 7th bit of the
received code is in error, show that it will be
detected

Note: Hamming codes with a distance ‘d’ can detect


all ‘d-1’ errors and correct all ‘(d-1)/2’ errors

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
Cyclic Redundancy Check
• At transmitter
– Left-shift data polynomial by (n–k) bits
– Divide by a generator polynomial using modulo-2
division
– Discard the quotient and append the remainder to
the data
• At receiver
– Divide received bit-stream polynomial with the
generator polynomial, modulo-2
– Error in the received bit-stream if remainder is not 0

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
CRC Example

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
CRC Example
• Available data
– Message M: 1010001101 – (10 bits)
– Generator polynomial P: 110101 – (6 bits)
– Frame check seq. (FCS) F: ?

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
CRC Example
• Available data
– Message M: 1010001101 – (10 bits)
– Generator polynomial P: 110101 – (6 bits)
– Frame check seq. (FCS) F: ? – (5 bits)
• Results:
– Quotient: 1101010110 – Discard
– Remainder R: 01110
– Append to M : 101000110101110 and transmit
– Check: Divide 101000110101110 by 110101.
Remainder should be 0
• Exercise: Introduce error(s) in the bit stream and
recalculate. Remainder should not be 0

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
CRC Polynomials
• CRC polynomial properties:
– It should not be divisible by x
– It should be divisible by x+1
• Some widely used polynomials:
– CRC-12: x12 + x11 + x3 + x2 + x + 1
– CRC-16: x16 + x15 + x2 + 1
or x16 + x12 + x5 + 1 (CCITT)
– CRC-32: x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8
+ x7 + x5 + x4 + x2 + x + 1

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
CRC Polynomial Error Detection
• Errors will not be detected if they are divisible by the
generator polynomial P
• Following errors can be detected:
– All single-bit errors, if P has more than one non-zero term
– All double-bit errors, as long as P has a factor with three
terms
– Any odd number of errors, as long as P has x+1 as a factor
– Any burst error for which the length of the burst is less than
or equal to the length of the FCS F (or n–k)
– 1–2 –(n–k–1) error bursts of length n–k+1
– 1–2 –(n–k) error bursts of length greater than n–k+1

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks
References and Further Reading
• A. S. Tanenbaum, “Computer Networks”, 4th edition, Section 3.2
• W. Stallings, “Data & Computer Communications”, 7th edition,
Section 6.3
• B. Forouzan, “Data Communications & Networking”, 3rd edition,
Section 10.3
• B. Sklar, “Digital Communications – Fundamentals and
Applications”, 2nd edition, Section 6.3, 6.4

© 2011 Khurram Aziz Department of EE, CIIT Abbottabad EEE-314: Data Communication & Computer
Networks

You might also like