ITC Lab Manual
ITC Lab Manual
SCHOOL OF ENGINEERING
SR UNIVERSITY WARANGAL
LAB RECORD
6 Convolution 11-03-24
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
AIM: To measure the entropy of different probability distributions using Gaussian and Normal distributions
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
% Calculate histogram
[counts, binCenters] = hist(x, 100);
% 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.
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:
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")
%%
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"
RUBRIC:
AIM: To Experiment with varying SNR and to observe their impact on communication.
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:
%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
CODE:
%varying snr in rectangular wave
% Parameters
+
Fs = 1000 % Sampling frequency
T = 1 / Fs % Sampling period
subplot(2, length(SNRs),i+length(SNRs));
xlabel('Time (s)');
ylabel('Amplitude');
end
OUTPUT:
Fs =
1000
T=
1.0000e-03
L=
1000
RESULT & ANALYSIS:
RUBRIC:
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:
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
RUBRIC:
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);
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
Array elements =
0
0
0
d=3
d=
3
E=
0001000
R=
1
1
0
>> R= GF(2) array
6. Convolution
AIM:
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
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];
xpad=[x zeros(1,6-length(x))];
ypad=[y zeros(1,6-length(y))];
ccirc=ifft(fft(xpad).*fft(ypad));
%plot
stem(ccirc,'filled')
ylim([0 35])
title('circular convolution of xpad and ypad');
Output:
RESULT & ANALYSIS:
RUBRIC:
AIM: To Implement the Encoding and decoding using Linear Block Code
THEORY:
CODE:
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:
G=
1 0 0 1 1 1
0 1 0 1 1 0
0 0 1 1 0 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
s_b =
1 1 0
s_d =
E=
0 1 0 0 0 0
CC =
1 1 1 1 0 0
msg =
1 1 1
>>
RUBRIC:
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 =
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
>>
RUBRIC:
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:
%bpsk demodulation
demodulatedSymbols=recievedSignal.*carrier;%demodulated the
signal
OUTPUT:
RESULT & ANALYSIS:
RUBRIC:
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:
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:
RUBRIC: