<< Chapter < Page Chapter >> Page >
Proper use of the FFT  command can be done as in specsin1.m  (the top graph), which plots only the positive frequencies, or as in specsin2.m  (the bottom graph), which shows the full magnitude spectrum symmetric about f=0.
Proper use of the FFT command can be done as in specsin1.m(the top graph), which plots only the positive frequencies, or as in specsin2.m(the bottom graph), which shows the full magnitude spectrum symmetric about f = 0 .

The second solution requires more bookkeeping of indices, but gives plots that more closely accord with continuous-timeintuition and graphs. specsin2.m exploits the built in function fftshift , which shuffles the output of the FFT command so that the negative frequencies occur on the left, the positivefrequencies on the right, and DC in the middle. f=100; Ts=1/1000; time=10.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=(-N/2:N/2-1)/(Ts*N);                   % frequency vector fw=fft(w(1:N));                            % do DFT/FFTfws=fftshift(fw);                          % shift it for plotting plot(ssf,abs(fws))                         % plot magnitude spectrum

specsin2.m spectrum of a sine wave via the FFT/DFT (download file)
[link] , which shows the complete magnitude spectrum for both positive and negative frequencies. It is also easy toplot the phase spectrum by substituting phase for abs in either of the preceding two programs.

Explore the limits of the FFT/DFT technique by choosing extreme values. What happens when:

  1. f becomes too large? Try f = 200, 300, 450, 550, 600, 800, 2200 Hz. Comment on the relationship between f and Ts .
  2. Ts becomes too large? Try Ts = 1/500, 1/250, 1/50. Comment on the relationship between f and Ts . (You may have to increase time in order to have enough samples to operate on.)
  3. N becomes too large or too small? What happens to the location in the peak of the magnitude spectrum when N = 2 11 , 2 14 , 2 8 , 2 4 , 2 2 , 2 20 ? What happens to the width of the peak in each of these cases? (You may have to increase time in order to have enough samples to operate on).

Replace the sin function with sin 2 . Use What is the spectrum of sin 2 ? What is the spectrum of sin 3 ? Consider sin k . What is the largest k for which the results make sense? Explain what limitations there are.

Replace the sin function with sinc . What is the spectrum of the sinc function? What is the spectrum of sinc 2 ?

Plot the spectrum of w ( t ) = sin ( t ) + j e - t . Should you use the technique of specsin1.m or of specsin2.m ? Hint: Think symmetry.

The FFT of a real sequence is typically complex, and sometimes it is important to look at the phase (as well asthe magnitude).

  1. Let For phi= 0, 0.2, 0.4, 0.8, 1.5, 3.14, find the phase of the FFT output at the frequencies ± f .
  2. Find the phase of the output of the FFT when

These are all examples of “simple” functions, which can be investigated (in principle, anyway) analytically.The greatest strength of the FFT/DFT is that it can also be used for the analysis of data when no functional form isknown. There is a data file on the website called gong.wav , which is a sound recording of an Indonesian gong (a large struck metalplate). The following code reads in the waveform and analyzes its spectrum using the FFT. Make sure that thefile gong.wav is in an active M atlab path, or you will get a “file not found” error. If there is a sound card (and speakers)attached, the sound command plays the .wav file at the sampling rate f s = 1 / T s . filename='gong.wav';                  % name of wave file goes here [x,sr]=wavread(filename);             % read in wavefile Ts=1/sr;                              % sample interval and # of samplesN=2^15; x=x(1:N)';                    % length for analysis sound(x,1/Ts)                         % play sound, if sound card installedtime=Ts*(0:length(x)-1);              % establish time base for plotting subplot(2,1,1), plot(time,x)          % and plot top figuremagx=abs(fft(x));                     % take FFT magnitude ssf=(0:N/2-1)/(Ts*N);                 % establish freq base for plottingsubplot(2,1,2), plot(ssf,magx(1:N/2)) % plot mag spectrum

specgong.m find spectrum of the gong sound (download file)
specgong.m results in the plot shown in [link] . The top figure shows the time behavior of the sound as it rises very quickly (when the gongis struck) and then slowly decays over about 1.5 seconds. The variable N defines the window over which the frequency analysis occurs. The middle plot shows the completespectrum, and the bottom plot zooms in on the low frequency portion where the largest spikes occur. This sound consists primarilyof three major frequencies, at about 520, 630, and 660 Hz. Physically, these represent the three largest resonant modesof the vibrating plate.

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