0% found this document useful (0 votes)
53 views

Network and Communication Kunal Singh 18BCI0189 Lab Da - 1

The document discusses two algorithms - CRC 32/8 and Hamming code. It then compares the performance of CRC vs parity check using MATLAB. For CRC 32/8, it generates CRC using direct and non-direct methods and checks if they are equal. For Hamming code, it encodes and decodes a message with and without errors to check error detection and correction. It then implements even and odd parity check algorithms. For a given bit sequence, it calculates the parity bit and appends it to output the sequence with parity bit. It measures time for both algorithms.

Uploaded by

Kunal Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views

Network and Communication Kunal Singh 18BCI0189 Lab Da - 1

The document discusses two algorithms - CRC 32/8 and Hamming code. It then compares the performance of CRC vs parity check using MATLAB. For CRC 32/8, it generates CRC using direct and non-direct methods and checks if they are equal. For Hamming code, it encodes and decodes a message with and without errors to check error detection and correction. It then implements even and odd parity check algorithms. For a given bit sequence, it calculates the parity bit and appends it to output the sequence with parity bit. It measures time for both algorithms.

Uploaded by

Kunal Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

NETWORK AND COMMUNICATION

Kunal Singh
18BCI0189
LAB DA -1

1.) Consider a 32-bit input/code using CRC 32/8 for an


ethernet IEEE 802, Predict the performance of the CRC
polynomial over hamming code in terms of order of
execution, Time taken and complexity of the algorithm
CODE FOR CRC 32/8:
tic() %start stopwatch
rng(1865); % Seed the random number generator for repeatable results
data = randi([0,1],100,1);
poly = [32,26,23,22,16,12,11,10,8,7,5,4,2,1,0]; %Polynomial of 32 degree
dataN = [not(data(1:32));data(33:end)];
crcGen1 = comm.CRCGenerator('Polynomial', poly, 'InitialConditions', 0,
'DirectMethod', false, 'FinalXOR', 1);
seq = crcGen1(dataN);
csNondirect = seq(end-31:end);
crcGen2 = comm.CRCGenerator('Polynomial', poly, 'InitialConditions', 1,
'DirectMethod', true, 'FinalXOR', 1);
txSeq = crcGen2(data);
csDirect = txSeq(end-31:end);
disp([csNondirect';csDirect']);
isequal(csNondirect,csDirect)
rng('default');
% Reset the random number generator
toc() %stop stopwatch
Output:
HAMMING CODE
Code:
tic()%start stopwatch
[h,g,n,k] = hammgen(3)
msg=[1,0,1,0];
n=7; k=4;
code = encode(msg,n,k,'linear/fmt',g)
msgd = decode(code,n,k,'linear/fmt',g)
% introduce an error
p_code = [1,0, 1, 1, 0, 1, 0];
msgd2 = decode(p_code,n,k,'linear/fmt',g)
fprintf("as only one error is induced it is corrected")
% introduce 2 errors
p_code2 = [1,1, 1, 1, 0, 1, 0];
msgd2 = decode(p_code2,n,k,'linear/fmt',g)
fprintf("as there are 2 error induced it is not able to correct both")
toc()%stop stopwatch
2.) Check performance of the CRC over parity check
using MATLAB.
Code:
Even parity:
clc;
close all;
clear all;
tic()
x = input('Enter the bit sequence to test for Even parity: ');
t = 0;
for i = 1:length(x) %can replace this 'for' loop just by t=sum(x)
if(x(i))
t = t + 1; %increment by one if a bit is one
end
end
if(mod(t,2)~=0) %check if not even then attach another '1' to make
the parity even
y = [x 1]; disp('Parity bit generated : 1');
else %check if even then attach another '0' to let the parity be even
y = [x 0]; disp('Parity bit generated : 0');
end
disp('Input bit sequence:');
disp(x); %display the input bit sequence
disp('Bit sequence with parity (Even) bit : ');
disp(y); %display the resultant bit sequence after parity bit addition
toc()

Output:
Code:
Odd parity:
clc;
close all;
clear all;
tic()
x = input('Enter the bit sequence to test for Odd parity: ');
t = 0;
for i = 1:length(x) %can replace this 'for' loop just by t=sum(x)
if(x(i))
t = t + 1; %increment by one if a bit is one
end
end

if(mod(t,2)~=1) %check if not odd then attach another '1' to make the parity
odd
y = [x 1]; disp('Parity bit generated : 1');
else %check if odd then attach another '0' to let the parity be odd
y = [x 0]; disp('Parity bit generated : 0');
end
disp('Input bit sequence:');
disp(x); %display the input bit sequence
disp('Bit sequence with parity (Odd) bit : ');
disp(y);%display the resultant bit sequence after parity bit addition
toc()

Output:

You might also like