0% found this document useful (0 votes)
15 views2 pages

Exp 2

The document contains a MATLAB script that performs the Discrete Fourier Transform (DFT) and its inverse on a randomly generated signal. It calculates the Fourier transform using both MATLAB's built-in functions and a manual implementation, displaying the results for both methods. The script also visualizes the magnitude and phase responses of the DFT and inverse DFT using stem plots.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Exp 2

The document contains a MATLAB script that performs the Discrete Fourier Transform (DFT) and its inverse on a randomly generated signal. It calculates the Fourier transform using both MATLAB's built-in functions and a manual implementation, displaying the results for both methods. The script also visualizes the magnitude and phase responses of the DFT and inverse DFT using stem plots.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

3/2/25 11:50 PM E:\Matlab projects\Sem 6\DFT.

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')

You might also like