Finite Length Discrete Fourier Transform Discrete Fourier Transform (DFT) Usually, we do not have an infinite amount of data which is required by the DTFT. Instead, we have 1 image, a segment of speech, etc. Also, most realworld data are not of the convenient form an u[n]. Finally, on a computer, we can not calculate an uncountably infinite (continuum) of frequencies as required by the DTFT. ACTUAL DATA ANALYSIS on a computer- Use a DFT to look at a finite segment of data. In our development in the previous section of x[n] periodic with x0 [n] the part of the signal that was repeated, we could have assumed that our finite segment of data came from “windowing” an infinite length sequence x[n] x0 [n] = x[n]wR [n] where wR [n] is a rectangular window: 1 wR [n] = ! 1, n = 0, 1, · · · , N − 1 0, otherwise x0 [n] = x[n]wR [n] is just the samples of x[n] between n = 0 and n = N − 1. x0 [n] is 0 everywhere else. Therefore, it is defined ∀n, and we can take its DTFT: X0 (Ω) = DTFT(x0 [n]) = ∞ " −jΩn x0 [n]e = n=−∞ ∞ " −jΩn x[n]wR [n]e n=−∞ = N −1 " x[n]e−jΩn n=0 So, X0 (Ω) = N −1 " x[n]e−jΩn = n=0 N −1 " x0 [n]e−jΩn n=0 as we saw before. Let’s say now that we want to sample X0 (Ω) (which is continuous and periodic with period 2π) so we store it on a computer. Sample X0 (Ω): Assume we want 8 points in frequency – then sample X0 (Ω) at 8 uniformly spaced points on the unit circle: Values of frequency are 0, π/4, π/2, · · · , 7π/4 or 2πk/8, k = 0, 1, · · · , 7. 2 If we let k = N, what happens? If k = N, we get repetition of the points we sampled so only N samples are unique. Define Discrete Fourier Transform (DFT) as X[k] = X0 ( 2πk ) N , k = 0, 1, . . . , N − 1, i.e. only look at the N distinct sampled for Ω = 2πk N frequencies of X0 (Ω). Significant Observations 1. The resolution of the samples of the frequency spectrum is 2π since we N sample the spectrum at points that are spaced 2π apart in frequency, N that is, ∆Ω = 2π . N 2. If we looked at the samples of X0 (Ω) for all k = −∞ to ∞ for frequencies 2πk , we would get the closely related Discrete Fourier Series (DFS) N which is of course periodic with period N since X0 (Ω) is periodic. 3. If x is a periodic signal with period N, as we saw that DFS was sufficient to construct the DTFT of the signal. In other words, the DFT procedure approximates a signal with a periodic approximation of itself. Now X[k] = X0 (Ω)|Ω = = = N −1 " n=0 N −1 " 2πk , k = 0, 1, · · · , N − 1 N x[n]e−jΩn |Ω= 2πk ,k=0,1,···,N −1 N x[n]e−j 2πkn N n=0 , k = 0, 1, · · · , N − 1 Shorthand Notation for the DFT: 2π Let WN = e−j N ⇒ N th root of unity (WNN = 1) since WNN = e−j2π = 1. You may also write WN simply as W . Then X[k] = N −1 " n=0 x[n]WNkn , k = 0, 1, · · · , N − 1 is the DFT of your windowed sequence x0 [n]. 3 Ex. Find N −1 " (e −j2πk N )n = n=0 N −1 " W kn n=0 This is just the DFT of x[n] = 1, n = 0, 1, · · · , 7. 4 Ex. x[n] = ! 1, n=0 0, n = 1, . . . , 7 Find X[k], k = 0, 1, . . . , 7. 5 Given y[n] = δ[n − 2] and N = 8, find Y [k]. 6 Ex. x[n] = cWN−pn , n = 0, 1, . . . , N − 1, 2π p is an integer with p ∈ [0, 1, . . . , N − 1] and WN = e−j N (as usual), find its DFT. 7 Synthesis: INVERSE DFT How can we recover x[n] from X[k]? Synthesis formula is x[n] = −1 1 N" X[k]WN−kn , n = 0, 1, . . . , N − 1 N k=0 Prove this gives back x[n]: x[n] = = −1 −1 N " 1 N" x[l]WNkl WN−kn N k=0 l=0 −1 N −1 " 1 N" k(l−n) x[l] WN N l=0 k=0 Ex. N −1 " k(l−n) WN k=0 8 =? ORTHOGONALITY OF EXPONENTIALS AGAIN! So, N −1 " k(l−n) WN = k=0 ! N, l = n 0, l = ̸ n and −1 N −1 −1 " 1 N" 1 N" k(l−n) x[l] WN = x[l]Nδ[n − l] N l=0 N l=0 k=0 1 (Nx[n]) = x[n] = N x[n] = Ex. Find the IDFT of X[k] = 1, k = 0, 1, . . . , 7. 9 Ex. Given x[n] = δ[n] + 2δ[n − 1] + 3δ[n − 2] + δ[n − 3] and N = 4, find X[k]. 10 Ex. Given X[k] = 2δ[k] + 2δ[k − 2] and N = 4, find x[n]. 11 Selected DFT Properties 1. Linearity. ax1 [n] + bx2 [n] ↔ aX1 [k] + bX2 [k] 2. Time shift. x[n − n0 ]mod N ↔ WNkn0 X[k] 3. Frequency shift. WN−nk0 x[n] ↔ X[k − k0 ]mod N 4. Multiplication. x1 [n]x2 [n] ↔ 1 X1 [k] ⊗ X2 [k] N 5. Circular convolution. x1 [n] ⊗ x2 [n] ↔ X1 [k]X2 [k] 6. Real/Even. x[n] = xe [n] + xo [n] ↔ X[k] = A[k] + jB[k] xe [n] ↔ A[k] xo [n] ↔ jB[k] If x[n] is real, then X[−k]mod N = X ∗ [k]. If x[n] is even, then X[k] is real. (For a finite length function to be even, x[n] = x[−n]mod N ) 12 Fast Fourier Transform The work of Cooley and Tukey showed how to calculate the DFT with complexity N log N (called the Fast Fourier Transform) instead of complexity N 2 using the direct algorithm. The fft command that you use in MATLAB implements a Fast Fourier Transform. Examine: X[k] = N −1 " x[n]W kn n=0 There are approximately N 2 complex multiplications and additions required to implement this (N for each value of X[k]). If N = 210 = 1024, then N 2 = 220 = 106 , a very large number! However, the FFT would only require about 5000, a substantial savings in complexity (the actual calculation is N2 log2 N). There are a number of different FFT algorithms that exist including decimation-in-time and decimation-in-frequency. The primary idea is to split up the size-N DFT into each. N 2 DFTs of length 2 You split the sum into 2 subsequences of length N2 and continue all the way down until you have N2 subsequences of length 2. 13 First break x[n] into even and odd subsequences: " X[k] = x[n]W kn + neven " x[n]W kn nodd Now let n = 2m for even numbers and n = 2m + 1 for odd numbers: N 2 X[k] = −1 " x[2m]W 2mk N 2 + m=0 N 2 −1 " −1 " x[2m + 1]W k(2m+1) = m=0 2 mk x[2m](W ) +W m=0 k N 2 −1 " x[2m + 1](W 2 )mk = m=0 Xe [k] + W k Xo [k] Xe [k] and Xo [k] are both the DFT of a N 2 point sequence. W k is often referred to as the “twiddle factor.” Now break up the size N 4 Xe [k] = −1 " N 2 subsequences in half by letting m = 2p: 4 kp x[4p](W ) +W p=0 2k N 4 −1 " x[4p + 2](W 4 )kp = p=0 The first subsequence here is the terms x[0], x[4], . . . and the second is x[2], x[6], . . . . 14 Also, we have that: N WN2 = −1 Y [k] = 1 " y[n]W2kn = y[0] + W2k y[1] n=0 W2 = e− j2π 2 = e−jπ = −1 So we get, Y [k] = y[0] + (−1)k y[1] and: Y [0] = y[0] + y[1] Y [1] = y[0] − y[1] 15 Ex. This was a problem I had on a DSP final exam in 1984: Express the DFT of the 9-point sequence {x[0], x[1], . . . , x[8]} in terms of the DFTs of 3-point sequences {x[0], x[3], x[6]}, {x[1], x[4], x[7]}, and {x[2], x[5], x[8]} We start with: X[k] = 2 " m=0 x[3m]W93mk + 2 " (3m+1)k x[3m + 1]W9 m=0 + 2 " m=0 16 (3m+2)k x[3m + 2]W9 Applications of the DFT Linear Convolution You can use an FFT in MATLAB to compute linear convolution. If you don’t use a sufficient number of points in the DFT, you will get overlap. CIRCULAR CONVOLUTION Since DFTs are a limited length sequence, convolution is done mod N ⇒ circular convolution. x1 [n] ⊗ x2 [n] = N −1 " p=0 x1 [p]x2 [n − p]mod N That is, when we flip and shift the sequence x2 [n], we do it mod N. Also, note that: x1 [n] ⊗ x2 [n] ↔ X1 [k]X2 [k] 17 Ex. Find x1 [n] ⊗ x2 [n] = z[n]. 18 Ex. N = 8, find x1 [n] ⊗ x2 [n] = y[n]. 19 Ex. Find y[n] = x[n] ⊗ x[n]. 20 Overview of Chapters 3, 4, and 5 Fourier Analysis for Discrete-Time Signals 1. DTFT for infinite length sequences: continuous frequency, periodic with period 2π, X(Ω) = " x[n]e−jΩn n Important: DT convolution ↔ multiplication of DTFTs. Inverse system: h[n] ∗ hi [n] = δ[n] ↔ H(Ω)Hi (Ω) = 1 2. DTFT of a periodic DT sequence by allowing impulses in frequency: x[n] = " k ak ejΩk n ↔ 2π where ak = X0 ( " k ak δ(Ω − Ωk ) 2πk ) N 3. DFT for a finite length data discrete frequency Take DTFT of windowed infinite length sequence and then sample at discrete frequencies, Ω= 2πk , k = 0, 1, . . . , N − 1 N N discrete frequencies since exponential is periodic. X[k] = N −1 " x[n]e−j n=0 2πkn N = N −1 " n=0 Orthogonality of Exponentials: N −1 " WNkn = Nδ[k] n=0 21 x[n]WNkn