Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

SH 9 FFT

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Fast Fourier Transform (FFT)

Objectives
1. To study and investigate the Fast Fourier Transform algorithm.
2. To learn the analysis and reconstruction of discrete-time signals using FFT and
IFFT, respectively.

Introduction
The DFT introduced previously is the only transform that is discrete in both time
and frequency domains, and it is defined for finite-duration sequences. Although it is a
computable transform, its straightforward implementation is very inefficient, especially
when the sequence length N is large. In 1965 Cooley and Tukey showed a procedure to
substantially reduce the amount of computations involved in DFT. This led to the
explosion of applications of the DFT, including digital signal processing area, and also
led to the development of other efficient algorithms. These algorithms are collectively
known as Fast Fourier Transform (FFT) algorithms.
In an efficiently designed algorithm, the number of computations should be
constant per data sample, and therefore the total number of computations should be linear
with respect to N. The number of DFT computations for an N-point sequence depends
quadratically on N, which will be denoted by the notation:

CN  (N 2 ) . (1)

FFT algorithms can reduce the quadratic dependence on N of the DFT.


Theoretically, the number of computations used in the FFT algorithms could be as small
as, depending on the radix used in the algorithm,

C N   ( N log 2 N ) (2)

MATLAB provides a function called fft to compute the DFT of a vector x. It is


invoked by x = fft(x, N), which computes the N-point DFT. If the length of x is less than
N, then x is padded with zeros. If the argument N is omitted, then the length of the DFT is
the length of x. If x is a matrix, then fft(x,N) computes the N-point of each column of x.

Notice that the FFT algorithm is not a different mathematical transform, it is


simply an efficient means to compute the DFT. fft function is written in machine

1
language and not using MATLAB commands (i.e., it is not available as a .m file).
Therefore it executes very fast. The inverse DFT is computed using the ifft function,
which has the same characteristics as fft.

The execution time for FFT depends on the length of the transform. It is fastest for
powers of two. It is almost as fast for lengths that have only small prime factors. It is
typically several times slower for lengths that are prime numbers or which have large
prime factors. It is important to notice that the spectrum of FFT is always displayed
between 0 and fs as shown in figure 1. In addition, the signal after 0.5fs is only a
repetition of the first part and can be neglected.

Figure (1): N-point FFT spectrum amplitude.

Experiment
1. Compute the FFT of x[n], which is a cosine wave with a frequency of 10Hz and
sampled using a sampling frequency of 100Hz. N (the number of points in the FFT)
must be at least as large as the number of samples in x[n]. Use the following code to
plot the spectrum amplitude:
clc
clear all
close all
fs=100;
Ts=1/fs;
n = 0:29;
x1 = cos(20*pi*n*Ts);
N = 30;
X1 = abs(fft(x1,N));
F = [0:N-1]/N *fs;
figure
stem(F,X1,'*');title('Amplitude of spectrum');

2
2. 2- To demonstrate the effect of N on the spectrum, repeat step (1) using three different
values of N: 64, 128 and 256, then plot the resulting spectrum amplitudes in one figure
using subplot.
Theoretically, sinusoid should transform to an impulse in the frequency domain,
why do we have sincs in the frequency domain? When FFT is computed with an N
larger than the number of samples in x[n], it fills in the samples after x[n] with zeros
(as happened in step (2), where Matlab computed FFT with filling the spaces after n
=30 with zeros). This is like taking a sine wave and multiplying it with a rectangular
box of length 30. A multiplication of a box by a sine wave in the time domain equals
to the convolution of a sinc and impulse in the frequency domain. The results of step
(2) support this conclusion.

3. Compare the execution time of FFT with that of DFT for the signal in step (1) using
N=2048 and 2039. Justify your results. Use the functions clock, etime and tic
toc.

4. Reduce the execution time of FFT to the minimum by using N that equals to the next
power of 2 for the signal given in step (1), using nextpow2 as follows:
N_FFT = 2^nextpow2(L); % L is the number of samples in x[n]

5. When the region between 0 and fs is examined, it can be seen that there is even
symmetry around the center point 0.5fs, where the data between 0.5fs and fs is a mirror
image of the data between 0 and 0.5fs. Remove the redundant information in step (4)
by displaying only half the spectrum amplitude.

6. A common use of Fourier transforms is to find the frequency components of a signal


buried in a noisy time domain signal. For the signal in step (4), use a length of 1000 for
x[n] and add random noise to x[n] using the function randn with an amplitude of 2,
then plot both the noisy time domain signal and its spectrum amplitude in one figure
using subplot.
o Can you distinguish the frequency of the original signal in time domain?
o Can you distinguish the frequency of the original signal in frequency domain?

3
7. Add a noise signal that has a single frequency of 40Hz (sine wave) to x[n], then
remove this frequency from the spectrum and synthesize the original signal using
ifft, as follows:
clc
clear all
close all
fs=100;
Ts=1/fs;
N=1000;
n = 0:N-1;
x1 = cos(20*pi*n*Ts)+sin(80*pi*n*Ts);
subplot(211);
stem(n*Ts,x1);
title('Signal + noise');
xlabel('nTs')
ylabel('x(nTs)')
X1 = abs(fft(x1,N));
F =[0:N-1]/N *fs;
subplot(212);
stem(F,X1);
title('Amplitude of spectrum');
xlabel('F (Hz)');
ylabel('|X(F)|');
%%%%%%%%%%%%%% IFFT %%%%%%%%%%%%%
x3=[X1(1:N/4) zeros(1,N/2) X1(N*3/4+1:end)];
figure ;
subplot(211);
stem(F, x3);
xlabel('F (Hz)')
ylabel('|X(F)|')
xr=ifft(x3, length(x3));
subplot(212);
stem(n*Ts, xr)
xlabel('nTs')
ylabel('x(nTs)')
title('Original signal')

You might also like