clc;
close all;
x=[2,-1,4,-3,5];
h=[-3,-2,1,5,-2,3,4];
m=length(x);
n=length(h);
p=autocorr(x);
subplot(2,2,1)
stem(p)
xlabel('no. of samples');
ylabel('Amplitude')
title('Auto-correlation of (x)')
disp(p);
q=autocorr(h);
subplot(2,2,2)
stem(q)
xlabel('no. of samples');
ylabel('Amplitude')
title('Auto-correlation of (h)')
disp(q);
r=xcorr(h,x);
subplot(2,2,3)
stem(r)
xlabel('no. of samples');
ylabel('Amplitude')
title('Cross-correlation of (h)&(x)')
disp(r);
s=xcorr(x,h);
subplot(2,2,4)
stem(s)
xlabel('no. of samples');
ylabel('Amplitude')
title('Cross-correlation of (x)&(h)')
disp(s)
Auto-Correlation without using MATLAB command
clc;
clear all;
close all;
h=[-3,-2,1,5,-2,3,4];
h2=flip(h);
m=length(h);
x1=[h2,zeros(1,m)];
h1=[h,zeros(1,m)];
for i=1:m+m-1
y(i)=0;
for j=1:m
if(i-j+1>0)
y(i)=y(i)+x1(j)*h1(i-j+1);
disp(i);
disp(j);
disp(y);
end
end
end
figure (1);
subplot(2,1,1);
stem(h)
xlabel('no. of samples');
ylabel('Amplitude')
title('seq h');
subplot(2,1,2);
stem(y)
xlabel('no. of samples');
ylabel('Amplitude')
title('rhh(l)');
disp(h)
disp(y)
clc;
clear all;
close all;
x=[2,-1,4,-3,5];
x2=flip(x);
m=length(x);
x1=[x2,zeros(1,m)];
h1=[x,zeros(1,m)];
for i=1:m+m-1
y(i)=0;
for j=1:m
if(i-j+1>0)
y(i)=y(i)+x1(j)*h1(i-j+1);
disp(i);
disp(j);
disp(y);
end
end
end
figure (1);
subplot(2,1,1);
stem(x)
xlabel('no. of samples');
ylabel('Amplitude')
title('seq x');
subplot(2,1,2);
stem(y)
xlabel('no. of samples');
ylabel('Amplitude')
title('rxx(l)');
disp(x)
disp(y)
Cross-Correlation without using MATLAB command
clc;
clear all;
close all
x=[2,-1,4,-3,5];
h=[-3,-2,1,5,-2,3,4];
h2=flip(h);
m=length(x);
n=length(h);
x1=[x,zeros(1,n)];
h1=[h2,zeros(1,m)];
for i=1:n+m-1
y(i)=0;
for j=1:m
if(i-j+1>0)
y(i)=y(i)+x1(j)*h1(i-j+1);
disp(i);
disp(j);
disp(y);
end
end
end
figure (1);
subplot(3,1,1);
stem(x)
xlabel('no. of samples');
ylabel('Amplitude')
title('seq x');
subplot(3,1,2);
stem(h)
xlabel('no. of samples');
ylabel('Amplitude')
title('seq h');
subplot(3,1,3);
stem(y)
xlabel('no. of samples');
ylabel('Amplitude')
title('rxh(l)');
disp(x)
disp(h)
disp(y)
clc;
clear all;
close all;
x=[2,-1,4,-3,5];
h=[-3,-2,1,5,-2,3,4];
x2=flip(x);
m=length(x);
n=length(h);
x1=[x2,zeros(1,n)];
h1=[h,zeros(1,m)];
for i=1:n+m-1
y(i)=0;
for j=1:m
if(i-j+1>0)
y(i)=y(i)+x1(j)*h1(i-j+1);
disp(i);
disp(j);
disp(y);
end
end
end
figure (1);
subplot(3,1,1);
stem(x)
xlabel('no. of samples');
ylabel('Amplitude')
title('seq x');
subplot(3,1,2);
stem(h)
xlabel('no. of samples');
ylabel('Amplitude')
title('seq h');
subplot(3,1,3);
stem(y)
xlabel('no. of samples');
ylabel('Amplitude')
title('rhx(l)');
disp(x)
disp(h)
disp(y)