%correlation
clc
clear all
v=input('Starting point of 1st Sequence =');
x1=input('Enter 1st sequence i.e. x(n) = ');
a=length(x1);
u=input('Starting point of 2nd Sequence =');
h1=input('Enter 2nd sequence i.e. h(n) =');
b=length(h1);
if(a>b) %Padding of Sequence
l=a-b;
h=[h1 zeros(1,l)];
x=x1;
b=a;
elseif(b>a)
l=b-a;
x=[x1 zeros(1,l)];
h=h1;
a=b;
else
x=x1;
h=h1;
end
g=[zeros(1,b-1) x];
i=h;
y=zeros(1, a+b-1);
e=a;
f=0;
for n=1:a+b-1
q=[zeros(1,f) i zeros(1,e-1)];
for k=1:a+b-1
y(1,n)=y(1,n)+g(1,k)*q(1,k);
end
e=e-1;
f=f+1;
end
y=y;
fprintf('Range of the N for result')
p=v+u;
q=p+a+b-2;
size=p:q
'OUTPUT--Correlation Result,y:-'
y
stem(size,y)
title('Correlation of x(n) & h(n) :---->');xlabel('samples, n---->');
ylabel('y(n)---->');
评论0