DSP applications using C and the TMS320C6X DSK (P6)

34 473 0
DSP applications using C and the TMS320C6X DSK (P6)

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

6 Fast Fourier Transform 182 • The fast Fourier transform using radix-2 and radix-4 • Decimation or decomposition in frequency and in time • Programming examples The fast Fourier transform (FFT) is an efficient algorithm that is used for convert- ing a time-domain signal into an equivalent frequency-domain signal, based on the discrete Fourier transform (DFT). Several real-time programming examples on FFT are included. 6.1 INTRODUCTION The discrete Fourier transform converts a time-domain sequence into an equivalent frequency-domain sequence. The inverse discrete Fourier transform performs the reverse operation and converts a frequency-domain sequence into an equivalent time-domain sequence. The fast Fourier transform (FFT) is a very efficient algo- rithm technique based on the discrete Fourier transform but with fewer computa- tions required. The FFT is one of the most commonly used operations in digital signal processing to provide a frequency spectrum analysis [1–6]. Two different procedures are introduced to compute an FFT: the decimation-in-frequency and the decimation-in-time. Several variants of the FFT have been used, such as the Winograd transform [7,8], the discrete cosine transform (DCT) [9], and the discrete Hartley transform [10–12]. Programs based on the DCT, FHT, and the FFT are avail- able in Ref. 9. DSP Applications Using C and the TMS320C6x DSK. Rulph Chassaing Copyright © 2002 John Wiley & Sons, Inc. ISBNs: 0-471-20754-3 (Hardback); 0-471-22112-0 (Electronic) 6.2 DEVELOPMENT OF THE FFT ALGORITHM WITH RADIX-2 The FFT reduces considerably the computational requirements of the discrete Fourier transform (DFT). The DFT of a discrete-time signal x(nT) is (6.1) where the sampling period T is implied in x(n) and N is the frame length. The constants W are referred to as twiddle constants or factors, which represent the phase, or (6.2) and is a function of the length N. Equation (6.1) can be written for k = 0,1, ., N - 1, as (6.3) This represents a matrix of N ¥ N terms, since X(k) needs to be calculated for N values for k. Since (6.3) is an equation in terms of a complex exponential, for each specific k there are (N - 1) complex additions and N complex multiplications. This results in a total of (N 2 - N) complex additions and N 2 complex multiplications. Hence, the computational requirements of the DFT can be very intensive, especially for large values of N. FFT reduces computational complexity from N 2 to NlogN. The FFT algorithm takes advantage of the periodicity and symmetry of the twiddle constants to reduce the computational requirements of the FFT. From the periodicity of W, W k+N = W k (6.4) and from the symmetry of W, (6.5) Figure 6.1 illustrates the properties of the twiddle constants W for N = 8. For example, let k = 2, and note that from (6.4), W 10 = W 2 , and from (6.5), W 6 =-W 2 . For a radix-2 (base 2), the FFT decomposes an N-point DFT into two (N/2)-point or smaller DFTs. Each (N/2)-point DFT is further decomposed into two (N/4)-point DFTs, and so on. The last decomposition consists of (N/2) two-point DFTs. The smallest transform is determined by the radix of the FFT. For a radix-2 FFT, N must be a power or base of 2, and the smallest transform or the last decomposition is the two-point DFT. For a radix-4, the last decomposition is a four-point DFT. WW kN k+ =- 2 Xk x x W x W xN W kk Nk () = () + () + () ++ - () - () 01 2 1 2 1 . We jN = - 2p Xk xnW k N nk n N () = () =- = - Â 0 1 01 1, , ., Development of the FFT Algorithm with Radix-2 183 184 Fast Fourier Transform 6.3 DECIMATION-IN-FREQUENCY FFT ALGORITHM WITH RADIX-2 Let a time-domain input sequence x(n) be separated into two halves: (a) (6.6) and (b) (6.7) Taking the DFT of each set of the sequence in (6.6) and (6.7) gives us (6.8) Let n = n + N/2 in the second summation of (6.8); X(k) becomes (6.9) where W kN/2 is taken out of the second summation because it is not a function of n. Using Wee j kN jk j k k k 2 1== () =- () =- () --pp ppcos sin Xk xnW W xn N W nk kN n N nk n N () = () ++ Ê Ë ˆ ¯ = () - = () - ÂÂ 2 0 21 0 21 2 Xk xnW xnW nk n N nk nN N () = () + () = () - = - ÂÂ 0 21 2 1 N x N xN 22 11 Ê Ë ˆ ¯ + Ê Ë ˆ ¯ - () , , ., xx x N 01 2 1 () () - Ê Ë ˆ ¯ , , ., W 3 = W 11 = … W 4 = W 12 = … W 0 = W 8 = … W 5 = W 13 = … W 7 = W 15 = … W 2 = W 10 = … W 6 = W 14 = … W 1 = W 9 = … FIGURE 6.1. Periodicity and symmetry of twiddle constant W. in (6.9), X(k) becomes (6.10) Because (-1) k = 1 for even k and -1 for odd k, (6.10) can be separated for even and odd k,or 1. For even k: (6.11) 2. For odd k: (6.12) Substituting k = 2k for even k, and k = 2k + 1 for odd k, (6.11) and (6.12) can be written for k = 0,1, .,(N/2) - 1 as (6.13) (6.14) Because the twiddle constant W is a function of the length N, it can be represented as W N . Then W 2 N can be written as W N/2 . Let (6.15) (6.16) Equations (6.13) and (6.14) can be written more clearly as two (N/2)-point DFTs, or (6.17) (6.18) Figure 6.2 shows the decomposition of an N-point DFT into two (N/2)-point DFTs, for N = 8. As a result of the decomposition process, the X’s in Figure 6.2 are even Xk bnWW n N N n N nk 21 0 21 2 + () = () = () - Â Xk anW n N N nk 2 0 21 2 () = () = () - Â bn xn xn N () = () -+ () 2 an xn xn N () = () ++ () 2 xk xn xn N WW n N nnk 21 2 0 21 2 + () = () -+ Ê Ë ˆ ¯ È Î Í ˘ ˚ ˙ = () - Â Xk xn xn N W n N nk 2 2 0 21 2 () = () ++ Ê Ë ˆ ¯ È Î Í ˘ ˚ ˙ = () - Â Xk xn xn N W n N nk () = () -+ Ê Ë ˆ ¯ È Î Í ˘ ˚ ˙ = () - Â 2 0 21 Xk xn xn N W n N nk () = () ++ Ê Ë ˆ ¯ È Î Í ˘ ˚ ˙ = () - Â 2 0 21 Xk xn xn N W k n N nk () = () +- () + Ê Ë ˆ ¯ È Î Í ˘ ˚ ˙ = () - Â 1 2 0 21 Decimation-in-Frequency FFT Algorithm with Radix-2 185 186 Fast Fourier Transform in the upper half and odd in the lower half. The decomposition process can now be repeated such that each of the (N/2)-point DFTs is further decomposed into two (N/4)-point DFTs, as shown in Figure 6.3, again using N = 8 to illustrate. The upper section of the output sequence in Figure 6.2 yields the sequence X(0) and X(4) in Figure 6.3, ordered as even. X(2) and X(6) from Figure 6.3 represent the odd values. Similarly, the lower section of the output sequence in Figure 6.2 yields X(1) and X(5), ordered as the even values, and X(3) and X(7) as the odd values. This scrambling is due to the decomposition process. The final order of the FIGURE 6.2. Decomposition of N-point DFT into two (N/2)-point DFTs, for N = 8. FIGURE 6.3. Decomposition of two (N/2)-point DFTs into four (N/4)-point DFTs, for N = 8. Decimation-in-Frequency FFT Algorithm with Radix-2 187 output sequence X(0), X(4), .in Figure 6.3 is shown to be scrambled. The output needs to be resequenced or reordered. Programming examples presented later in this chapter include the appropriate function for resequencing.The output sequence X(k) represents the DFT of the time sequence x(n). This is the last decomposition, since we now have a set of (N/2) two-point DFTs, the lowest decomposition for a radix-2. For the two-point DFT, X(k) in (6.1) can be written as (6.19) or X(0) = x(0)W 0 + x(1)W 0 = x(0) + x(1) (6.20) X(1) = x(0)W 0 + x(1)W 0 = x(0) - x(1) (6.21) since W 1 = e -j2p/2 =-1. Equations (6.20) and (6.21) can be represented by the flow graph in Figure 6.4, usually referred to as a butterfly. The final flow graph of an eight-point FFT algorithm is shown in Figure 6.5. This algorithm is referred as decimation-in-frequency (DIF) because the output sequence X(k) is decomposed (decimated) into smaller subsequences, and this process continues through M stages or iterations, where N = 2 M . The output X(k) is complex with both real and imagi- nary components, and the FFT algorithm can accommodate either complex or real input values. The FFT is not an approximation of the DFT. It yields the same result as the DFT with fewer computations required. This reduction becomes more and more important with higher-order FFT. There are other FFT structures that have been used to illustrate the FFT. An alternative flow graph to that in Figure 6.5 can be obtained with ordered output and scrambled input. An eight-point FFT is illustrated through the following exercise. We will see that flow graphs for higher-order FFT (larger N) can readily be obtained. Xk xnW k nk n () = () = = Â 0 1 01, FIGURE 6.4. Two-point FFT butterfly. 188 Fast Fourier Transform Exercise 6.1: Eight-Point FFT Using Decimation-in-Frequency Let the input x(n) represent a rectangular waveform, or x(0) = x(1) = x(2) = x(3) = 1 and x(4) = x(5) = x(6) = x(7) = 0. The eight-point FFT flow graph in Figure 6.5 can be used to find the output sequence X(k), k = 0,1, .,7.With N = 8, four twiddle constants need to be calculated, or W 0 = 1 The intermediate output sequence can be found after each stage. Stage 1 x(0) + x(4) = 1 Æ x¢(0) x(1) + x(5) = 1 Æ x¢(1) x(2) + x(6) = 1 Æ x¢(2) x(3) + x(7) = 1 Æ x¢(3) [x(0) - x(4)]W 0 = 1 Æ x¢(4) [x(1) - x(5)]W 1 = 0.707 - j0.707 Æ x¢(5) [x(2) - x(6)]W 2 =-j Æ x¢(6) [x(3) - x(7)]W 3 =-0.707 - j0.707 Æ x¢(7) We j j 3 68 0 707 0 707==-- -p We j j 2 48 ==- -p We j j j 1 28 4 4 0 707 0 707== () - () =- -p ppcos sin . . FIGURE 6.5. Eight-point FFT flow graph using decimation-in-frequency. where x¢(0), x¢(1), .,x¢(7) represent the intermediate output sequence after the first iteration, which becomes the input to the second stage. Stage 2 x¢(0) + x¢(2) = 2 Æ x≤(0) x¢(1) + x¢(3) = 2 Æ x≤(1) [x¢(0) - x¢(2)]W 0 = 0 Æ x≤(2) [x¢(1) - x¢(3)]W 2 = 0 Æ x≤(3) x¢(4) + x¢(6) = 1 - j Æ x≤(4) x¢(5) + x¢(7) = (0.707 - j0.707) + (-0.707 - j0.707) = -j1.41 Æ x≤(5) [x¢(4) - x¢(6)]W 0 = 1 + j Æ x≤(6) [x¢(5) - x¢(7)]W 2 =-j1.41 Æ x≤(7) The resulting intermediate, second-stage output sequence x≤(0), x≤(1), ., x≤(7) becomes the input sequence to the third stage. Stage 3 X(0) = x≤(0) + x≤(1) = 4 X(4) = x≤(0) - x≤(1) = 0 X(2) = x≤(2) + x≤(3) = 0 X(6) = x≤(2) - x≤(3) = 0 X(1) = x≤(4) + x≤(5) = (1 - j) + (-j1.41) = 1 - j2.41 X(5) = x≤(4) - x≤(5) = 1 + j0.41 X(3) = x≤(6) + x≤(7) = (1 + j) + (-j1.41) = 1 - j0.41 X(7) = x≤(6) - x≤(7) = 1 + j2.41 We now use the notation of X’s to represent the final output sequence. The values X(0), X(1), ., X(7) form the scrambled output sequence. These results can be verified with MATLAB, described in Appendix D. We show later how to reorder the output sequence and plot the output magnitude. Exercise 6.2: Sixteen-Point FFT Given x(0) = x(1) = .= x(7) = 1, and x(8) = x(9) = .x(15) = 0, which represents a rectangular input sequence. The output sequence can be found using the 16-point flow graph shown in Figure 6.6. The intermediate output results after each stage are found in a manner similar to that in Exercise 6.1. Eight twiddle constants W 0 , W 1 , .,W 7 need to be calculated for N = 16. Verify the scrambled output sequence X’s as shown in Figure 6.6. Reorder this output sequence and take its magnitude. Verify the plot in Figure 6.7, which Decimation-in-Frequency FFT Algorithm with Radix-2 189 stage 1 stage 2 stage 3 stage 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 8 0 0 0 0 0 0 0 4 4 0 0 0 0 0 0 0 2 2 2 2 0 0 0 0 0 0 0 x(0) x(1) x(2) x(3) x(4) x(5) x(6) x(7) x(8) x(9) x(10) x(11) x(12) x(13) x(14) x(15) W 1 W 2 W 2 W 4 W 6 W 2 W 4 W 4 W 4 W 4 W 4 W 6 W 3 W 4 W 5 W 6 W 7 0.923 - j 0.38 0.707 - j 0.707 -0.707 - j 0.707 0.38 - j 0.92 -0.38 - j 0.92 -j -0.92 - j 0.38 -1.3 - j 0.54 -0.54 - j 1.3 0.54 - j 1.3 -j 2.61 -j 2.61 1.3 - j 0.54 1 + j 1 - j 1 - j 2.41 1 + j 2.41 1 + j 0.41 1 + j 0.2 1 - j 0.2 1 + j 1.496 1 - j 1.496 1 - j 0.41 1 - j 5.028 1 + j 5.028 X(15) X(7) X(11) X(3) X(13) X(5) X(9) X(1) X(14) X(6) X(10) X(2) X(12) X(4) X(8) X(0) 1 - j 0.668 1 + j 0.668 - j 1.41 - j 1.08 - j 1.08 - j 1.41 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 FIGURE 6.6. Sixteen-point FFT flow graph using decimation-in-frequency. 190 Decimation-in-Time FFT Algorithm with Radix-2 191 represents a sinc function. The output X(8) represents the magnitude at the Nyquist frequency. These results can be verified with MATLAB, described in Appendix D. 6.4 DECIMATION-IN-TIME FFT ALGORITHM WITH RADIX-2 Whereas the decimation-in-frequency (DIF) process decomposes an output se- quence into smaller subsequences, the decimation-in-time (DIT) is a process that decomposes the input sequence into smaller subsequences. Let the input sequence be decomposed into an even sequence and an odd sequence, or x(0), x(2), x(4), .,x(2n) and x(1), x(3), x(5), .,x(2n + 1) We can apply (6.1) to these two sequences to obtain (6.22) Using W 2 N = W N/2 in (6.22) yields (6.23) which represents two (N/2)-point DFTs. Let Xk xnW W xn W N nk N k N nk n N n N ()= () ++ () = () - = () - ÂÂ 221 22 0 21 0 21 Xk x nW x n W nk nk n N n N ()= () ++ () + () = () - = () - ÂÂ 221 2 21 0 21 0 21 FIGURE 6.7. Output magnitude for 16-point FFT. [...]... signal It calls a generic FFT function in C, FFT .c (on the accompanying disk) This FFT function, used with the C3 1 DSK and the C3 0 EVM, is listed and described in Refs 13 and 14 The twiddle constants are generated within the program The imaginary components of the input data are set to zero to illustrate this implementation The magnitude of the resulting FFT (scaled) is taken for output to the codec Three... represents the sampling frequency Fs The location of the first positive spike then corresponds to a frequency of 2 kHz (the mid-distance between the two spikes corresponds to 4 kHz) The location of the second positive spike corresponds to the folding frequency of Fs - f = 6 kHz Increase the frequency of the input signal and observe the convergence of the two spikes toward the 4-kHz Nyquist frequency Example... test the results: 1 Select View Æ Watch Window and insert the two expressions j and out (right click on the Watch window) Click on +out to expand and view out[0] and out[1] that represent the real and imaginary components, respectively 2 Place a breakpoint at the bracket “}” that follows the DFT function call 3 Select Debug Æ Animate (Animation speed can be controlled through Options) Verify that the. .. REFERENCES 1 J W Cooley and J W Tukey, An algorithm for the machine calculation of complex Fourier series, Mathematics of Computation, Vol 19, 1965, pp 297–301 2 J W Cooley, How the FFT gained acceptance, IEEE Signal Processing, Jan 1992, pp 10–13 References 215 3 J W Cooley, The structure of FFT and convolution algorithms, from a tutorial, IEEE 1990 International Conference on Acoustics, Speech, and. .. purposes of clarity Alternative Version for Simulation The program fastconvosim .c (on the accompanying disk) is a non-real-time version of the program fastconvo .c, which processes a prestored sequence of input samples Using breakpoints (locations specified within the program), the user can step through the various stages in the overlap-add process, viewing the contents of each of the buffers at each step... the low- and high-frequency components are accentuated while the midrange frequency components are attenuated This is because the filter coefficients are scaled in the program by bass_gain and treble_gain, initially set to 1, and by mid_gain, initially set to zero The slider file graphicEQ.gel (on the disk) allows you to control the three frequency bands independently Figure 6.20 shows the output spectrum... to the 2’scomplement format of the AD535 codec and a dc offset of approximately 1.1 V) It is used as a reference scheme The input data are scaled so that the output magnitude is positive (again due to the codec data format) The sampling rate is achieved through polling Build and run this project as FFTsinetable The two support files for bit reversal and the complex FFT function also are included in the. .. Experiments Using C and the TMS32 0C3 1 DSK, Wiley, New York, 1999 14 R Chassaing, Digital Signal Processing with C and the TMS32 0C3 0, Wiley, New York, 1992 15 P M Embree and B Kimble, C Language Algorithms for Digital Signal Processing, Prentice Hall, Upper Saddle River, NJ, 1990 16 S Kay and R Sudhaker, A zero crossing spectrum analyzer, IEEE Transactions on Acoustics, Speech, and Signal Processing, Vol... program using TI’s floating-point FFT functions (graphicEQ .c) 212 for (i=0; i . It calls a generic FFT func- tion in C, FFT .c (on the accompanying disk). This FFT function, used with the C3 1 DSK and the C3 0 EVM, is listed and described. discrete Hartley transform [10–12]. Programs based on the DCT, FHT, and the FFT are avail- able in Ref. 9. DSP Applications Using C and the TMS32 0C6 x DSK.

Ngày đăng: 07/11/2013, 10:15

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan