Wednesday, 18 December 2013

DFT USING FFT MATLAB CODE - EXAMPLE


A fast Fourier transform (FFT) is an algorithm to compute the discrete Fourier transform (DFT) and its inverse. A Fourier transform converts time (or space) to frequency and vice versa; an FFT rapidly computes such transformations. As a result, fast Fourier transforms are widely used for many applications in engineering, science, and mathematics.

The FFT algorithm computes one cycle of the DFT and its inverse is one cycle of the DFT inverse. So it is the simple way to compute DFT of a sequence.


Here is a simple code to compute DFT of a sequence using FFT. The FFT is computed using the FFT(…..) function.

PROGRAM:
clc;
x=input('Enter the sequence : ');
n=input('Enter the length of FFT : ');

y=fft(x,n);
stem(y);
title('FFT');
xlabel('sample...');
ylabel('amplitude...');
disp('The FFT of the given sequence');
disp(y);
disp('The real value of FFT is ');
disp(real(y));
disp('The imaginary value of FFT is ');
disp(imag(y));
disp('The magnitude of FFT is ');
disp(abs(y));
disp('The phase of FFT is ');
disp(angle(y));
figure;
subplot(2,2,1);
stem(real(y));
title('Real');
xlabel('sample...');
ylabel('amplitude...');
subplot(2,2,2);
stem(imag(y));
title('Imaginary');
xlabel('sample...');
ylabel('amplitude...');
subplot(2,2,3);
stem(abs(y));
title('Magnitude plot');
xlabel('sample...');
ylabel('amplitude...');
subplot(2,2,4);
stem(angle(y));
title('Phase angle plot');
xlabel('sample...');
ylabel('amplitude...');
clear;

Input:
Enter the sequence : [2 4 6 8]
Enter the length of FFT : 5
Output:
The FFT of the given sequence
20.0000 ‐8.0902 ‐ 2.6287i 3.0902 ‐ 4.2533i 3.0902 + 4.2533i
‐8.0902 + 2.6287i


Waveform output:




If you enjoyed this post plz let us know your views via comments.
This helps us to do much more better.
Thankyou.


0 comments:

Post a Comment

Search Here...