1 VII. Discrete Fourier Transform (DFT) Chapter-8 A. Modulo Arithmetic (n) N is n modulo N, n is an integer variable. (n) N = n m N 0 n m N N-1, pick m Ex. (k) 4 W N = e -j2π/n
2 Note that W N k = 0 but W N mk = N if m is a multiple of N but 0, elsewhere Theorem : W N mk = N δ(m) N Proof: Case 1, m = k N for some k Then W nm N = (W N N ) nk = 1 nk = 1 and W nm N = N Case 2 m k N, then (W N m ) n = (1- W N mn ) (1-1) (1- W N m ) (1 - W N m )
3 QED 0 = = 0 (1- W N m ) B. Basic Definitions: (1) Forward and inverse transforms X(k) = x(n) W N nk x(n) = (1/N) X(k) W N -nk Proof of inverse transform Substitute X(k) into x(n) expression x(n) = (1/N) ( x(m) W N mk ) W N -nk
4 = (1/N) ( x(m) W N k(m-n) ) = x(m) δ(m-n) = x(n) (2) Relationships between DFT, DTFT, Z-transforms. Let x(n) be a causal, finite length sequence, non-zero between n =0 and n = N-1 X(e jw ) = x(n) (e -jw ) n X(z) = x(n) (Z -1 ) n X(k) = x(n) (e -j2πk/n ) n X(k) = X(e j2πk/n ) = X(W N -k )
5 (3) Linear Algebra Viewpoint X(k) = x(n) W N nk a(k,n)x(n) X = A x a(k,n) X = X(0) x = x(0) X(1) x(1).... X(N-1) x(n-1) A = a(0,0) a(0,1) a(0,n-1) a(0,0)... a(n-1,0) a(n-1,n-1) x = A -1 X
6 (4) Fast Fourier Transform (FFT) The FFT is a special Algorithm for calculating the DFT efficiently. The DFT is usually performed in the real world using an FFT sub-programs. Many are available. Historically: (1) The FFT was invented and reinvented many times. (2) It was last reinvented and popularized by Cooley and Tukey in the mid 1960s. (3) It was probably first invented during world war II. Then it was used to generate artillery tables and was performed by
7 groups of women sitting at desks and operating adding and multiplying machines. DFT Efficiency X(k) = x(n) W N nk = N multiplies per output point. = 2N real multiplies if x(n) real. Therefore 2N 2 real multiplies for total transform if x(n) real. Same for inverse DFT. FFT Efficiency N log 2 (N) complex mult or 4Nlog 2 (N) real mult in general case. 2Nlog 2 (N) real mult for forward or inverse transform if x(n) was real.
8 (5) Simple Transform Examples Ex. x(n) = δ(n), X(k) = δ(n) W N nk =1 Inverse x(n) = (1/N) W N -nk = δ(n) N = δ(n) Ex. δ(n-m)
9 Ex. x(n) = a n (u(n) u(n-m) ) Assume M N X(k) = a n W N nk = (a W N k ) n = 1 a M W N km 1- aw N k C. Rules for evaluating DFT Sums X(k) = x(a+bm) W N km (1) Make sure that all dummy variables on one side of the equal sign are different. Make sure that the final variables are not used anywhere as dummy variables.
(2) Evaluate the expression using one of the following 2 techniques. (a) Standard Method 10 (i) Replace (1/N) W N km by δ(m) N (ii) Replace x(a+bm) δ(m-u) by x(a+bu) N (iii) Replace x(a+bu) N by x(a+bu) if 0 a+bu N-1 always. (b) Fast Method. (i) Replace (1/N) W N km by δ(m) (ii) Replace x(a+bm) δ(m-u)
11 by x(a+bu) (iii) Replace x(a+bu) by x(a+bu) N if 0 a+bu N-1 can be violated. D. Circular Convolution. Questions: (1) DFT outputs always have N samples. How does this effect convolution. (2) Can non-causal operations be performed? 1. Derivation. Let X(k) = DFT { x(n) } = x(m) W N mk
12 H(k) = DFT { h(n) } = h(i) W N ik Final Expression for y(n) is DFT -1 {H(k) X(k) } = (1/N) ( x(m) h(i) W N mk W N ik ) W N -nk = (1/N) x(m) h(i) W N k(m+i-n) = x(m) h(i) δ(m+i-n) = x(m) h(n-m) = x(m) h(n-m) + x(m) h(n-m + N)
13
14 E. Ordinary Convolution using DFT 1.CAUSAL FILTER AND CAUSAL INPUT.
15 Goal: When is circular convolution the same as regular convolution? Guess: N 1 + M 1 2 N-1 Derivation: x(m) h(n-m) N = x(m) h(n-m) + x(m) h(n-m +N) Case 1: 0 n N 1-2 Is h(n-m+n) = 0? Min(n-m+N) = min(n) max(m) +N = 0 (N 1-1) +N = N N 1 + 1 Max(n-m+N) = max(n) min(m)+n = N-1 Therefore h(k) = 0 for N N 1 +1 k N-1 so N N 1 + 1 M 1 sufficient to guarantee results so N 1 + M 1 1 N, same as guess.
16 Case 2: n N 1-1 x(m) h(n-m) N = x(m) h(n-m) 2. Non- Causal filtering of Causal input Goals: (1) Find out how to store non-causal h(n) into causal, N sample sequence h(n). (2) Find conditions on M and N 1
17 y(n) = x(k) h(n-k) = x(k) h(n-k) + x(k) h(n-k) = x(k) h(n-k) + x(k) h(n + n-k) Therefore need h(n-k) = h(n+n-k) Let n =0, then h(n-k) = h(-k) for 1 k M
18 Restrictions on M, N, N 1 # filter points + # input points- 1 N (1+2M) + N 1 1 N or 2M + N 1 N or M 1 = 1 + 2M
19 E. Properties of the DFT (1) Shift Theorem DFT -1 { W N ik X(k)} = (1/N) W N ki ( x(m) W N mk ) W N -nk = (1/N) x(m) W N k(m+i-n) = x(n-i) N (2) Odd and Even Sequences for the DFT x(n) = x ep (n) + x op (n) where x ep (n) = ½ [ x(n) + x * (N-n) N ]
20 x op (n) = ½ [ x(n) - x * (N-n) N ] DFT{x ep (n) } = ½ x(n) W N kn + ½ x * (N-n) N W N kn = ½ [ X(k) + X * (k)] = Re {X(k) } Try DFT{x op (n)} (3) Symmetry Relationships for Real sequences If x(n) is real, we know that (i) X(e jw ) = X * (e -jw )
21 (ii) X(e jw ) = X(e -jw ) amplitude even. (iii) Arg(X(e jw )) = - arg( X(e -jw )) phase odd. (iv) Re(X(e jw )) = Re(X(e -jw )) real part even (v) Im (X(e jw )) = -Im (X(e -jw )) Im part odd. What are corresponding relationships for DFT, for x(n) real? (i) X(k) = X*(-k) N (ii) X(k) = X(-k) N (iii) arg (X(k)) = -arg (X(-k) N ) (iv) Re(X(k)) = Re(X(-k) N ) (v) Im(X(k)) = -Im(X(-k) N ) Ex (i) X(k) = x(n) W N nk X*(-k) N = ( x(n) W N n(-k) )*
22 = ( x(n) W N -nk )* = x(n) W N nk = X(k) F. More Examples Ex Write pseudo-code which reads a, Na, b, Nb, Nfreq, and plots H(e jw(k) ) versus w(k), for k = 0 to Nfreq, w(k) = πk / Nfreq
23
24 Ex Find the closed form DFT of x(n) = cos(w 1 n) (u(n) u(n-m)) X(k) = ½ (e jw1 n + e -jw1 n ) W N nk = ½ (e jw1 W N k ) n + (e -jw1 W N k ) n (1- (e jw1 W N k ) M (1- (e -jw1 W N k ) M = ½ + (1- (e jw1 W N k )) (1- (e -jw1 W N k )) Ex Find the closed form DFT of na n (u(n)- u(n-n)) x(n) Approach: Find -z X (z) and use z = e jw X(z) = x(n) z -n
25 X (z) = - n x(n) z -n-1 z X (z) = z{nx(n)} X(z) = a n z -n = 1 (az -1 ) N 1 (az -1 ) -zx (z) = - z[((1 (az -1 ))a N N z -N-1 (1 (az -1 ) N ) a z -2 ) [ 1 az -1 ] 2 z -1 = W N k
26 X(k) = -W N -k [(1-(aW N k ))a N NW N +(N+1)k (1 (aw N k ) N )a W N 2k ] [1 aw N k ] 2 = - [ ( (1 (a W N k ))a N N - a W N k (1 a N )] [1 aw N k ] 2 Ex We have a sequence x(n), 0 n M-1 and we want to calculate X(e jw ) for w = k w, where w is << π (a) What value of N is necessary if this is to be done using DFT (FFT)
27 w k for DFT is (2π/N) k = k w 2π/N = w or N = [2π/ w] R [] R denotes rounding to nearest integer (b) What restrictions on M are necessary? (c) Suppose we want to examine X(e jw ) for w 1 w w 2. what is the corresponding range of k in X(k)?
28 w 1 = 2π k 1 / N, w 2 = 2π k 2 / N k 1 = Nw 1 / 2π, k 2 = Nw 2 / 2π Ex Design a zero phase LPF h(n) with cut-off w c using the inverse DFT. Truncate the impulse response to length 1+2M. (1) Get k 1 from N and w c w c = 2π k 1 / N k 1 = Nw c / 2π (2) Draw H(k) and show cut-off samples (3) Find h(n) h(n) = DFT -1 (H(k)) = (1/N) (W N -n ) k + (1/N) (W N -n ) k
29 1-W N -n(k1 + 1) = (1/N) + 1-W N -n W N n k1-1 1-W N -n = (1/N) W N nk1 - W N -n(k1+1) 1-W N -n = (1/N) W N n(k1+1/2) - W N -n(k1+1/2) W N n/2 W N -n/2 = (1/N) sin( (2π/N)n(k 1 +½) ) sin( (π/n)n)
30 Ex Referring to h(n) from previous example, (a) How does h(n) from DFT -1 differ from h(n) for DTFT? (b) Since h(n)( is defined for 0 n N-1, how can we possibly use it for ordinary or straight convolution with the DFT? (a) h(n) = (1/N) sin((2πn/n)(nw c /2π+½)) sin( (π/n)n) = sin( w c n + (πn/n)) N sin( (π/n)n)
31 = sin( w c n + (πn/n)) N(π/N)n [sin( w c n) / (πn) ] = h(n) for DTFT (b) Use Truncation. Truncate to 1+2M coefficient h(n) h(n) w(n) Possible Windows
32 Parseval s Theorem Ex: (a) Prove that if h(n) is real, h 2 (n) = (1/N) H(k) 2 (b) From the results of part (a), justify the choice of w 1 (n) as a window for zerophase filter design. (c) Replacing h(n) by h(n) h(n), H(k) by H(k) H(k) [ h(n) h(n) w(n)] 2 = (1/N) H(k)- H(k) 2
33 = h 2 (n) (1- w(n)) = (1/N) H(k)- H(k) 2 (1- w 1 (n) h(n)) 2 << (1- w 2 (n)) 2 h 2 (n) So choose w 1 (n) (a) h(n) (1/N) H(k) W N -kn = (1/N) H(k) h(n) W N -kn = (1/N) H(k) 2
34 Ex: Find y(n) if Y(k) = H(j) X(j+k) N y(n) = (1/N) H(j) X(j+k) N W N -kn = (1/N) H(j) X(j+k) N W N -kn X(k) W N -(k-j)n = (1/N) H(j) W N -j(-n) X(k) W N -kn = N h(-n) N x(n) Ex: Find y(n) if Y(k) = H(j) X(j+k) N Z(j-k) N
35 Use H(j) = h(m) W N jm, X(j+k) N = x(i) W N i(j+k) Z(j-k) N = Z(l) W N l(j-k) Y(k)= h(m) x(i) z(l) W N jm+i(j+k)+l(j-k) = N h(-i-l) x(i) z(l) W N k(i-l) y(n) = (1/N) h(-i-l) x(i) z(l) W N k(i-l) W N -kn = N x(l+n) z(l) h(-n-2l) N
36 G. Advanced Topics 1. Filter Design for Arbitrary Frequency Responses Goal: Given H(e jw ), find h(n) if F -1 {H(e jw )} is not easily performed. First Try: Pick N, define? w, then w(k) = k? w For 0 k N-1, H(k) = H(e jw(k) ) End h(n) = DFT {H(k)} Stop Problems: (1) H(e jw ) may not be defined for w > p
(2) The phase at w = 2p may differ from that at w = 0, so H(e jw(k) ) H(e j(2 p-w(k)) ) Solution, for N Even H(0) = H(e j0 ) For 1 k N/2, H(k) = H(e jw(k) ) H(N-k) = H * (k) End h(n) = DFT {H(k)} Stop Truncation If h(n) is Applied Using the DFT 37
If h(n) is Applied in the Time Domain 38
2. Sliding DFT for an N-Sample Moving Time Domain Window Goal: In an infinite length real-time sequence x(n), we want a DFT of an N- sample moving window, as X(k) n Then, N 1 m= 0 ( X ) mk N N 1 mk n+1 N m= 0 mk -k N N -k -k -k n N N N n x(n-n+1+m)w X (k) = x(n-n+2+m)w,... m m 1 N = x(n-n+1+m)w W m= 1 = n = X(k)W +x(n+1)w -x(n-n+1)w n 1 X(k) = (k)+x(n)-x(n-n) W -k n-1 N 39
40 3. FFT Filtering of Causal, Infinite Length Sequences Goal: Find an FFT method for performing y(n) = h(n)*x(n), where h(n) is nonzero for 0 n N 1-1. The signal x(n) is causal and has an infinite number of samples. Segmenting the Input The convolution can be done efficiently as follows. Divide x(n) into length N 2 segments, and perform 0-fill as x m (n) = x(n+(m-1) N 2 ) for 0 n N 2-1 0 for N 2 n N 3-1. x m (n) has N 3 samples.
41 Zero-fill for h(n) Now, the impulse response array h(n) is padded with zeroes so that h(n) = 0 for N 1 n N 3-1. Finding the Output First, find the DFT order, N 3. For each value of m, we convolve sequences that end at n = (N 1 1) and (N 2 1). The last non-zero sample of the output y m (n) must be at n = (N 1 1) + (N 2 1), which must be less than or equal to (N 3-1). The DFT order N 3 then satisfies: N 3 (N 1 + N 2 1) Now, Y m (k) = H(k) X m (k) and y m (n) = DFT -1 {Y m (k)}.
42 Reconstructing y(n) We construct y(n) as y(n) = y (n-(m-1) N 5 ) m=1 m The delay N 5 should be equal to N 2 so that y(n) = y (n-(m-1) N 2 ) m=1 m System Time Delays Inputs x(n) may become available at a constant sampling rate, but y(n) samples appear in groups N 2. Also, the filter itself will have a time delay. Assume that the filter h(n) is symmetric (even or odd) about sample number N 6, so h(n 6 -k) = h(n 6 +k)
for example. The filter s natural time delay is N 6. Minimum Time Delay When sample number (N 2 1) comes into an input block x m (n), assume that 0-fill, forward FFT, and inverse FFT take place in no time. The time delay for x m (N 2 1) is only that for the filter, so 43 Min time delay = N 6 Maximum Time Delay When sample number 0 comes into an input block x m (n), it must wait until the remaining (N 2 1) samples come in, before the 0-fill and FFTs can take place. The time delay for x m (0) is then Max time delay = N 6 + (N 2 1)
44 4. Interpolating of the DFT Given X(k), assume that we want to reconstruct X(e jw ) by interpolating X(k). Substituting N 1 1 x(n) = X( kw ) N into k = 0 N 1 jw jwn X( e ) = xne ( ), we get n= 0 1 X( e ) X( kw ) e, = = N 1 N 1 jw nk jwn = N n= 0 N k= 0 N 1 N 1 k= 0 n= 0 N 1 k = 0 where 1 X( k) ( WN e ) N ak ( ) ix( k) nk N k jw n
45 N 1 1 ak ( ) = ( WN e ) N n= 0 k jw n kn jwn 1 1 WN e ak ( ) = k jw N 1 WN e j( w w( k)) N 1 1 e = j( w w( k)) N 1 e 1 N sin(( w wk ( )) 2 ) = e 1 i N sin(( w wk ( )) 2) j(( w wk ( )) N 1 2