First we will find convolution of two discrete signals and then crosscorrelation of two signals using conv and xcorr function.
MATLAB Code:
clc;
a=[2 3 1];
b=[1 2 3];
c=conv(a,b);
m=length(c)-1;
n=0:1:m;
subplot(3,1,1);
stem(n,c);
xlabel('n');
ylabel('c');
title('convolution of two discrete sequence using conv function');
x=[1 2 3];
y=[1 2 3];
n1=length(y)-1;
n2=length(x)-1;
r1=conv(x,fliplr(y));
r=xcorr(x,y);
k=-n1:n2;
subplot(3,1,2);
stem(k,r);
xlabel('k');
ylabel('r');
title('cross-correlation of two discrete sequence using conv and xcorr function');
subplot(3,1,3);
stem(k,r1);
Output:
No comments:
Post a Comment