DSS Exp5
DSS Exp5
DSS Exp5
2023-24
Experiment 5 (2023-24)
Roll No:- 65
Section:- A
Date:- 26/10/2023
1
Department of Electronics & Computer Science
2023-24
Linear Convolution :
Lab5 a) Write matlab program to perform convolution operation on two given signals.
Given x(n) input , h(n) impulse response of system and y(n) o/p of the system
Part A : Using direct inbuilt function : use matlab help
clc
clear all
clf
n1=0:1:3;
x=[1 2 3 1];
n2=-1:1:2;
h=[1 2 1 -1];
y=conv(x,h);
display(y);
% plot results properly
n3=min(n1)+min(n2); n4=max(n1)+max(n2);
r=n3:1:n4;
subplot (3,1,1); stem(n1,x); axis([-10 10 -1 5])
subplot (3,1,2); stem(n2,h); axis([-10 10 -3 5]);
subplot (3,1,3); stem(r,y); axis([-10 10 -5 10]);
2
Department of Electronics & Computer Science
2023-24
3
Department of Electronics & Computer Science
2023-24
% Step4 Plotting the result
n3=min(n1)+min(n2);
n4=max(n1)+max(n2);
p=n3:1:n4;
subplot (3,1,1);
stem(n1,x);
axis([-10 10 -2 5])
subplot (3,1,2);
stem(n2,h);
axis([-10 10 -3 5]);
subplot (3,1,3);
stem(p,y);
axis([-10 10 -5 10]);
4
Department of Electronics & Computer Science
2023-24
Lab 5 d) Use above program
to perform following convolution
X(n)=u(n)-u(n-10) and h(n)=0.9n u(n) you are not allowed to use conv or filter function.
Plot x(n), h(n) and o/p of the system.
Solution:
clc
clear all
n1 = -5:1:50;
n2 = n1;
x = zeros(size(n1));
x(n1 >= 0 & n1 <= 10) = 1;
y = zeros(1, length(n1));
for i = 1:length(n1)
for j = 1:length(n2)
if (i - j >= 0)
y(i) = y(i) + x(i - j + 1) * h(j);
end
end
end
subplot(3, 1, 1);
stem(n1, x);
title('x(n) = u(n) - u(n-10)');
5
Department of Electronics & Computer Science
2023-24
xlabel('n');
ylabel('x(n)');
subplot(3, 1, 2);
stem(n2, h);
title('h(n) = 0.9^n * u(n)');
xlabel('n');
ylabel('h(n)');
subplot(3, 1, 3);
stem(n1, y);
title('Output y(n) = x(n) * h(n)');
xlabel('n');
ylabel('y(n)');
6
Department of Electronics & Computer Science
2023-24
clc
clear all
close all
x=input('Enter the sequence');
n1=input('Enter the time sample range:');
h=fliplr(x);
n2=-fliplr(n1);
z=[];
for i=1:length(x)
g=h.*x(i);
z=[z;g];
end
[r c]=size(z);
k=r+c;
t=2;
y=[];
7
Department of Electronics & Computer Science
2023-24
cd=0;
while(t<=k)
for i=1:r
for j=1:c
if((i+j)==t)
cd=cd+z(i,j);
end
end
end
t=t+1;
y=[y cd];
cd=0;
end
nl=min(n1)+min(n2);
nh=max(n1)+max(n2);
t=nl:1:nh;
display(y);
subplot(3,1,1)
stem(n1,x);
axis([-5 5 -1 5]);
subplot(3,1,2)
stem(n2,h);
axis([-5 5 -1 5]);
subplot(3,1,3)
stem(t,y);
axis([-5 5 -5 30]);
8
Department of Electronics & Computer Science
2023-24
Part f Questions
1. Image Processing: Convolution is extensively used in image processing for tasks like edge
detection, blurring, and feature extraction.
2. Signal Processing: In audio and speech processing, convolution is used for filtering, noise
reduction, and effects like reverb.
3. Radar and Sonar Systems: Convolution is applied in radar and sonar systems to analyze
echo signals, locate objects, and determine their characteristics.
4. Neural Networks: In deep learning and artificial neural networks, convolutional layers are
used for feature extraction and pattern recognition.
5. Communication Systems: Convolution is used in digital communication systems for
channel equalization, error correction, and modulation/demodulation.
9
Department of Electronics & Computer Science
2023-24
c) Modify and develop matlab function/program for finding cross- corelation between 2
signal
Soln:
function crossCorrelation = cross_corr(x, h)
x = fliplr(x); % Flip x to perform cross-correlation
crossCorrelation = conv(x, h);
end
d) Applications of cross correlation
Soln:
1. Time Delay Estimation: In audio and signal processing, cross-correlation is used to
estimate the time delay between two signals.
2. Pattern Matching: Cross-correlation is used in pattern recognition to identify patterns or
objects within an image or a signal.
3. Geophysics: Cross-correlation of seismograph data is used to locate the epicenter of an
earthquake.
4. Radar: Cross-correlation is applied to radar signals for target detection and tracking.
5. Bioinformatics: Cross-correlation is used to analyze DNA sequences for sequence
alignment and identification of motifs.
10
Department of Electronics & Computer Science
2023-24
Soln:
function energy = calculateEnergy(x)
autocorr_result = xcorr(x, 'biased'); % Calculate the auto-correlation
energy = sum(autocorr_result);
end
Example 1:
Code:
X1 = [0, 1, 2, 3, 4];
energy1 = calculateEnergy(X1);
disp(['Energy of Example 1: ', num2str(energy1)]);
Output:
Energy of Example 1: 20
Example 2:
Code:
n2 = -4:4;
X2 = 2 .^ n2;
energy2 = calculateEnergy(X2);
disp(['Energy of Example 2: ', num2str(energy2)]);
Output:
Energy of Example 2: 113.3338
11