Blogger Widgets

Wednesday 18 April 2012

circular convolution using DFT & IDFT

MATLAB Code:


clc;
clear all;
close all;
x1=input('Enter the 1st input:');
x2=input('Enter the 2nd input:');
lx1=length(x1);
lx2=length(x2);
l=max(lx1,lx2);
if(l==lx1)
x2=[x2,zeros(1,l-lx2)];end;
if(l==lx2)
x1=[x1,zeros(1,l-lx1)];end;

for k=1:l
x1n(k)=0;
x2n(k)=0;
for n=1:l
x1n(k)=x1n(k)+(x1(n)*exp((-1j)*2*pi*(k-1)*(n-1)/l));
x2n(k)=x2n(k)+(x2(n)*exp((-1j)*2*pi*(k-1)*(n-1)/l));
end;
end
y=x1n.*x2n;
ly=length(y);

for n=1:ly
y1(n)=0;
for k=1:ly
y1(n)=y1(n)+y(k)*exp(1j*2*pi*(k-1)*(n-1)/ly);
end;
y1(n)=y1(n)/ly;
end;
disp(y1);
subplot(2,2,1);
stem(x1);
title('1st input');
subplot(2,2,2);
stem(x2);
title('2nd input');
subplot(2,2,3:4);
stem(abs(y1));
title('circular convolution using DFT & IDFT');


Figure:-




0 comments

Post a Comment