Exp 2
Exp 2
m 1 of 2
clc;
N= 200;
x = rand(1,N);
Tr= zeros(1,N);
iTr= zeros(1,N);
t= 0: N-1;
a = fft(x);
b = ifft(a);
ab = abs(a);
an = angle(a);
iab = abs(b);
ian = angle(b);
fprintf('Given function: ');
disp(x)
fprintf('Using matlab Function\n\n');
fprintf('Fourier transform: ');
disp(a)
fprintf('Inverse Fourier transform: ');
disp(b)
for k1= 0:N-1
for n1= 1:N
m1= x(n1).*(exp((-2).*(pi).*(1i).*(k1)*(n1-1)./(N)));
Tr(1,k1+1)= Tr(1,k1+1)+ m1;
end
end
for k2= 0:N-1
for n2= 1:N
m2= Tr(n2).*(exp((2).*(pi).*(1i).*(k2)*(n2-1)./(N)));
iTr(1,k2+1)= iTr(1,k2+1)+ m2/N;
end
end
fprintf('Without using matlab Function\n\n');
fprintf('Fourier Transform: ');
disp(Tr)
fprintf('Inverse Fourier Transform: ');
disp(iTr)
subplot(2,1,1)
stem(t,ab)
title('Magnitude of DFT')
xlabel('Time');
ylabel('Magnitude');
subplot(2,1,2)
stem(t,an)
xlabel('Time');
ylabel('Phase response');
title('Phase response of DFT')
figure
subplot(2,1,1)
stem(t,iab)
3/2/25 11:50 PM E:\Matlab projects\Sem 6\DFT.m 2 of 2
title('Magnitude of iDFT')
xlabel('Time');
ylabel('Magnitude');
subplot(2,1,2)
stem(t,ian)
xlabel('Time');
ylabel('Phase response');
title('Phase response of iDFT')