Fast Fourier Transform of Time Domain Signals

The objective of this experiment is to take FFT of the time domain signal and plot the spectra and study the spectra of the signal.

Matlab  Functions

Apart from  already known functions that we have used in the previous experiments, list of  few more MATLAB in built functions that may be used for the Experiment are listed below ,

1. fft()                                % to compute the fft of the sequence

2.linspace()                      % generate 'N' equally  spaced points between two numbers

3. abs()                             % To take absolute value of the complex number [ Remember output sequence of FFT is complex valued]

4.nextpow2()                   %   Ex:  nextpow2(200) returns 8 

5. fftshift()                        % Optional function

Let's  Code

Example Code 1

Let us see how much FFT is faster than DFT in terms of computational time. Execute the following code in the editor window.


t=0:0.01:10;

x_n=sin(2*pi*t);

dft_mat=dftmtx(length(t));

disp('Using DFT')

tic;

X_k=dft_mat*x_n';

toc;

disp('Using FFT')

tic;

X_k=fft(x_n);

toc;

Let's consider a simple sequence  x(n) = [1 1 1 1 1 1 ] that we have used in the class room, Computing the FFT for the sequence in the MATLAB  is very simple.

 Do the following In the command window, 

>> x = [1 1 1 1 1 1] ;

>> fft(x,8)       

ans =

  Columns 1 through 5

   6.0000 + 0.0000i  -0.7071 - 1.7071i   1.0000 - 1.0000i   0.7071 + 0.2929i   0.0000 + 0.0000i

  Columns 6 through 8

   0.7071 - 0.2929i   1.0000 + 1.0000i  -0.7071 + 1.7071i

Observation:

Example Code 2:

Copy Paste the following code in the Editor Window ,save the file and run it.

Answer  the Following:

Applying FFT for Basic Signals

This is the final task of the experiment. Applying  fft to Basic signals and plotting their spectrum.

Example:

Generate 10 Hz sine wave and plot the spectra by computing fft for the sine wave. Here is the sample code to generate the sine wave.

Instructions to Plot the Correct Spectra:

Output to Reproduce

If you look at the spectra, there are two peaks at +10 Hz and -10 Hz as the input is 10 Hz Sine . Producing one side spectrum is also alright [i.e one peak at +10 Hz] . If the frequency varies, the position of the peak also moves to the respective frequency.

FFT for the rest of the basic Signals

Produce the fft plot for all the basic signals. The FFT plot for the step and ramp may look like the following. Refer to the external links to know the theory behind the plots