0% found this document useful (0 votes)
56 views7 pages

SPL 3

This document contains an experiment on signal processing concepts of convolution and correlation. It includes 4 examples - the first performs convolution on two discrete signals in MATLAB, the second convolves two functions, the third performs cross-correlation on two signals, and the fourth performs auto-correlation on a sine wave signal. It also includes two discussion questions - the first computes the convolution of an input and impulse response using MATLAB, and the second writes a MATLAB program to compute the output of a discrete time LTI system given its impulse response and input.

Uploaded by

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

SPL 3

This document contains an experiment on signal processing concepts of convolution and correlation. It includes 4 examples - the first performs convolution on two discrete signals in MATLAB, the second convolves two functions, the third performs cross-correlation on two signals, and the fourth performs auto-correlation on a sine wave signal. It also includes two discussion questions - the first computes the convolution of an input and impulse response using MATLAB, and the second writes a MATLAB program to compute the output of a discrete time LTI system given its impulse response and input.

Uploaded by

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

University of Technology

Department of Communications Engineering


Optical Communication Systems Engineering Branch

Convolution and Correlation

Experiment No.3
Signal Processing Laboratory

Mousa Saad Luaibi

Third Year

Morning Study

Group (B)

Wednesday, April 6, 2022


Signal Processing Laboratory EXP.NO.3: Convolution and Correlation

➢ Introduction
A mathematical way of combining two signals to form a new signal is known as Convolution.
In MATLAB for convolution ‘conv’ statement is used. The convolution of two vectors, p, and
q given as “a = conv (p,q)” which represents that the area of overlap under the points as p
slides across q. Convolution is the most important technique in Digital Signal Processing.

Example (1): Convolution of two discrete signals


input y(n)
close all; 6

n1=0:1:7; 4

01234567 2
y1=[1 2 3 1 2 3 4 5];
0
h1=[1 1 1 2 1 -1 1 1]; 0 1 2 3 4 5 6 7

X=conv(y1,h1); 2
impulse response h(n)

n2=0:length(X)-1;
1
figure(1)
subplot(3,1,1) 0

stem(n1,y1); -1
0 1 2 3 4 5 6 7
title(‘input y(n)’);
output x(n)
subplot(3,1,2) 30

stem(n1,h1); 20

title(‘impulse response h(n)’);


10
subplot(3,1,3)
stem(n2,X); 0
0 2 4 6 8 10 12 14

title(‘output x(n)’);

Example (2): Convolution of two functions

close all;
Fs=100; % use higher sampling rate
t=-10:1/Fs:10;
d=(abs(t)-1)==0; % use kronecker delta function
% for discrete-time simulation
s=sign(t);
x=d.*s;
x2=1*(t>-1 & t<2);
Signal Processing Laboratory EXP.NO.3: Convolution and Correlation
sp1=conv(x,x2,’same’);
1

%plotting figures
figure;

f(x)
0.5

subplot(3,1,1);
0

plot(t,x2); -10 -8 -6 -4 -2 0 2 4 6 8 10

1
ylabel(‘f(x)’); 0.5

subplot(3,1,2)

g(x)
0

plot(t,x); -0.5

ylabel(‘g(x)’); -1
-10 -8 -6 -4 -2 0 2 4 6 8 10

subplot(3,1,3) 1

plot(t,sp1); convolution
0.5

0
xlabel(‘Time’); -0.5

ylabel(‘convolution’); -1
-10 -8 -6 -4 -2 0 2 4 6 8 10
Time

input signal
Example (3): Corss-correlation of two vectors 1

0.5
t=0:99;
x=cos(2*pi*1/10*t); 0

figure; -0.5

subplot(2,1,1);
-1
stem(t,x); 0 20 40 60 80 100

title('input signal'); cros-correlated signal


1
y=cos(2*pi*1/10*t-pi)+0.25*randn(size(t));
[xc,lags]=xcorr(y,x,20,'coeff'); 0.5

subplot(2,1,2); 0

stem(lags(21:end),xc(21:end));
-0.5
title('cross-correlated signal');
-1
0 5 10 15 20

Example (4): Auto-correlation of a sine wave signal

N=1000; % Number of samples


f1=1; % Frequency of the sine wave
FS=200; % Sample index numbers
Signal Processing Laboratory EXP.NO.3: Convolution and Correlation

input signal
n=0:N-1; 1

figure; 0.5

x=sin(2*pi*f1*n/FS); %Generate the signal x(n); 0

subplot(2,1,1); -0.5
plot(n,x);
-1
title('input signal'); 0 200 400 600 800 1000

[xc, lags]=xcorr(x,'coeff'); 1
auto-correlated signal

tau=lags*1/FS;
0.5
subplot(2,1,2);
0
plot(tau,xc);
-0.5
title('auto-correlated signal');
-1
-5 0 5

➢ Discussion
1. Consider an LTI system with the impulse response h(n) and input x(n). Find the
convolution sum, y(n) and sketch the output for this system using MATLAB.

x(n) signal
3

n=0:1:6; 2

x=[0,1,2,3,2,1,0]; 1

h=[1,1,1,1,1,1,0]; 0
0 1 2 3 4 5 6

c=conv(x,h); 1
h(n) signal

n1=0:length(c)-1;
0.5
subplot(3,1,1);
stem(n,x); 0
0 1 2 3 4 5 6

title('x(n) signal'); 10
convolution signal

subplot(3,1,2);
5
stem(n,h);
0
0 2 4 6 8 10 12
Signal Processing Laboratory EXP.NO.3: Convolution and Correlation

title('h(n) signal');
subplot(3,1,3);
stem(n1,c)
title('convolution signal');

2. Write a MATLAB program to compute the output for a discrete time LTI system whose
impulse response h(t) and input x(t) is given by:

x(t) signal
2
t=-5:0.001:5;
1
x=(-t+1>=0)-2*(-t>=0)+(-t-1>=0);
0
h=2*[(-t+1==0)-(-t+3==0)];
-1
c=conv(x,h,'same');
-2
subplot(3,1,1) -5 -4 -3 -2 -1 0 1 2 3 4 5

plot(t,x) h(t) signal

title('x(t) signal'); 2

ylim([-2 2]);
0
subplot(3,1,2)
plot(t,h) -2

title('h(t) signal'); -5 -4 -3 -2 -1 0 1 2 3 4 5

ylim([-3 3]); output signal

subplot(3,1,3) 2

plot(t,c)
0
title('output signal');
ylim([-3 3]); -2

-5 -4 -3 -2 -1 0 1 2 3 4 5
Signal Processing Laboratory EXP.NO.3: Convolution and Correlation

3. Write a MATLAB program to compute the cross correlation between the following
signals:

v1(t) signal)
T=1; 2

t=0:0.001:3; 1

v1=sawtooth(2*pi*t*T); 0

v2=square(2*pi*t*T); -1

[c,lags]=xcorr(v1,v2,10,'coeff'); -2
-1 0 1 2 3 4

subplot(3,1,1) v2(t) signal)


2
plot(t,v1)
1
axis([-1 4 -2 2]);
0
title('v1(t) signal)');
-1
subplot(3,1,2)
-2
-1 0 1 2 3 4
plot(t,v2)
cross-correlated signal)
axis([-1 4 -2 2]); -0.82

title('v2(t) signal)');
-0.84
subplot(3,1,3);
-0.86
plot(lags(11:end),c(11:end))
title('cross correlated signal)'); -0.88
0 2 4 6 8 10

4. Write a MATLAB program to convolute the two signals below in the time domain:

ℎ(𝑡) = {𝑡 , 0 < 𝑡 < 2 ; 0 , 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒]


𝑥(𝑡) = {|𝑡| , −1 < 𝑡 < 1 ; 0 , 𝑒𝑙𝑠𝑒𝑤ℎ𝑒𝑟𝑒]
Signal Processing Laboratory EXP.NO.3: Convolution and Correlation
x(t) signal
1

t=-4:0.001:4;
0.5
x=abs(t).*[(-t+1>=0)-(-t-1>=0)];
h=t.*[(-t+2>=0)-(-t>=0)]; 0
-4 -3 -2 -1 0 1 2 3 4
c=conv(x,h,'same');
h(t) signal
subplot(3,1,1) 2

plot(t,x)
title('x(t) signal'); 1

subplot(3,1,2)
0
plot(t,h) -4 -3 -2 -1 0 1 2 3 4

title('h(t) signal'); 1000


convolution signal

subplot(3,1,3)
plot(t,c) 500

title('convolution signal');
0
-4 -3 -2 -1 0 1 2 3 4

5. Write the MATLAB code that sketch the autocorrelation of the following periodic square
wave f(t):

x(t) signal
2

T=1;
0
t=-5:0.001:5;
s=square(2*pi*(t+0.25)*(T) ); -1

subplot(2,1,1)
plot(t,s); -2
-5 -4 -3 -2 -1 0 1 2 3 4 5

ylim([-2 2]);
title('x(t) signal'); 1
auto-correlated signal

[c,lags]=xcorr(s,'coeff');
t=lags*T; 0.5

subplot(2,1,2)
0
plot(t,c);
title('auto-correlated signal'); -0.5

-1
-1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
4
x 10

You might also like