0% found this document useful (0 votes)
22 views34 pages

Lab 4 - Error Detection and Correction

Uploaded by

attaurr.mca25
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)
22 views34 pages

Lab 4 - Error Detection and Correction

Uploaded by

attaurr.mca25
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/ 34

An Introduction to Error

Detection and Correction


Code
LAB – 4,
MCA, NIT PATNA
Data can be corrupted during transmission. Some applications require
that errors be detected and corrected.

Many communication channels are subject to noise, and thus errors may
be introduced during transmission from the source to a receiver. There
are many reasons such as noise, cross-talk etc.

The upper layers of the OSI model are not much aware of actual
hardware data processing. Hence, the upper layers expect error-free
transmission between the systems.

Datalink Layer uses some error control mechanism to ensure that frames
(data bit streams) are transmitted with certain level of accuracy.
Error detection techniques allow detecting such errors, while
error correction enables reconstruction of the original data in
many cases.

• In error detection, we are only looking to see if any error has


occurred.

• In error correction, we need to know the exact number of bits


that are corrupted as well as their location in the message.
Types of Errors
In a single-bit error, only 1 bit in the data unit has changed.

The term burst error means that 2 or more bits in the data unit have
changed.
Redundancy
❑ The central concept in detecting or correcting errors is redundancy.
❑ To be able to detect or correct errors, we need to send some extra bits
with our data.
❑ These redundant bits are added by the sender and removed by the
receiver.
❑ Their presence allows the receiver to detect or correct corrupted bits.
❑ Redundancy is achieved through various coding schemes.
Block Coding
❑ In block coding, we divide our message into blocks, each of k bits, called
datawords.
❑ We add r redundant bits to each block to make the length n = k + r. The
resulting n-bit blocks are called codewords.
Errors can be detected using block coding if two conditions are met:
o The receiver has a list of valid codewords.
o The original codeword has changed to an invalid one.

Let us assume that k = 2 and n = 3.


Table below shows the list of data words and codewords.
Assume the sender encodes the dataword 01 as 011 and sends it to the receiver.
Consider the following cases:

1. The receiver receives 011.


o It is a valid codeword. The receiver extracts the dataword 01 from it.

2. The codeword is corrupted during transmission, and 111 is received.


o This is not a valid codeword and is discarded.

3. The codeword is corrupted during transmission, and 000 is received.


o This is a valid codeword.
o The receiver incorrectly extracts the dataword 00.
o Two corrupted bits have made the error undetectable.
Error Detection
Hamming Distance
o One of the central concepts in coding for error control is the idea of
Hamming distance.
◦ The Hamming distance between two words (of the same size) is the number
of differences between corresponding bits.

o Why is it important?
The Hamming distance between the received codeword and the sent
codeword is the number of bits that are corrupted during transmission.

If the Hamming distance between the sent and received codeword is not
zero, the codeword has been corrupted during transmission.
The Hamming distance can easily be found if we apply the XOR operation
on the two words and count the number of 1s in the result. Note that the
Hamming distance is a value greater than or equal to zero.
Minimum Hamming Distance
o Given a set of codewords, the minimum hamming distance is the smallest Hamming
distance between all possible pairs of codewords.
o If we want to detect up to ‘s’ errors, we need to find minimum hamming distance.
o If ‘s’ errors occur during transmission, the hamming distance between sent and
received codeword is ‘s’.

To guarantee the detection of up to s errors in all cases, the minimum


Hamming distance in a block code must be dmin = s + 1 so that the
received codeword does not match a valid codeword.
Example C1=000,C2=011,C3=110
The minimum Hamming distance for our first code scheme is 2. This code
guarantees detection of only a single error. For example, if the third codeword (101)
is sent and one error occurs, the received codeword does not match any valid
codeword. If two errors occur, however, the received codeword may match a valid
codeword and the errors are not detected.
Simple parity-check code
o A linear block code is a code in which the exclusive OR of two valid
codewords creates another valid codeword.
o Parity-check code is a linear block code and is the most familiar error
detecting code.
o A simple parity-check code is a single-bit error-detecting code in which
n = k + 1 with dmin = 2.
o Even parity (ensures that a codeword has an even number of 1’s) and
odd parity (ensures that there are an odd number of 1’s in the codeword).
o A simple parity-check code can detect an odd number of errors.
Parity bits
A parity bit is a bit appended to a data of binary bits to ensure that the total number of
1’s in the data is even or odd. Parity bits are used for error detection. There are two types
of parity bits:
Even parity bit:
In the case of even parity, for a given set of bits, the number of 1’s are counted. If that
count is odd, the parity bit value is set to 1, making the total count of occurrences of 1’s
an even number. If the total number of 1’s in a given set of bits is already even, the
parity bit’s value is 0.
Odd Parity bit –
In the case of odd parity, for a given set of bits, the number of 1’s are counted. If that
count is even, the parity bit value is set to 1, making the total count of occurrences of 1’s
an odd number. If the total number of 1’s in a given set of bits is already odd, the parity
bit’s value is 0.
Hamming Code
In this coding method, the source encodes the message by inserting redundant bits
within the message. These redundant bits are extra bits that are generated and inserted
at specific positions in the message itself to enable error detection and correction. When
the destination receives this message, it performs recalculations to detect errors and find
the bit position that has error.

Step 1: Calculation of the number of redundant bits


2r ≥ m + r + 1 where m is the number of data bits and r is the number of redundant bits.
Step 2: Positioning the redundant bits
The r redundant bits placed at bit positions of powers of 2, i.e. 1, 2, 4, 8, 16 etc. They are
referred in the rest of this text as r1 (at position 1), r2 (at position 2), r3 (at position
4), r4 (at position 8) and so on.
Hamming Code (contd.)
Step 3: Calculating the values of each redundant bit.
Each redundant bit, ri, is calculated as the parity, generally even parity, based upon its
bit position. It covers all bit positions whose binary representation includes a 1 in the
ith position except the position of ri.
o r1 is the parity bit for all data bits in positions whose binary representation includes a 1
in the least significant position excluding 1 (3, 5, 7, 9, 11 and so on)
o r2 is the parity bit for all data bits in positions whose binary representation includes a 1
in the position 2 from right except 2 (3, 6, 7, 10, 11 and so on)
o r3 is the parity bit for all data bits in positions whose binary representation includes a 1
in the position 3 from right except 4 (5-7, 12-15, 20-23 and so on)
Example
Position 7 6 5 4 3 2 1
Bit D3 D2 D1 R2 D0 R1 R0

Suppose the data to be transmitted is 1010.


Number of data bits, m = 4
Find number of redundant bits, r:
2r ≥ m + r + 1 => 2r ≥ 5 + r => r = 3
Total number of bits to be transmitted = m + r = 4 + 3 = 7 bits
Position 7 6 5 4 3 2 1
Binary 111 110 101 100 011 010 001
Bit D3 D2 D1 R2 D0 R1 R0
Value 1 0 1 0 0 1 0

Finding Parity bits:


❑ R0 bit is calculated using parity check at all the bits positions whose binary representation includes a
1 in the least significant position: 3, 5, 7 except 1. To find the redundant bit R0, we check for even
parity.
o D3, D1, D0 = 1, 1, 0 🡪 already in even parity.
o The value of R0 (parity bit’s value) = 0.
❑ R1 bit is calculated using parity check at all the bits positions whose binary representation includes a
1 in the second position from the least significant bit, except 2. That is, 3,6,7.
o D3, D2, D0 = 1, 0, 0 🡪 not even parity
o The value of R1 = 1
❑ Similarly, for R2 bit, check 7, 6, 5 🡪 D3, D2, D1 = 1, 0, 1 🡪 even
o The value of R2 = 0

Therefore, the codeword is = 1010010


Polynomial Representation
o We can use a polynomial to represent a binary word.
o Each bit from right to left is mapped onto a power term.
o The rightmost bit represents the “0” power term. The bit next to it the “1” power term, etc.
o If the bit is of value zero, the power term is deleted from the expression.
✔ Polynomial codes are based upon treating bit strings as representations of polynomials
with coefficients of 0 and 1 only

✔ Polynomial arithmetic is done modulo 2, according to the rules of algebraic field


theory.

✔ When the polynomial code method is employed, the sender and receiver must agree
upon a generator polynomial, G(x), in advance.

✔ To compute the checksum for some frame with m bits, corresponding to the
polynomial M(x), the frame must be longer than the generator polynomial
Cyclic Redundancy Check (CRC)
✔ Cyclic Redundancy Check (CRC) is a block code invented by W. Wesley Peterson in
1961. It is commonly used to detect accidental changes to data transmitted via
telecommunications networks and storage devices.

✔ CRC involves binary division of the data bits being sent by a predetermined divisor
agreed upon by the communicating system.

✔ The divisor is generated using polynomials. So, CRC is also called polynomial code
checksum.
Cyclic Codes
Cyclic codes are special linear block codes with one extra property. In a cyclic code, if a
codeword is cyclically shifted (rotated), the result is another codeword.

In a cyclic code,
▪ If syndrome s(x) ≠ 0, one or more bits is
corrupted.
▪ If s(x) = 0, either
▪ No bit is corrupted. OR
▪ Some bits are corrupted, but the
decoder failed to detect them.
CRC division using polynomials

The divisor in a cyclic code is


normally called the generator
polynomial or simply the generator.
Ex: Division in CRC encoder
Division in the CRC decoder for two cases
Task 1: Write a program to find the minimum hamming distance of the
coding scheme: d(01100, 01011); d(01110, 10101).

Task 2: Write a program to find the remainder obtained by dividing 𝑥7


+ 𝑥5 + 1 by the generator polynomial 𝑥3 + 1.

You might also like