DISCRETE FOURIER TRANSFORM DFT

Equations 16.26 and 16.27 represent the discrete analogs of Eqs. 16.25 and 16.24, respectively. As such, they can be employed to compute both a direct and an in- verse Fourier transform for discrete data. Note that the factor 1n in Eq. 16.27 is merely a scale factor that can be included in either Eq. 16.26 or 16.27, but not both. For exam- ple, if it is shifted to Eq. 16.26, the first coefficient F which is the analog of the constant a is equal to the arithmetic mean of the samples. Before proceeding, several other aspects of the DFT bear mentioning. The highest fre- quency that can be measured in a signal, called the Nyquist frequency, is half the sampling frequency. Periodic variations that occur more rapidly than the shortest sampled time in- terval cannot be detected. The lowest frequency you can detect is the inverse of the total sample length. As an example, suppose that you take 100 samples of data n = 100 samples at a sample frequency of f s = 1000 Hz i.e., 1000 samples per second. This means that the sample interval is t = 1 f s = 1 1000 sampless = 0.001 ssample The total sample length is t n = n f s = 100 samples 1000 sampless = 0.1 s and the frequency increment is f = f s n = 1000 sampless 100 samples = 10 Hz The Nyquist frequency is f max = 0.5 f s = 0.51000 Hz = 500 Hz and the lowest detectable frequency is f min = 1 0.1 s = 10 Hz Thus, for this example, the DFT could detect signals with periods from 1500 = 0.002 s up to 110 = 0.1 s.

16.5.1 Fast Fourier Transform FFT

Although an algorithm can be developed to compute the DFT based on Eq. 16.26, it is computationally burdensome because n 2 operations are required. Consequently, for data samples of even moderate size, the direct determination of the DFT can be extremely time consuming. 16.5 DISCRETE FOURIER TRANSFORM DFT 395 The fast Fourier transform, or FFT, is an algorithm that has been developed to com- pute the DFT in an extremely economical fashion. Its speed stems from the fact that it utilizes the results of previous computations to reduce the number of operations. In par- ticular, it exploits the periodicity and symmetry of trigonometric functions to compute the transform with approximately n log 2 n operations Fig. 16.10. Thus, for n = 50 sam- ples, the FFT is about 10 times faster than the standard DFT. For n = 1000, it is about 100 times faster. The first FFT algorithm was developed by Gauss in the early nineteenth century Heideman et al., 1984. Other major contributions were made by Runge, Danielson, Lanczos, and others in the early twentieth century. However, because discrete transforms often took days to weeks to calculate by hand, they did not attract broad interest prior to the development of the modern digital computer. In 1965, J. W. Cooley and J. W. Tukey published a key paper in which they outlined an algorithm for calculating the FFT. This scheme, which is similar to those of Gauss and other earlier investigators, is called the Cooley-Tukey algorithm. Today, there are a host of other approaches that are offshoots of this method. As described next, MATLAB offers a function called fft that employs such efficient algorithms to compute the DFT.

16.5.2 MATLAB Function:

fft MATLAB’s fft function provides an efficient way to compute the DFT. A simple repre- sentation of its syntax is F = fftf, n FIGURE 16.10 Plot of number of operations vs. sample size for the standard DFT and the FFT. FFT⬃ n log 2 n DFT⬃n 2 Samples 40 2000 1000 Operations where F = a vector containing the DFT, and f = a vector containing the signal. The parameter n , which is optional, indicates that the user wants to implement an n-point FFT. If f has less than n points, it is padded with zeros and truncated if it has more. Note that the elements in F are sequenced in what is called reverse-wrap-around order . The first half of the values are the positive frequencies starting with the constant and the second half are the negative frequencies. Thus, if n = 8, the order is 0, 1, 2, 3, 4, ⫺3, ⫺2, ⫺1. The following example illustrates the function’s use to calculate the DFT of a simple sinusoid. EXAMPLE 16.3 Computing the DFT of a Simple Sinusoid with MATLAB Problem Statement. Apply the MATLAB fft function to determine the discrete Fourier transform for a simple sinusoid: f t = 5 + cos2π12.5t + sin2π18.75t Generate 8 equispaced points with t = 0.02 s. Plot the result versus frequency. Solution. Before generating the DFT, we can compute a number of quantities. The sam- pling frequency is f s = 1 t = 1 0.02 s = 50 Hz The total sample length is t n = n f s = 8 samples 50 sampless = 0.16 s The Nyquist frequency is f max = 0.5 f s = 0.550 Hz = 25 Hz and the lowest detectable frequency is f min = 1 0.16 s = 6.25 Hz Thus, the analysis can detect signals with periods from 125 = 0.04 s up to 16.25 = 0.16 s. So we should be able to detect both the 12.5 and 18.75 Hz signals. The following MATLAB statements can be used to generate and plot the sample Fig. 16.11a: clc n=8; dt=0.02; fs=1dt; T = 0.16; tspan=0:n-1fs; y=5+cos2pi12.5tspan+sin2pi31.25tspan; 16.5 DISCRETE FOURIER TRANSFORM DFT 397 subplot3,1,1; plottspan,y,-ok,linewidth,2,MarkerFaceColor,black; titlea ft versus time s; As was mentioned at the beginning of Sec. 16.5, notice that tspan omits the last point. The fft function can be used to compute the DFT and display the results Y=fftyn; Y We have divided the transform by n in order that the first coefficient is equal to the arith- metic mean of the samples. When this code is executed, the results are displayed as ans = 5.0000 0.0000 - 0.0000i 0.5000 -0.0000 + 0.5000i -0.0000 - 0.5000i 0.5000 0.0000 + 0.0000i 0.02 0.04 0.06 0.08 0.1 0.12 0.14 2 4 6 a f t versus time s 6 8 10 12 14 16 18 20 22 24 26 ⫺0.5 0.5 b Real component versus frequency 6 8 10 12 14 16 18 20 22 24 26 ⫺0.5 0.5 c Imaginary component versus frequency Frequency Hz FIGURE 16.11 Results of computing a DFT with MATLAB’s fft function: a the sample; and plots of the b real and c imaginary parts of the DFT versus frequency. 16.6 THE POWER SPECTRUM 399 Notice that the first coefficient corresponds to the signal’s mean value. In addition, be- cause of the reverse-wrap-around order, the results can be interpreted as in the following table: Index k Frequency Period Real Imaginary 1 constant 5 2 1 6.25 0.16 3 2 12.5 0.08 0.5 4 3 18.75 0.053333 0.5 5 4 25 0.04 6 ⫺3 31.25 0.032 ⫺0.5 7 ⫺2 37.5 0.026667 0.5 8 ⫺1 43.75 0.022857 Notice that the fft has detected the 12.5- and 18.75-Hz signals. In addition, we have high- lighted the Nyquist frequency to indicate that the values below it in the table are redundant. That is, they are merely reflections of the results below the Nyquist frequency. If we remove the constant value, we can plot both the real and imaginary parts of the DFT versus frequency nyquist=fs2;fmin=1T; f = linspacefmin,nyquist,n2; Y1=[];YP=Y1:n2; subplot3,1,2 stemf,realYP,linewidth,2,MarkerFaceColor,blue grid;titleb Real component versus frequency subplot3,1,3 stemf,imagYP,linewidth,2,MarkerFaceColor,blue grid;titleb Imaginary component versus frequency xlabelfrequency Hz As expected recall Fig. 16.7, a positive peak occurs for the cosine at 12.5 Hz Fig. 16.11b, and a negative peak occurs for the sine at 18.75 Hz Fig. 16.11c.

16.6 THE POWER SPECTRUM

Beyond amplitude and phase spectra, power spectra provide another useful way to discern the underlying harmonics of seemingly random signals. As the name implies, it derives from the analysis of the power output of electrical systems. In terms of the DFT, a power spectrum consists of a plot of the power associated with each frequency component versus frequency. The power can be computed by summing the squares of the Fourier coefficients: P k = | ˜c k | 2 where P k is the power associated with each frequency kω . EXAMPLE 16.4 Computing the Power Spectrum with MATLAB Problem Statement. Compute the power spectrum for the simple sinusoid for which the DFT was computed in Example 16.3. Solution. The following script can be developed to compute the power spectrum: compute the DFT clc;clf n=8; dt=0.02; fs=1dt;tspan=0:n-1fs; y=5+cos2pi12.5tspan+sin2pi18.75tspan; Y=fftyn; f = 0:n-1fsn; Y1=[];f1=[]; compute and display the power spectrum nyquist=fs2; f = 1:n2n2nyquist; Pyy = absY1:n2.2; stemf,Pyy,linewidth,2,MarkerFaceColor,blue titlePower spectrum xlabelFrequency Hz;ylim[0 0.3] As indicated, the first section merely computes the DFT with the pertinent statements from Example 16.3. The second section then computes and displays the power spectrum. As in Fig. 16.12, the resulting graph indicates that peaks occur at both 12.5 and 18.75 Hz as expected. 6 8 26 10 12 14 16 18 20 22 24 0.05 0.1 0.15 0.2 0.25 Power spectrum Frequency Hz FIGURE 16.12 Power spectrum for a simple sinusoidal function with frequencies of 12.5 and 18.75 Hz.