Experiment 1

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 12

Convolution & Correlation

DSP_FALL 2022 1
Convolution
A mathematical operator which
computes the “amount of overlap”
between two functions. Can be thought
of as a general moving average
Discrete domain:

DSP_FALL 2022 2
Convolution
Arbitrary discrete-time signal;

The response of the system to x(n) is,

The output sequence y(n) is found as,

This is called convolution sum.


DSP_FALL 2022 3
Linear Convolution
clc; for i=1:N1
for j=1:N2
clear all;
y(i,i+j-1) =x(i)*h(j);
close all; end
x=input('enter the 1st End
sequence'); y=sum(y);
h=input('enter the 2nd disp('convolved signal');
sequence'); disp(y);
N1=length(x); Y=conv(x,h);
disp('convolved signal using
N2=length(h);
builtin fn');
disp(Y);
DSP_FALL 2022 4
Circular Convolution
clc;
for i=0:N-1
clear all;
for j=0:N-1
close all;
k=mod(i-j,N);
x=input('enter the 1st Y(i+1)=Y(i+1)+(X(k+1)*
sequence'); H(j+1));
h=input('enter the 2nd end
sequence');
end
N1=length(x);
disp(Y);
N2=length(h);
CC=cconv(x,h,N);
N=max(N1,N2);
disp('Circular
X=[x,zeros(1,N-N1)]; convolution');CC
H=[h,zeros(1,N-N2)];
Y=zeros(1,N); DSP_FALL 2022 5
Correlation of Discrete-Time
Signals

Transmitted Signal, x(n)

Reflected Signal,
y(n) = x(n-D) + w(n)

0 T

DSP_FALL 2022 6
Correlation
Auto Correlation:

rxx  l    x  n  x  n  l   r  l 
n 
xx l  0, 1, 2,

Cross Correlation:

rxy  l    x n y n  l 
n 
l  0, 1, 2,

rxy  l    x n  l  y n
n 
l  0, 1, 2,

DSP_FALL 2022 7
Correlation
clc;
clear all; for i=1:N1
close all; for j=1:N2
x=input('enter the 1st Y(i+j-1)=Y(i+j-
sequence'); 1)+(x(i)*H(j));
h=input('enter the 2nd end
sequence'); end
N1=length(x); disp(Y);
N2=length(h); Corr=xcorr(x,h);
H=fliplr(h); disp(Correlation');Corr
Y=zeros(1,N1+N2-1);
DSP_FALL 2022 8
Correlation of Signals
A=conv(x,y);
load gong;
B=xcorr(x,y);
x=y;
figure;subplot(2,2,1);grid on;
Fs1=Fs; plot(x);title('GONG SIGNAL');
player=audioplayer(x,Fs1); subplot(2,2,2);grid on;
play(player) plot(y);
load chirp; title('CHIRP SIGNAL');
player=audioplayer(y,Fs); subplot(2,2,3);grid on;
play(player) plot(A);
title('Convolved SIGNAL');
subplot(2,2,4);grid on;
plot(B);
DSP_FALL 2022 title('Correlated SIGNAL'); 9
Exp.2
Generate the signals
 x(n) over the interval 100-300 with
amplitude ‘1’
 y(n) over the interval 200-800 with
magnitude ‘1.5’

Find the cross correlation between x(n)


and y(n).

DSP_FALL 2022 10
DSP_FALL 2022 11
Exp.2
Generate a signal
Find the cross
with components
w1,w2,w3 as correlation
shown in figure between x(n) and
and plot their y(n).
auto-correlation

DSP_FALL 2022 12

You might also like