American International University Digital Signal Processing Lab Experiement#9
The document discusses Fast Fourier Transforms (FFT) and how to use Matlab's FFT function. It provides 4 examples: 1) Taking the FFT of a cosine signal with different N values, 2) Varying the number of periods in a signal and taking its FFT, 3) How zero-padding affects the FFT output, and 4) Using fftshift to properly display the frequency spectrum from -fs/2 to fs/2. The FFT decomposes a signal into its frequency components in a computationally efficient way compared to the discrete Fourier transform (DFT).
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 ratings0% found this document useful (0 votes)
45 views
American International University Digital Signal Processing Lab Experiement#9
The document discusses Fast Fourier Transforms (FFT) and how to use Matlab's FFT function. It provides 4 examples: 1) Taking the FFT of a cosine signal with different N values, 2) Varying the number of periods in a signal and taking its FFT, 3) How zero-padding affects the FFT output, and 4) Using fftshift to properly display the frequency spectrum from -fs/2 to fs/2. The FFT decomposes a signal into its frequency components in a computationally efficient way compared to the discrete Fourier transform (DFT).
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/ 4
American International University
Digital Signal Processing Lab
Experiement#9
Experiment no. 4( Final Term): Fast Fourier Transforms (FFT)
Objective:
The objective of this experiment is to become familiar with Fast Fourier Transform (FFT)
Introduction
The Fast Fourier transform (FFT) is an algorithm for computing DFT, before which the DFT required excessive amount of computation time, particularly when high number of samples (N) was required. The FFT forces one further assumption, that N is an integer multiple of 2. This allows certain symmetries to occur reducing the number of calculations (especially multiplications) which have to be done
Matlab's FFT function is an effective tool for computing the discrete Fourier transform of a signal. The following code examples will help you to understand the details of using the FFT function.
Example 1:
The typical syntax for computing the FFT of a signal is FFT(x,N) where x is the signal, x[n], you wish to transform, and N is the number of points in the FFT. N must be at least as large as the number of samples in x[n]. To demonstrate the effect of changing the value of N, synthesize a cosine with 30 samples at 10 samples per period.
n =[0:29]; x =cos(2*pi*n/10);
Define 3 different values for N. Then take the transform of x[n] for each of the 3 values that were defined . The abs function absolute of the magnitude of the transform, as we are not concerned with distinguishing between real and imaginary components.
The frequency scale begins at 0 and extends to N-1 for an N-point FFT. We then normalize the scale so that it extends from 0 to 1-1/N . F1 =[0 : N1 - 1]/N1; F2 =[0 : N2 - 1]/N2; F3 =[0 : N3 - 1]/N3; Plot each of the transforms one above the other. subplot(3,1,1) plot(F1,X1,'-x'),title('N =64'),axis([0 1 0 20]) subplot(3,1,2) plot(F2,X2,'-x'),title('N =128'),axis([0 1 0 20]) subplot(3,1,3) plot(F3,X3,'-x'),title('N =256'),axis([0 1 0 20])
Upon examining the plot (shown in in Figure ) one can see that each of the transforms adheres to the same shape, differing only in the number of samples used to approximate that shape. What happens if N is the same as the number of samples in x[n]? To find out, set N1 =30. What does the resulting plot look like? Why does it look like this? Example 2:
In the the last example the length of x[n] was limited to 3 periods in length. Now, let's choose a large value for N (for a transform with many points), and vary the number of repetitions of the fundamental period.
n =[0:29]; x1 =cos(2*pi*n/10); % 3 periods x2 =[x1 x1]; % 6 periods x3 =[x1 x1 x1]; % 9 periods N =2048; X1 =abs(fft(x1,N)); X2 =abs(fft(x2,N)); X3 =abs(fft(x3,N)); F =[0:N-1]/N; subplot(3,1,1) plot(F,X1),title('3 periods'),axis([0 1 0 50]) subplot(3,1,2) plot(F,X2),title('6 periods'),axis([0 1 0 50]) subplot(3,1,3) plot(F,X3),title('9 periods'),axis([0 1 0 50]) The previous code will produce three plots as shown in the following figure. 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 10 20 30 40 50 3 periods 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 10 20 30 40 50 6 periods 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 0 10 20 30 40 50 9 periods
The first plot, the transform of 3 periods of a cosine, looks like the magnitude of 2 sincs with the center of the first sinc at 0.1fs and the second at 0.9fs. The second plot also has a sinc-like appearance, but its frequency is higher and it has a larger magnitude at 0.1fs and 0.9fs. Similarly, the third plot has a larger sinc frequency and magnitude.
As x[n] is extended to an large number of periods, the sincs will begin to look more and more like impulses. But we know that a sinusoid transformed to an impulse, why do we have sincs in the frequency domain? When the 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. Example 2 had an x[n] that was 30 samples long, but the FFT had an N =2048. When Matlab computes the FFT, it automatically fills the spaces from n =30 to n =2047 with zeros. This is like taking a sinusoid and multiplying it with a rectangular box of length 30. A multiplication of a box and a sinusoid in the time domain should result in the convolution of a sinc with impulses in the frequency domain. Furthermore, increasing the width of the box in the time domain should increase the frequency of the sinc in the frequency domain. The previous Matlab experiment supports this conclusion.
Example 4: Spectrum Analysis with the FFT and Matlab The FFT does not directly give you the spectrum of a signal. As we have seen with the last two experiments, the FFT can vary dramatically depending on the number of points (N) of the FFT, and the number of periods of the signal that are represented. There is another problem as well. The FFT contains information between 0 and fs, however, we know that the sampling frequency 5 must be at least twice the highest frequency component. Therefore, the signal's spectrum should be entirely below fs, the Nyquist frequency. Recall also that a real signal should have a transform magnitude that is symmetrical for positive and negative frequencies. So instead of having a spectrum that goes from 0 to fs, it would be more appropriate to show the spectrum from fs/2 to fs/2 This can be accomplished by using Matlab's shift function as the following code demonstrates. n =[0:149]; x1 =cos(2*pi*n/10); N =2048; X =abs(fft(x1,N)); X =fftshift(X); F =[-N/2:N/2-1]/N; plot(F,X), xlabel('frequency / f s') 0.5 0.4 0.3 0.2 0.1 0 0.1 0.2 0.3 0.4 0.5 0 10 20 30 40 50 60 70 80 frequency / f s