Lecture 7 - The Discrete Fourier Transform 7.1 The DFT The Discrete Fourier Transform (DFT) is the equivalent of the continuous Fourier Transform for signals known only at instants separated by sample times (i.e. a finite sequence of data). Let be the continuous signal which is the source of the data. Let samples . be denoted The Fourier Transform of the original signal, , would be "!$#%'& (*) +/102,3 , . + ) We could regard each sample as an impulse having area 45 . Then, since the integrand exists only at the sample points: 6!$#%7& & (98;: =+ <>;? +/A02B3 @ 8;: CD- +/EGF D- +/10H?IF F D- +/10J?IF H- +/A0 +=<>;? ie. "!$#%K& : L +=< JNMOE D- +/10J? We could in principle evaluate this for any # , but with only data points to start with, only final outputs will be significant. You may remember that the continuous Fourier transform could be evaluated QP over a finite interval (usually the fundamental period @ ) rather than from to 82 F P if the waveform was periodic. Similarly, since there are only a finite number of input data points, the DFT treats the data as if it were periodic (i.e. to S H is the same as R to H .) Hence the sequence shown below in Fig. 7.1(a) is considered to be one period of the periodic sequence in plot (b). (a) 1 0.8 0.6 0.4 0.2 0 0 1 2 3 4 5 6 7 8 9 10 11 (b) 1 0.8 0.6 0.4 0.2 0 0 5 10 15 &TU Figure 7.1: (a) Sequence of 20 25 30 samples. (b) implicit periodicity in DFT. Since the operation treats the data as if it were periodic, we evaluate the < DFT VXW equation for the fundamental frequency (one cycle per sequence, : ? Hz, : ? rad/sec.) and its harmonics (not forgetting the d.c. component (or average) at #Y&Z ). i.e. set #Y&Z[ H\ \ S] ^ \ ]`_ \ S] or, in general _ & : L +=< JaMOE ec f J D- + /$bdg 83 Z & ih _ S H U _ is the Discrete Fourier Transform of the sequence . We may write this equation in matrix form as: jkk C kk kl .. . S where p mnn jkk n & lk nn o kk kk p V p pvq p u p .. . V p q r p u r p w r pts Tp Tp Tp V p : +=< p : + p : + q V &Zxy[z{ !\}| and p &Zp : etc. ~ & . m nn +=< nn : + V nn : + q n o p : jkk mnn C kk kl .. . nn n o DFT – example Let the continuous signal be @ F K& F $UH\ O \ dc 2Hz 1Hz 10 8 6 4 2 0 −2 −4 0 1 2 3 4 5 6 7 8 9 10 Figure 7.2: Example signal for DFT. Let us sample at 4 times per second (ie. values of the discrete samples are given by: W @ F &t F $5 V $\{ 84 = 4Hz) from &r to & by putting &r& J s s q . The i.e. &t , & , &t , &Z Therefore jkkl mn kjlk C n & o _ & , &ZR L q L q d- + /c b f J & A ! f J E JNMOE ! ! mnn kjlk m n kjlk m n C n $ n & R! ! o o H o ! !R The magnitude of the DFT coefficients is shown below in Fig. 7.3. 20 |F[n]| 15 10 5 0 0 1 2 3 f (Hz) Figure 7.3: DFT of four point sequence. Inverse Discrete Fourier Transform The inverse transform of _ & : L +=< JaMOE d- +/bdegc f J 85 is : =+ < L f MOE 4& : i.e. the inverse matrix is ric) matrix. < _ D-U / bdec f J times the complex conjugate of the original (symmet- Note that the coefficients are complex. We can assume that the 4 values _ are real (this is the simplest case; there are situations (e.g. radar) in which two inputs, at each , are treated as a complex pair, since they are the outputs from o and o demodulators). and (reIn the process of taking the inverse transform the terms :V _ _ member that the spectrum is symmetrical about ) combine to produce frequency components, only one of which VXW is considered to: be valid (the one at the V ; the higher frequency Hz where lower of the two frequencies, :V _ _*] ? component is at an “aliasing frequency” ( )). _¡ From the inverse transform formula, the contribution to of is: f & £ _ S For all real 8: - + /bde c + f ¦> J & But i.e. S _ & ª© e c f J¤F D- / bdg _ _ & VXW - + / J 1 for all : L +=< JaMOE _ _ and 8;: D- / bde c + f >"J¥ 8 : D- +/bde c + f >¦J ec f J - $/ bdec¨§ J &Z- $/ bdg (i.e. the complex conjugate) 86 ¢ _ (7.2) Substituting into the Equation for f 4& f above gives, J F © .- +/ bdegc f JH¥ d- / db egc f ¤ _ _ £ f & ie. £«¬£ _ ¥ \ i.e. a sampled sinewave at For the special case of contribution of C to nent. VXW f : ? Hz, of magnitude 2. 3. implies a d.c. value of ª© V {& R! ¸ V & : ± ¦ ± & s ] ª&r i.e. _ &ºH component V & \ ¥ ¨¯6° \ _ _ ¥ d ¥ V : ± _ ± : < VE &r s C& (as expected) implies a fundamental component of peak amplitude ²³¨´ & ¹ o with phase given by : & V _ VXW - / J &T &µ , &S¶· 4 (i.e. sum of all samples) and the _ 4 is E ¤& : < & average of ¤& d.c. compo- Interpretation of example C&r$ £ \ f & T± F²$³¨´ ± £ _ _ or 1. _ ­¦® since o ¤&tKU – no other e c »V J & D- / bd¼ S _ \ Y o component here) and this implies a W 4Hd- / J & \{ since ¨¯D°\{i&t for all 87 (as expected) (as expected) 6 5 |F[n]| 4 3/sqrt(2) 3 sqrt(2) 2 1 0 0 1 f (Hz) 2 3 Figure 7.4: DFT of four point signal. Thus, the conventional way of displaying a spectrum is not as shown in Fig. 7.3 but as shown in Fig. 7.4 (obviously, the information content is the same): In typical applications, is much greater than ; for example, for UR , UR are the complex conjugates of&½ has U components, but ^ ^ $ , V V EV À < À A < < À _ leaving <B¾E ¿ as the d.c. component, <BE V ¾Â ¿ V to <BE V ¾Â ¿ à V as complete a.c. com- s ponents and frequency _ < <BE V s & <VÀ ¾Â ¿ à V :V . s{Á Á sGÁ Á as the cosine-only component at the highest distinguishable fÀ fÀb Most computer programmes evaluate ¾: ¿ (or ¾: ¿ for the power spectral denÁ Á Á Á sity) which gives the correct “shape” for the spectrum, except for the values at : &Z and V . _ 7.2 Discrete Fourier Transform Errors To what degree does the DFT approximate the Fourier transform of the function underlying the data? Clearly the DFT is only an approximation since it provides only for a finite set of frequencies. But how correct are these discrete values themselves? There are two main types of DFT errors: aliasing and “leakage”: 88 7.2.1 Aliasing This is another manifestation of the phenomenon which we have now encountered several times. If the initial samples are not sufficiently closely spaced to represent high-frequency components present in the underlying function, then the DFT values will be corrupted by aliasing. As before, the solution is either to increase the sampling rate (if possible) or to pre-filter the signal in order to minimise its highfrequency spectral content. 7.2.2 Leakage Recall that the continuous Fourier transform of a periodic waveform requires the P F P or over an integer number integration to be performed over the interval - to of cycles of the waveform. If we attempt to complete the DFT over a non-integer number of cycles of the input signal, then we might expect the transform to be corrupted in some way. This is indeed the case, as will now be shown. Consider the case of an input signal which is a sinusoid with a fractional num: ber of cycles in the data samples. The DFT for this case (for &Ä to & V ) _ _ is shown below in 7.5. 8 |F[n]| 6 4 2 0 0 2 4 freq 6 8 Figure 7.5: Leakage. We might have expected the DFT to give an output at just the quantised frequen89 cies either side of the true frequency. This certainly does happen but we also find non-zero outputs at all other frequencies. This smearing effect, which is known as leakage, arises because we are effectively calculating the Fourier series for the waveform in Fig. 7.6, which has major discontinuities, hence other frequency components. 1 0.5 0 −0.5 −1 0 5 10 15 20 25 30 35 40 45 50 Figure 7.6: Leakage. The repeating waveform has discontinuities. Most sequences of real data are much more complicated than the sinusoidal sequences that we have so far considered and so it will not be possible to avoid introducing discontinuities when using a finite number of points from the sequence in order to calculate the DFT. The solution is to use one of the window functions which we encountered in the design of FIR filters (e.g. the Hamming or Hanning windows). These window functions taper the samples towards zero values at both endpoints, and so there is no discontinuity (or very little, in the case of the Hanning window) with a hypothetical next period. Hence the leakage of spectral content away from its correct location is much reduced, as in Fig 7.7. (a) (b) 7 5 6 4 5 4 3 3 2 2 1 1 0 0 2 4 6 0 8 0 2 4 6 Figure 7.7: Leakage is reduced using a Hanning window. 90 8 7.3 The Fast Fourier Transform The time taken to evaluate a DFT on a digital computer depends principally on the number of multiplications involved, since these V are the slowest operations. With the DFT, this number is directly related to (matrix multiplication of a vector), where is the length of the transform. For most problems, is chosen to be at least 256 in order to get a reasonable approximation for the spectrum of the sequence under consideration – hence computational speed becomes a major consideration. Highly efficient computer algorithms for estimating Discrete Fourier Transforms have been developed since the mid-60’s. These are known as Fast Fourier Transform (FFT) algorithms and they rely on the fact that the standard DFT involves a lot of redundant calculations: Re-writing _ & : L +=< JaMOE D- +/ bde c f J as _ & : L +=< J JNMOE dp : f J it is easy to realise that the same values of p : f are calculated many times as the computation proceeds. Firstly, the integer product repeats for different comJ _ binations of and ; secondly, p : f is a periodic function with only distinct _ values. For example, consider of 2) &9 (the FFT is simplest by far if is an integral power ! < + / + / b d c Æ Å p &t& - s ÃXÇ & È t & É= say Z V © Then É & ! ÉRq& !5Éi& É És & © Éà & É É u &Ê! É5Ë%&Ê!5ÉÌ&9É From the above, it can be seen that: 91 Å É ~ & ptÅ s p Åà p Åu pvÅ Ë Also, if _ & p ÅE & p Å V< & p Å & pvÅ q falls outside the range 0-7, we still get one of the above values: eg. if _ &t and i&rÍ^ Å p Å q à &tÉ q à &ºÉ sÎ É q &tÉ q 7.3.1 Decimation-in-time algorithm Let us begin by splitting the single summation over samples into 2 summations, : each with V samples, one for even and the other for odd. J J+=V < for odd and write: Substitute ÏS& V for even and ÏS& e =+ < Lb VÐ 8 V Ð < > 4ϸdp : f F Ï F dp : f & _ Ð OM E Ð MOE e =+ < Lb Note that + / bde c Ð f VÐ f Ð 8V Ð f > + / d b c e & - b 9 p : t & &rp e f b e =+ < Lb e =+ < Ð Ð Lb Ð & 4ϸdp e f F p : Ï F dp e f _ b b Ð OM E Ð MOE Therefore ie. _ &tÑÒ _ Ð F p :i Ó _ : Thus the -point DFT can be obtained from two V -point transforms, _ one on even input data, ÑÒ , and one on odd input data, Ó . Although the fre: _ _ quency index ranges over values, only V values of ÑÒ and Ó need to be : _ _ _ V computed since ÑÔ and Ó are periodic in with period . _ For example, for _ &9 _ : 92 Õ Õ even input data dÖ$ odd input data &tÑÒ ¦&tÑÒ¦ 4H&tÑÒ4 &tÑÒ C&tÑÒ 4H&tÑÒ¦ ×&tÑÒ4 4ÍH&tÑÒ F p ÅE Ó F p Å< Ó F p ÅV Ó F prÅ q Ó F ptÅ s Ó F p Å Ó F p Å Ãu Ó F pvÅ Ë Ó × ¦d d4H Í C C&tÑÒC &tÑÒ ÑÒ &&t tÑÒ ÅE p Å< Ó p ÅV Ó p Å Ó prq Ó C This is shown graphically on the flow graph of Fig 7.8: G[0] f[0] f[2] f[4] f[6] N/2 point DFT f[1] f[3] f[5] f[7] N/2 point DFT F[0] G[3] H[0] F[7] H[3] Figure 7.8: FFT flow graph 1. Assuming than is a power of , we can repeat the above process on the two :V : -point transforms, breaking them down to -point transforms, etc , until we come down to -point transforms. For &s , only one further stage is needed (i.e. there are Ø stages, where &ZHÙ ), as shown below in Fig 7.9. Thus the FFT is computed by dividing up, or decimating, the sample sequence into sub-sequences until only -point DFT’s remain. Since it is the input, or time, samples which are divided up, this algorithm is known as the decimationin-time (DIT) algorithm. (An equivalent algorithm exists for which the output, or frequency, points are sub-divided – the decimation-in-frequency algorithm.) The basic computation at the heart of the FFT is known as the butterfly because of its criss-cross appearance. For the DIT FFT algorithm, the butterfly computation is of the form of Fig 7.10 93 f[0] f[4] f[2] f[6] f[1] f[5] f[3] f[7] F[0] N/4 point DFT N/4 point DFT N/4 point DFT N/4 point DFT F[7] Figure 7.9: FFT flow graph 2. Ú Ú F Û p*: Ü R à á Ý Þ Þ à Þ Þ à à à Þ Þ à Þ Þ à à à Þà àÞ Þ Þ F p :Ü à à à Þ Þ à à Þ Þ à à Þ Þ RÞ ß Ú Ü p : Û à Û Ý p :Ü * Figure 7.10: Butterfly operation in FFT. Ú Û where and are complex numbers. Thus a butterfly computation requires one complex multiplication and 2 complex additions. Note also, that the input samples are “bit-reversed” (see table below) because at each stage of decimation the sequence input samples is separated into even- and odd- indexed samples. (NB: the bit-reversal algorithm only applies if 94 is an integral power of ). Index [ 0 1 2 3 4 5 6 7 Binary Bit-reversed Bit-reversed representation Binary index 000 000 0 001 100 4 010 010 2 011 110 6 100 001 1 101 101 5 110 011 3 111 111 7 7.3.2 Computational speed of FFT V complex multiplications. At each stage of the FFT (i.e. The DFT requires :V each halving) complex multiplications are required to combine the results of the previous stage. Since there are BâBUã V stages, the number of complex multiplications required to evaluate an -point DFT with the FFT is approximately e E because multiplications by factors such as p : , p : b |e ä âBUã V (approximately äe p : and pµ: å are really just complex additions and subtractions). V 32 256 1,024 (DFT) 1,024 65,536 1,048,576 :V , â,Uã V (FFT) saving 80 92 æ 1,024 98 æ 5,120 99.5 æ 7.3.3 Practical considerations If is not a power of , there are 2 strategies available to complete an FFT. -point 1. take advantage of such factors as possesses. For example, if is divisi ble by (e.g. &ÄR ), the final decimation stage would include a -point transform. 95 2. pack the data with zeroes; e.g. include 16 zeroes with the 48 data points (for &vR ) and compute a ×$ -point FFT. (However, you should again be wary of abrupt transitions between the trailing (or leading) edge of the data and the following (or preceding) zeroes; a better approach might be to pack the data with more realistic “dummy values”). 96