You are on page 1of 8

CORRELATION & CONVOLUTION

Linear convolution
n=0:3;
x=[1 2 3 4];
subplot(2,2,1);stem(n,x),grid on
title('x(n)sequence');Xlabel('n');
Ylabel('amplitude');
h=[1 2 1 2];
subplot(2,2,2);stem(n,h),grid on
title('h(n)sequence');Xlabel('n');
Ylabel('amplitude');
t=0:6;
y=conv(x,h);
subplot(2,2,3);stem(t,y),grid on
title('y(n)sequence');Xlabel('n');
Ylabel('amplitude');

Reg no: 96209106019

Liner convolution

Reg no:96209106019

Circular convolution :

n=0:3;
xn=[1,2,3,4];
subplot(2,2,1);stem(n,xn),grid on
N=4;
for k=0:1:N-1
for n=0:1:N-1
p=exp(-j*pi*2*n*k/N);
x1(k+1,n+1)=p;
end
end
xk=xn*x1;
title('x(n)sequence');Xlabel('n');
Ylabel('amplitude');
disp(xn);
hn=[1 2 1 2];
N=4;
for k=0:1:N-1
for n=0:1:N-1
q=exp(-j*pi*2*n*k/N);
h1(k+1,n+1)=q;
end
end
hk=hn*h1;
n=0:3;
h=[1 2 1 2];
subplot(2,2,2);stem(n,h),grid on
title('h(n)sequence');Xlabel('n');
Ylabel('amplitude');
disp(hk);
yk=xk.*hk;
N=4;
for k=0:1:N-1

for n=0:1:N-1
t=exp(j*pi*2*n*k/N);
Reg no:96209106019
y1(k+1,n+1)=t/N;
end
end
yn=yk*y1;
s=0:3;
subplot(2,2,3);stem(s,yn),grid on
title('y(n)sequence');Xlabel('n');
Ylabel('amplitude');
disp(yk);

Reg no:96209106019

Auto correlation
n=0:3;
x=[1 2 3 4];
subplot(1,2,1);stem(n,x),grid on
title('x(n)sequence');Xlabel('n');
Ylabel('amplitude');
t=-3:3;
y=xcorr(x,x);
subplot(1,2,2);stem(t,y),grid on
title('rxx(l)');Xlabel('n');
Ylabel('amplitude');

Reg no: 96209106019

Cross correlation
n=0:3;
x=[1 2 3 4];
subplot(2,2,1);stem(n,x),grid on
title('x(n)sequence');Xlabel('n');
Ylabel('amplitude');
y=[1 2 1 2];
subplot(2,2,2);stem(n,y),grid on
title('h(n)sequence');Xlabel('n');
Ylabel('amplitude');
t=-3:3;
rxy=xcorr(x,y);
subplot(2,2,3);stem(t,rxy),grid on
title('rxy(l)');Xlabel(n');
Ylabel('amplitude');

Reg no: 96209106019

You might also like