0% found this document useful (0 votes)
19 views38 pages

ITC Lab Manual

The document outlines a lab experiment on measuring entropy of different probability distributions. It provides the theory, code samples, and results for Gaussian and normal distributions. It also includes potential viva questions and answers related to MATLAB functions used.

Uploaded by

humafarha26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views38 pages

ITC Lab Manual

The document outlines a lab experiment on measuring entropy of different probability distributions. It provides the theory, code samples, and results for Gaussian and normal distributions. It also includes potential viva questions and answers related to MATLAB functions used.

Uploaded by

humafarha26
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 38

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

SCHOOL OF ENGINEERING
SR UNIVERSITY WARANGAL

LAB RECORD

INFORMATION THEORY AND CODING


Name: HUMA FARHA
H. T. No: 2105A42003
Date of
TITLE OF THE Date of Maximum Marks Faculty
S.NO Record
EXPERIMENT Performance Marks Obtained Signature
Submission
1 Measure the entropy of 29-01-24
different probability
distributions

Compare the efficiency 05-02-24


2 of different source
coding methods.

3 Experiment with 12-03-24


varying SNR to observe
their impact on
communication.

4 Implement and test 19-02-24


error-detection codes
(e.g., CRC codes)

5 Error correction using 04-03-24


Hamming Code

6 Convolution 11-03-24

7 Encoding decoding with 18-03-24


LBC

8 Study the performance 13-04-24


of block codes under
varying error conditions

9 BER vs SNR for 15-04-24


hamming coded bpsk
modulation

10 Trade-off between 22-04-24


bandwidth-Efficiency
and error resilience
CODE OF CONDUCT FOR THE LABORATORY

1. All students must follow the Dress Code while in the laboratory.
2. Sandals or open-toed shoes are NOT allowed.
3. All bags must be left at the indicated place.
4. The lab timetable must be strictly followed.
5. Be PUNCTUAL for your laboratory session.
6. Experiment must be completed within the given time.
7. Noise must be kept to a minimum.
8. Workspace must be kept clean and tidy at all time.
9. Handle all equipment and components with care.
10. All students are liable to pay for any damage to the equipment, accessories, tools, or
components due to their own negligence.
11. All equipment’s, apparatus, tools and components must be RETURNED to their original place
after use.
12. Students are strictly PROHIBITED from taking out any items from the laboratory.
13. Students are NOT allowed to work alone in the laboratory without the Lab Supervisor
14. Report immediately to the Lab Supervisor any damages to equipment Before leaving the lab
15. Place the stools under the lab bench.
16. Turn off the power to all instruments.
17. Please check the laboratory notice board regularly for updates.
List of Experiments

1. Measure the entropy of different probability distributions


2. Compare the efficiency of different source coding methods.
3. Experiment with varying SNR to observe their impact on communication.
4. Implement and test error-detection codes (e.g., CRC codes)
5. Error correction using Hamming Code
6. Convolution
7. Encoding decoding with LBC
8. Study the performance of block codes under varying error conditions
9. BER vs SNR for hamming coded bpsk modulation
10. Trade-off between bandwidth-Efficiency and error resilience
Assessment Rubrics
Rubric for Demo experiments

Execution(6M) Record (2M) VIVA (2M)


Maximum marks are given if Maximum marks are given if Maximum marks are given if
the execution is done in time the record submitted in time answered all the questions.
and with neat &clear
solutions.

Rubrics for Design experiments

Solution(2M) Output(4M) Record(2M) VIVA (2M)


Maximum marks are given if the As per the
Maximum marks are given procedure of doing experiment, Maximum marks are given number of
if solutions are unique in the accurate Output, selection of if the record submitted in questions
class and submitted in time. components time and with neat &clear answered.
solutions.

Rubrics for Structured Experiments


AIMS proposed Record
Solutions(2M) Output(3M) VIVA (2M)
(1M) (2M)

Maximum marks are Maximum marks are


Maximum marks are
given if the number given if the procedure Maximum As per the number
assigned If more than one
aims more than 3 out of doing experiment, marks are given of questions
solution is proposed for
of which one is accurate Output, if the record answered
the selected aim
unique and not selection of submitted in
proposed by any components. time and with
batch neat &clear
solutions.
1. Measure the entropy of different probability distributions

AIM: To measure the entropy of different probability distributions using Gaussian and Normal distributions

SOFTWARE REQUIRED: MATLAB

THEORY: In probability, entropy tells us how uncertain a distribution is. It's like a measure of "surprise."
Higher entropy means more uncertainty and spread-out probabilities (like a fair coin flip). Lower entropy
signifies less surprise and concentrated probabilities (like a biased coin always landing heads). Mathematically,
formulas like Shannon entropy capture this using probabilities and logarithms.

CODE:
GAUSSIAN DISTRIBUTION
x=randn(100000,1);
[counts,binCenters]=hist(x,100);
binWidth=diff(binCenters);
binWidth=[binWidth(end),binWidth];
nz=counts>0;
frequency=counts(nz)/sum(counts(nz));
H=-sum(frequency.*log(frequency./binWidth(nz)))
% Plotting the histogram
figure;
histogram(x, binCenters);
xlabel('Value');
ylabel('Frequency');
title('Histogram of Dataset');

OUTPUT:
H=

1.4155
NORMAL DISTRIBUTION
CODE:
% Parameters for the normal distribution
mu = 0; % Mean
sigma = 1; % Standard deviation
num_samples = 100000; % Number of samples

% Generate samples from a normal distribution


x = mu + sigma * randn(num_samples, 1);

% Calculate histogram
[counts, binCenters] = hist(x, 100);

% Calculate bin width


binWidth = diff(binCenters);
binWidth = [binWidth(end), binWidth]; % Replicate last bin width for first, which is
indeterminate.

% Filter non-zero bins


nz = counts > 0;

% Calculate relative frequency


frequency = counts(nz) / sum(counts(nz));

% Calculate entropy
H = -sum(frequency .* log(frequency ./ binWidth(nz)));

% Plot histogram
figure;
bar(binCenters(nz), counts(nz) / sum(counts(nz)), 'hist'); % Normalizing counts
xlabel('Value');
ylabel('Probability Density');
title('Normal Distribution');

OUTPUT:
RESULT & ANALYSIS:

Hence I have done and verified the output of Gaussian distribution and Normal distribution.

POSSIBLE VIVA QUESTIONS:

1.Expand MATLAB?And importance of MATLAB?


2.What is clear all and close all will do?
3. What is disp() and input()?

Answers:

1. MATLAB stands for "MATrix LABoratory" and is a high-level programming language and interactive
environment primarily used for numerical computing, data analysis, and visualization. MATLAB facilitates
efficient algorithm development, data exploration, and problem-solving. Its user-friendly interface and seamless
integration with other tools further enhance its importance in scientific and engineering applications.

2. clear all: This command in MATLAB clears all variables from the workspace. It removes all variables from
the current workspace, releasing their memory. This is useful when you want to start with a clean workspace or
when you need to free up memory after working with large datasets or variables.

close all: This command closes all open figure windows in MATLAB. If you have opened multiple figure
windows during your MATLAB session, using "close all" will close them all at once. This is helpful for
cleaning up the display and organizing your workspace.

3.disp(): The disp() function in MATLAB is used to display the value of an expression or a message in the
command window. It is often used for printing outputs, messages, or intermediate results during script
execution. For example:

disp('Hello, MATLAB!')
This command will display "Hello, MATLAB!" in the command window.

input(): The input() function is used to prompt the user to enter data interactively. It allows MATLAB programs
to accept input from the user during runtime. The syntax is:

For example:
age = input('Enter your age: ');

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


2. Compare the efficiency of different source coding methods.

AIM: To Compare the efficiency of different source coding methods.

SOFTWARE REQUIRED: MATLAB

THEORY: The Shannon-Fano theorem is a method used in information theory for constructing prefix codes
that minimize the average code word length for a given probability distribution of symbols. In MATLAB, it can
be implemented to compare the efficiency of different source coding methods by encoding a set of symbols
with varying probabilities using Shannon-Fano coding and then calculating the average code word length

CODE:

%Shannon fano
clc
clear all
%%
rng(16)
input_prob=rand(10,1);
input_prob=input_prob/sum(input_prob);
test_prob=[0.35; 0.3; 0.2; 0.1; 0.04; 0.005; 0.005];
result=fano_encoding(test_prob);
result=extractAfter(result,"0")
%%

%%fano code generation


function bit_stream=fano_encoding(input_prob,stream,index,original_stream)

if nargin == 1
stream=string(zeros(size(input_prob)));
index=0;
original_stream=input_prob;
end
if(length(input_prob)>2)
input_prob=sort(input_prob,'descend');
%input_prob=reshape(input_prob,[],1);
split_index=find(cumsum(input_prob)>=sum(input_prob)/2,1);
bit_stream=stream;

bit_stream(index+1:split_index+index)=strcat(bit_stream(index+1:split_index+index),'
0');

bit_stream(split_index+index+1:end)=strcat(bit_stream(split_index+index+1:length(bit
_stream),1),'1');

bit_stream=fano_encoding(original_stream(split_index+index+1:length(bit_stream)),bit
_stream,split_index+index,original_stream);

if(find(cumsum(original_stream)>=0.5,1)>=split_index+index)
bit_stream=fano_encoding(original_stream(index+1:split_index+index),bit_stream,inde
x,original_stream);
end

elseif (length(input_prob)==2)
bit_stream=stream;
bit_stream(index+1)=strcat(stream(index+1),'0');
bit_stream(index+2)=strcat(stream(index+2),'1');

else
bit_stream=stream;
end
end

OUTPUT:
result =
7×1 string array
"00"
"01"
"10"
"110"
"1110"
"11110"
"11111"

RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


3. Experiment with varying SNR to observe their impact on communication.

AIM: To Experiment with varying SNR and to observe their impact on communication.

SOFTWARE REQUIRED: MATLAB

THEORY: In communication systems, varying Signal-to-Noise Ratio (SNR) levels allow us to observe their
impact on signal quality and reliability. By conducting experiments with different SNR values in MATLAB,
researchers can simulate scenarios where the signal strength relative to noise changes, mimicking real-world
conditions. These experiments help in analyzing the system's performance metrics such as bit error rate (BER)
or signal-to-noise ratio at the receiver end, aiding in the optimization of communication systems and the
selection of appropriate modulation and coding schemes for reliable data transmission across various channels
and environments.

CODE:

%varying snr in sine wave


fs = 1000
t = 0:1/fs:1
f = 10
A=1
x = A.*sin(2*pi*f*t)
subplot(2,1,1)
plot(t,x);
title('Original signal sine')
xlabel('time(s)')
ylabel('Amplitude')

%Add noise

SNR_values=[45,10,5,0,-5];

for i=1:length(SNR_values)
SNR=SNR_values(i)

noise_power=10^(-SNR/10)

noise=sqrt(noise_power)*randn(size(x))

y=x+noise

%plot the noisy signal

subplot(2, length(SNR_values), i+length(SNR_values)); plot(t,y)

title(['Noisy signal(SNR=', num2str(SNR), 'db)']); xlabel('time(s)');


xlabel('time(s)');
ylabel('amplitude')
end
OUTPUT:

CODE:
%varying snr in rectangular wave

% Parameters
+
Fs = 1000 % Sampling frequency

T = 1 / Fs % Sampling period

L = 1000 % Length of signal


t=(0:L-1)*T; % Time vector

% Generate a rectangular wave as the signal


rect_signal = square(2*pi*5*t);

% Plot the original signal figure;


figure
subplot(2,1,1)
plot(t,rect_signal)
title('original signal')
xlabel('Time (s)');
ylabel('Amplitude');

% Add Gaussian noise to simulate the communication channel

SNRs = [10, 5, 0, -5]; % SNR values to test

received_signals = zeros(length(SNRs), L);


for i = 1:length(SNRs)

noise_power = 10^(-SNRs(i)/10); % Calculate noise power based on SNR


noise = sqrt(noise_power)*randn(1, L); % Generate Gaussian noise

received_signals(i, :) = rect_signal + noise; % Add noise to the signal

% Plot received signals

subplot(2, length(SNRs),i+length(SNRs));

plot(t, received_signals(i, :));

title(['Received Signal (SNR = ', num2str(SNRs(i)), 'dB)']);

xlabel('Time (s)');

ylabel('Amplitude');

end

OUTPUT:

Fs =
1000
T=
1.0000e-03
L=
1000
RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


4. Implement and test error-detection codes (e.g., CRC codes)

AIM: To Implement and test error-detection codes (e.g., CRC codes)

SOFTWARE REQUIRED: MATLAB

THEORY: Implementing and testing error-detection codes such as CRC (Cyclic Redundancy Check) in
MATLAB involves generating the code, appending it to the data stream, transmitting it through a simulated
channel, and then checking for errors at the receiver end. By systematically introducing errors into the
transmitted data and verifying the integrity of the received message using CRC decoding algorithms,
researchers can evaluate the effectiveness of error detection and correction mechanisms. This experimentation
aids in refining error-detection code designs and assessing their performance under different noise and
interference conditions, ensuring robust data transmission in communication systems.

CODE:

%cyclic redundancy check of noisy BPSK data frames example


x=randi([0 1],12,1);
crcgenerator= comm.CRCGenerator([1 0 0 1],'ChecksumsPerFrame',2);
codeword=crcgenerator(x);
crcdetector=comm.CRCDetector([1 0 0 1],'ChecksumsPerFrame',2);
[~,error]=crcdetector(codeword);
codeword(end)=not(codeword(end));
[~,error]=crcdetector(codeword)
%if we remove all the semicolons we will get o/p for each line
OUTPUT:
error =
0
1

CODE:
%cyclic redundancy check of noisey BPSK data frames example2
poly='z4+z3+z2+z+1';
crcgenerator= comm.CRCGenerator(poly);
crcdetector= comm.CRCDetector(poly);
numFrames=20;
frmError= zeros(numFrames,1);

for k=1:numFrames
data= randi([0 1],12,1); %generate binary data
encData=crcgenerator(data); %append crc bits
modData=pskmod(encData,2); %bpsk modulate
rxSig=awgn(modData,5); %AWGN channel,SNR=5db
demodData=pskdemod(rxSig,2); %bpsk demodulate
[~,frmError(k)]=crcdetector(demodData);
end
find(frmError)
%if we remove all the semicolons we will get o/p for each line

OUTPUT:
ans =
3

RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


5. Error correction using Hamming Code

AIM: To Error correction using Hamming Code

SOFTWARE REQUIRED: MATLAB

THEORY: Error correction using Hamming Code involves encoding the data with redundant bits to detect and
correct errors during transmission. In MATLAB, implementing Hamming Codes allows for the generation of
parity bits and appending them to the original message. By simulating noisy channels and decoding received
messages using Hamming decoding algorithms, one can effectively correct single-bit errors and detect double-
bit errors, enhancing data reliability in communication systems. This process enables the evaluation of
Hamming Code performance under various error conditions, aiding in the design and optimization of error-
correction schemes.

CODE:
%error detection using hamming technique
M=3
[H,G]=hammgen(M);

%2nd method Given either H or G, the otherv matrix G or H


can be found with
%one command
H=gen2par(G)

%3rd using 4 bit message M=[0 1 0 1] and gf(2)


arithematic,the 7 bit
%codeword is created using generated matrix(G)
M=gf([0 1 0 1])
C=M*G

%any codeword C can be checked for errors using the check


matrix
H*C'

%the minimum hamming distance b/w any two codewords from


generating
%polynomial G is found as:
d=3
d=gfweight(G)

%correcting an error involves identifying a row in the


syndrome table from
%error reaminder. consider the single bit error
E=[0 0 0 1 0 0 0]; %error pattern
R=H*E' %syndrome for error

Output:

M=3
H=
1001011
0101110
0010111
G=
1101000
0110100
1110010
1010001
H=
1001011
0101110
0010111

M = GF(2) array.

Array elements =

0101

C = GF(2) array.

Array elements =

1100101

ans = GF(2) array.

Array elements =
0
0
0

d=3

d=
3

E=

0001000

R=
1
1
0
>> R= GF(2) array
6. Convolution

AIM:

SOFTWARE REQUIRED: MATLAB

THEORY: Convolution is a fundamental mathematical concept used in various fields like signal processing,
image analysis, and physics. It essentially describes how two functions interact with each other.
Convolution plays a crucial role in information theory and communication primarily through:

Convolutional Codes: These are error-correcting codes used for transmitting data over noisy channels. The
information is encoded using a specific mathematical operation based on convolution. This encoding adds
redundancy to the data, allowing for the detection and correction of errors introduced during transmission.

Channel Modeling: Channels in communication systems (e.g., wireless, wired) can introduce distortions or
filtering effects on the transmitted signal. Convolution can be used to model these channel effects
mathematically. By understanding how the channel "convolves" the signal, engineers can design techniques to
compensate for these distortions and improve communication reliability.

Feature Extraction: Convolution is a key operation in convolutional neural networks (CNNs), which are
powerful tools for tasks like image and speech recognition. In CNNs, convolution acts as a feature extractor,
identifying patterns and edges within the data. This extracted information is then used for classification or
prediction tasks.
Normal convolution: Normal convolution finds limited use in practical communication systems due
to its continuous nature. However, it plays a role in the theoretical analysis of communication systems. For
example, it can be used to model ideal channel behavior or analyze the theoretical performance limits of certain
communication techniques.

CODE:
%Normalconvolution

tint=0;
tfinal=0.05;
tstep=0.0005;

t=tint:tstep:tfinal;

x=4*square(500*t,50);
subplot(3,1,1);
plot(t,x);

h=400*exp((-400*t));
subplot(3,1,2);
plot(t,h);

t2=2*tint:tstep:tfinal*2;
y=conv(x,h)*tstep;

subplot(3,1,3);
plot(t2,y);

Output:
Discrete convolution: Discrete convolution is a superstar in information theory and coding,
especially for error correction. It forms the foundation of convolutional codes. Here, information is encoded by
mathematically convolving it with a specific sequence. This adds redundancy, allowing the receiver to not only
detect errors introduced during transmission, but also potentially fix them by decoding the convolution at their
end. It's a powerful technique for ensuring reliable communication despite channel noise.

CODE:

t = -1 0 1

%Discreteconvolution

a=-1;% this is the starting value of time for x(t)


b=0;% starting value of time for h(t)

x=[2 -1 1];
h=[3 2 1];

subplot(3,1,1);
t=a:a+length(x)-1 %tstep is not required here
stem(t,x);

subplot(3,1,2);
t=b:b+length(h)-1;
stem(t,h);

y=conv(x,h);

subplot(3,1,3);
t=a+b:a+b+length(y)-1;
stem(t,y);

Output:
Circular Convolution: Circular convolution, while not directly tied to core information theory concepts,
plays a supporting role in communication systems. Particularly in OFDM (Orthogonal Frequency-Division
Multiplexing), it helps analyze how a cyclic prefix combats inter-symbol interference (ISI). This prefix, created
by copying the packet's tail to the front, essentially loops the data. Circular convolution helps understand how
this loop interacts with the channel, ensuring the prefix eliminates ISI and allows for clear data reception.

CODE:
%Circularconvolution

x=[2 5 4 1];
y=[1 4 3];

%zeropad vectors uptill 4+3-1

xpad=[x zeros(1,6-length(x))];
ypad=[y zeros(1,6-length(y))];

%multiply ffts of both vectors and take idft of product

ccirc=ifft(fft(xpad).*fft(ypad));

%plot
stem(ccirc,'filled')
ylim([0 35])
title('circular convolution of xpad and ypad');

Output:
RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


7. Encoding and decoding using Linear Block Code

AIM: To Implement the Encoding and decoding using Linear Block Code

SOFTWARE REQUIRED: MATLAB

THEORY:
CODE:

%linear block code(LBC)


%for a systematic LBC, the 3 parity check digits c4,c5,c6 are given by
%c4=m1+m2+m3
%c5=m1+m2
%c6=m1+m3
% a. construct a generator matrix
% b. construct code generated by this matrix
% c. decode the recieved words 1)[1 0 1 1 0 0] 2)[0 0 1 1 0 0]
%c=(m1,m2,m3,...mk,p1,p2,...p(n-k))
%c=M*G
%c=1xn -> code vector of n bits
%M= message vector of 1xk bits
%G= generator matrix kxn size
% G=[I_k:P_(kxq)]_kxn, 9=(n-k)
% parity matrix =p= [1 1 1; 1 1 0;1 0 1]

clc;
clear all:
k=input("Enter the length of msg word: ");
n=input("Enter the length of codeword: ");
p=input("Enter the parity matrix:");
G=[eye(k) p]
m=input("Enter the msg word: ");
o=rem(m*G,2)
c=encode(m,n,k,'linear',G)
H=[p' eye(n-k)]
dtable=syndtable(H);
R=input("Enter the received codeword: ");
s_b=rem(R*H',2)
s_d=bi2de(s_b,'left-msb')
if (s_d==0)
disp("the received word is valid")
else
disp("the received word is invalld")
E=dtable(s_d+1,:)
disp("the corrected code word is: ")
CC=rem(R+E,2)
msg=CC(1:k)
end

OUTPUT:

Enter the length of msg word: 3


Enter the length of codeword: 6
Enter the parity matrix:[1 1 1;1 1 0;1 0 1]

G=

1 0 0 1 1 1
0 1 0 1 1 0
0 0 1 1 0 1

Enter the msg word: [1 1 1]

o=

1 1 1 1 0 0

c=

1 1 1 1 0 0

H=
1 1 1 1 0 0
1 1 0 0 1 0
1 0 1 0 0 1

Single-error patterns loaded in decoding table. 1 rows remaining.


2-error patterns loaded. 0 rows remaining.
Enter the received codeword: [1 0 1 1 0 0]

s_b =

1 1 0

s_d =

the received word is invalld

E=

0 1 0 0 0 0

the corrected code word is:

CC =

1 1 1 1 0 0

msg =

1 1 1

>>

RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


8. Study the performance of block codes under varying error
conditions
AIM: To study the performance of block codes under varying error conditions

SOFTWARE REQUIRED: MATLAB

THEORY:
Block codes are a crucial tool in digital communication systems, offering error detection and correction
capabilities by encoding fixed-size blocks of data with redundant bits. Their performance is evaluated based on
metrics like bit error rate (BER), frame error rate (FER), or block error rate (BLER. Under different error
conditions, such as varying levels of noise or distortion in the channel, block codes exhibit varying effectiveness
in error detection and correction. Their performance is influenced by factors like the code rate, the error
correction algorithm used, and channel characteristics. To assess performance, researchers simulate encoding
and decoding processes, adjusting parameters like signal-to-noise ratio (SNR) to observe changes in error rates.
This study is vital for designing robust communication systems capable of operating reliably in real-world
environments.

CODE:

clc
clear all
close all
n=7
k=4
A=[1 1 1;1 1 0;1 0 1;0 1 1]
G=[eye(k) A]
H=[A' eye(n-k)]
%encoding
msg=[1 1 1 1 ]
code=mod(msg*G,2)
%Channel Error
%code(1)=~code(1)
code(2)=~code(2)
%code(3)=~code(3)
%code(4)=~code(4)
%code(5)=~code(5)
%code(6)=~code(6)
%code(7)=~code(7)
recd = code
%decoding
syndrome = mod(recd*H',2)
find=0
for ii=1:n
if ~find
errvect =zeros(1,n)
errvect(ii)=1
search =mod (errvect*H',2)
if search ==syndrome
find=1
index=ii
end
end
end
disp(['position of error in codeword=',num2str(index)])
correctedcode=recd
correctedcode(index)=mod(recd(index)+1,2)
%strip off parity bits
msg_decoded=correctedcode
msg_decoded=msg_decoded(1:4)

OUTPUT:

n=

k=

A=

1 1 1
1 1 0
1 0 1
0 1 1

G=

1 0 0 0 1 1 1
0 1 0 0 1 1 0
0 0 1 0 1 0 1
0 0 0 1 0 1 1

H=

1 1 1 0 1 0 0
1 1 0 1 0 1 0
1 0 1 1 0 0 1

msg =

1 1 1 1
code =

1 1 1 1 1 1 1

code =

1 0 1 1 1 1 1

recd =

1 0 1 1 1 1 1

syndrome =

1 1 0

find =

errvect =

0 0 0 0 0 0 0

errvect =

1 0 0 0 0 0 0

search =

1 1 1

errvect =

0 0 0 0 0 0 0

errvect =

0 1 0 0 0 0 0

search =

1 1 0

find =
1

index =

position of error in codeword=2

correctedcode =

1 0 1 1 1 1 1

correctedcode =

1 1 1 1 1 1 1

msg_decoded =

1 1 1 1 1 1 1

msg_decoded =

1 1 1 1

>>

RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


9. BER vs SNR for hamming coded bpsk modulation
AIM: To study BER vs SNR for hamming coded bpsk modulation

SOFTWARE REQUIRED: MATLAB

THEORY:

In BPSK modulation with Hamming coding, the BER vs SNR curve illustrates how the error rate of transmitted
bits changes with varying signal-to-noise ratios. Hamming coding adds redundancy to aid error detection and
correction. As SNR increases, BER typically decreases, indicating better performance. However, there's usually
an error floor where further SNR increases yield diminishing improvements due to channel and receiver
imperfections. This curve guides the design of communication systems to achieve desired error rates across
different noise conditions.

CODE:

% Define system parameters


n = 7; % Hamming code parameters k = 4;
k=4;
SNR_dB = 0:2:20; % SNR range in dB
% Initialize arrays to store BER values
ber = zeros(size(SNR_dB));
% Simulate and evaluate performance for each SNR value
for i = 1:length(SNR_dB)

% Generate random message bits


messageBits = randi ([0, 1], 1, k);
% Encode the message using a Hamming code
encodedHamming = encode(messageBits, n, k,
'hamming/binary');
% BPSK modulation
carrier = cos(2*pi* (0:length(encodedHamming)-1)); % Carrier
signal modulatedSignal = encodedHamming.* carrier; % Modulate
the signal
modulatedSignal= encodedHamming.*carrier; %modulate the
signal

% Add AWGN noise to the modulated signal


SNR=10^(SNR_dB(i)/10); %convert SNR from db to linear scale
recievedSignal=awgn(modulatedSignal,SNR,"measured");

%bpsk demodulation
demodulatedSymbols=recievedSignal.*carrier;%demodulated the
signal

%convert demodulated symbols to binary numbers


threshold=0;% set threshold for demodulation
decodedBits=demodulatedSymbols> threshold;% convert symbols
to binary

%decode the recieved bits


decodedMessage=decode(decodedBits,n,k, 'hamming/binary');

%calculate Bit error rate


ber(i)=biterr(messageBits,decodedMessage)/k;
end
%plot ber vs snr
figure;
semilogy(SNR_dB,ber, 'bo-');%plotting with blue marker
xlabel('SNR_dB');
ylabel('BER');
title('BER vs SNR for hamming coded bpsk modulation');
grid on;

%to ensure plot window is not minimized or hidden


set(gcf,'Visible','on');

OUTPUT:
RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)


10. Trade off between bandwidth efficiency and error
resilience
AIM: Evaluate trade-off between bandwidth-Efficiency and error resilience

SOFTWARE REQUIRED: MATLAB

THEORY:

Balancing bandwidth efficiency and error resilience in communication systems requires a delicate compromise.
While maximizing bandwidth efficiency enables the transmission of more data within a given bandwidth,
enhancing error resilience necessitates the inclusion of redundancy to detect and correct errors. However, this
redundancy consumes additional bandwidth, potentially reducing efficiency. Conversely, minimizing
redundancy to optimize bandwidth efficiency can compromise error resilience. Thus, striking the right balance
involves tailoring the level of redundancy to the specific requirements of the application, ensuring efficient data
transmission while maintaining robust error detection and correction capabilities.

CODE:

%evaluate the trade offs between bandwidth and error effiency


%parameters
nBits = 1000; %Number of bits
EbNo_dB = 0:2:20;%Eb/No range
EbNo_lin = 10.^(EbNo_dB/10);%convert dB to
nTrials = 100;%number of trial
%Initialize arrays to store results
ber = zeros (length (EbNo_dB),1);
bw_efficiency = zeros (length (EbNo_dB),1);
for i = 1:length (EbNo_dB)
errors = 0;

for trial = 1:nTrials


%generate random bits to transmit
tx_bits = randi([0,1],1,nBits);
%simulate transmission channel (Add AWGN)
noise_std = 1/sqrt(2*EbNo_lin(i));
noise = noise_std*randn(1,nBits);%g
rx_signal = tx_bits +noise;
%demodulation (assuming hard decision )
rx_bits =rx_signal >0.5;
%count errors
errors=errors +sum(rx_bits~=tx_bits);
end
%calculate bit error rate (BER)
ber(i)=errors/(nBits*nTrials);
%calculate bandwidth efficiency (bits per second per Hz)
bw_efficiency(i) = nBits /(2*log2(1+EbNo_lin(i)));
end
%plot results
figure;
subplot(2,1,1);
semilogy(EbNo_dB,ber,'o-');
xlabel('Eb/No(dB)');
ylabel('Bit Error Rate (BER)');
title('Bit Error Rate vs Eb/No');
grid on;

subplot(2,1,2);
plot (EbNo_dB,bw_efficiency,'o-');
xlabel('Eb/No(dB)');
ylabel('Bandwidth Efficiency (bps/Hz)');
title('Bandwidth Efficiency vs Eb/No');
grid on;

OUTPUT:
RESULT & ANALYSIS:

Hence I have done and verified the output.

RUBRIC:

Execution(6M) Record (2M) VIVA (2M)

You might also like