<< Chapter < Page Chapter >> Page >

While the FFT/IFFT commands are easy to invoke, their meaning is not always instantly transparent.The intent of this section is to provide some examples that show how to interpret (andhow not to interpret) the frequency analysis commands in M atlab .

Begin with a simple sine wave of frequency f sampled every T s seconds, as is familiar from previous programs such as speccos.m . The first step in any frequency analysis is todefine the window over which the analysis will take place, since the FFT/DFT must operate on a finite data record.The program specsin0.m defines the length of the analysis with the variable N (powers of two make for fast calculations), and then analyzes the first N samples of w . It is tempting to simply invoke the M atlab commands fft and to plot the results. Typing plot(fft(w(1:N))) gives a meaningless answer (try it!) because the output of the fft command is a vector of complex numbers. When M atlab plots complex numbers, it plots the imaginary vs. the real parts. In order to view themagnitude spectrum, first use the abs command, as shown in specsin0.m .

f=100; Ts=1/1000; time=5.0;      % freq, sampling interval, time t=Ts:Ts:time;                    % define a time vectorw=sin(2*pi*f*t);                 % define the sinusoid N=2^10;                          % size of analysis windowfw=abs(fft(w(1:N)));             % find magnitude of DFT/FFT plot(fw)                         % plot the waveform
specsin0.m naive and deceptive spectrum of a sine wave via the FFT (download file)

Running this program results in a plot of the magnitude of the output of the FFT analysis of the waveform w . The top plot in [link] shows two large spikes, one near “100” and one near “900”. What do these mean? Try a simple experiment. Change the value of N from 2 10 to 2 11 . This is shown in the bottom plot of [link] , where the two spikes now occur at about “200” and at about “1850”. But the frequency of thesine wave hasn't changed! It does not seem reasonable that the window over which the analysis is done should change the frequencies inthe signal.

Naive and deceptive plots of the spectrum of a sine wave in which the frequency of the analyzed wave appears to depend on the size N of the analysis window. The top figure has N=2^10, while the bottom uses N=2^11.
Naive and deceptive plots of the spectrum of a sine wave in which the frequency of the analyzed wave appears to depend onthe size N of the analysis window. The top figure has N = 2 10 , while the bottom uses N = 2 11 .

There are two problems. First, specsin0.m plots the magnitude data against the index of the vector fw , and this index (by itself) is meaningless. The discussion surrounding [link] shows that each element of W [ n ] represents a scaling of the complex sinusoid with frequency e j 2 π n / N . Hence, these indices must be scaled by the time over which the analysis is conducted, which involvesboth the sampling interval and the number of points in the FFT analysis. The second problem is the ordering of the frequencies.Like the columns C n of the DFT matrix M [link] , the frequencies represented by the W [ N - n ] are the negative of the frequencies represented by W [ n ] .

There are two solutions. The first is appropriate only when the original signal is real valued. In this case, the W [ n ] 's are symmetric and there is no extra information contained inthe negative frequencies. This suggests plotting only the positive frequencies, a strategy that is followed in specsin1.m . f=100; Ts=1/1000; time=5.0;             % freq, sampling interval, time t=Ts:Ts:time;                           % define a time vectorw=sin(2*pi*f*t);                        % define the sinusoid N=2^10;                                 % size of analysis windowssf=(0:N/2-1)/(Ts*N);                   % frequency vector fw=abs(fft(w(1:N)));                    % find magnitude of DFT/FFTplot(ssf,fw(1:N/2))                     % plot for positive freq. only

specsin1.m spectrum of a sine wave via the FFT/DFT (download file)
specsin1.m is shown in the top plot of [link] . The magnitude spectrum shows a single spikeat 100 Hz, as is expected. Change f to other values, and observe that the location of the peak in frequency moves accordingly.Change the width and location of the analysis window N and verify that the location of the peak does not change. Change the sampling interval Ts and verify that the analyzed peak remains at the same frequency.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Software receiver design. OpenStax CNX. Aug 13, 2013 Download for free at http://cnx.org/content/col11510/1.3
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Software receiver design' conversation and receive update notifications?

Ask