You are on page 1of 8

Open-ended Lab File

COMMUNICATION SYSTEM LAB


[ECE-320]

Submitted to: - Dr Garima Mahendru

Amity School of Engineering & Technology

AMITY UNIVERSITY UTTAR PRADESH


GAUTAM BUDDHA NAGAR

Submitted by-

Pratibha Nayar (A2305119056)


Rachna Yadav (A2305119057)
Prateek Goel (A2305119059)
Arjun (A2305119061)
Anitya Saxena (A2305119062)

B.Tech
5ECE1-Y
Index
S.N Categor Ex Name of Pa Date Date of Max Marks Signat
o. y of p. Experim ge Allotme Evaluat . Obtain ure of
Assignm No. ent No. nt of ion Mar ed Facult
ent Experim ks y
ent

1. Mandator 1. To design a
y system that
constructs
Experime Hamming
nt* codes using
any
simulation
platform or
any
programmi
ng
language.
AIM:
To design a system that constructs Hamming code using any simulation platform or any
programming language.

Software Used:
Online Python Compiler

THEORY-
Hamming Codes
In digital communication system, the data transfer should be error free and with high
accuracy. The data errors often result in the loss of important or secure data. To overcome
this issue, a scientist named Richard W Hamming formulated an algorithm to detect and
correct single-error correcting binary codes. His research paper was published in 1950 and
later these codes were popularized as Hamming Code.

The basic concept of Hamming Code is to add Parity bits to the data stream to verify that the
data received is correct or matches with the input. These bits are transmitted in such a way
that they identify where the error has occurred in the data stream and rectify it.

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:
1. Even parity bit:
In the case of even parity, for a given set of bits, the numbers 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.
2. Odd Parity bit:
In the case of odd parity, for a given set of bits, the numbers 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.

General Algorithm of Hamming code –


The Hamming Code is simply the use of extra parity bits to allow the identification of an
error.
i. Write the bit positions starting from 1 in binary form (1, 10, 11, 100, etc.).
ii. All the bit positions that are a power of 2 are marked as parity bits (1, 2, 4, 8, etc.).
iii. All the other bit positions are marked as data bits.
iv. Each data bit is included in a unique set of parity bits, as determined its bit position
in binary form.
 Parity bit 1 covers all the bits positions whose binary representation includes a 1 in
the least significant position (1, 3, 5, 7, 9, 11, etc.).
 Parity bit 2 covers all the bits positions whose binary representation includes a 1 in
the second position from the least significant bit (2, 3, 6, 7, 10, 11, etc.).
 Parity bit 4 covers all the bits positions whose binary representation includes a 1 in
the third position from the least significant bit (4–7, 12–15, 20–23, etc.).
 Parity bit 8 covers all the bits positions whose binary representation includes a 1 in
the fourth position from the least significant bit bits (8–15, 24–31, 40–47, etc.).
 In general, each parity bit covers all bits where the bitwise AND of the parity
position and the bit position is non-zero.
v. Since we check for even parity set a parity bit to 1 if the total number of ones in the
positions it checks is odd.
vi. Set a parity bit to 0 if the total number of ones in the positions it checks is even.

Fig1: Position of parity bit according to 1’s position

CODE:
 
def calcRedundantBits(m):
 
    # Use the formula 2 ^ r >= m + r + 1
    # to calculate the no of redundant bits.
    # Iterate over 0 .. m and return the value
    # that satisfies the equation
 
    for i in range(m):
        if(2**i >= m + i + 1):
            return i
 
def posRedundantBits(data, r):
 
    # Redundancy bits are placed at the positions
    # which correspond to the power of 2.
    j = 0
    k = 1
    m = len(data)
    res = ''
 
    # If position is power of 2 then insert '0'
    # Else append the data
    for i in range(1, m + r+1):
        if(i == 2**j):
            res = res + '0'
            j += 1
        else:
            res = res + data[-1 * k]
            k += 1

    # The result is reversed since positions are


    # counted backwards. (m + r+1 ... 1)
    return res[::-1]
  
def calcParityBits(arr, r):
    n = len(arr)
 
    # For finding rth parity bit, iterate over
    # 0 to r - 1
    for i in range(r):
        val = 0
        for j in range(1, n + 1):
 
            # If position has 1 in ith significant
            # position then Bitwise OR the array value
            # to find parity bit value.
            if(j & (2**i) == (2**i)):
                val = val ^ int(arr[-1 * j])
                # -1 * j is given since array is reversed
 
        # String Concatenation
        # (0 to n - 2^r) + parity bit + (n - 2^r + 1 to n)
        arr = arr[:n-(2**i)] + str(val) + arr[n-(2**i)+1:]
    return arr
 
def detectError(arr, nr):
    n = len(arr)
    res = 0
 
    # Calculate parity bits again
    for i in range(nr):
        val = 0
        for j in range(1, n + 1):
            if(j & (2**i) == (2**i)):
                val = val ^ int(arr[-1 * j])
 
        # Create a binary no by appending
        # parity bits together.
 
        res = res + val*(10**i)
 
    # Convert binary to decimal
    return int(str(res), 2)
 
 
# Enter the data to be transmitted
data = '1011001'
 
# Calculate the no of Redundant Bits Required
m = len(data)
r = calcRedundantBits(m)
 
# Determine the positions of Redundant Bits
arr = posRedundantBits(data, r)
 
# Determine the parity bits
arr = calcParityBits(arr, r)
 
# Data to be transferred
print("Data transferred is " + arr) 
 
# Stimulate error in transmission by changing
# a bit value.
# 10101001110 -> 11101001110, error in 10th position.
 
arr = '11101001110'
print("Error Data is " + arr)
correction = detectError(arr, r)
print("The position of error is " + str(correction))

SIMULATION-
OUTPUT:

APPLICATIONS-
The applications of Hamming Code are:

 They are extensively used in telecommunication industry.


 They are used in computer memory, modems and embedded processors.
 They are used in Nano Satellites.

Advantages of Hamming Code-


The advantages of Hamming Code are:

 They are effectively used to detect and correct errors.


 Single-bit error correction using these Codes is effective on Data Stream
Networks.

Disadvantages of Hamming Code:


The disadvantages of Hamming Code are:

 Bandwidth usage is more.


 Extra parity bit added for error correction reduces the bit rate of transmitter.

CONCLUSION:
Hence, we have successfully constructed the Hamming codes using python language. On this
coding process we have basically defined four function i.e… for calculating reductant bit,
second for to identify the position of reductant bits, third one is to find weather it has odd
number of 1’s or even number of 1’s in parity bit according to parity bit position, and last one
is used to find the position of error Bit of any present in transferred data.

MARKING SCHEME

Pratibha Rachna Prateek Arjun Anitya


Criteria Total Nayar Yadav Goel Saxena
(A23051190
Mar
(A23051190 (A23051190 (A23051190 61) (A23051190
ks
56) 57) 59) 62)

Designing 3      
concept (D)

Application 2      
of
Knowledge(
A)

Performance( 3      
P)

Result(G) 2      

Total Marks 10      

You might also like