(DFT) Outline • Domains of Definition • Discrete Fourier Transform
Total Page:16
File Type:pdf, Size:1020Kb
MUS421 Lecture 2 Review of the Discrete Fourier Transform (DFT) Julius O. Smith III ([email protected]) Center for Computer Research in Music and Acoustics (CCRMA) Department of Music, Stanford University Stanford, California 94305 June 27, 2020 Outline Domains of Definition • Discrete Fourier Transform • Properties of the Fourier Transform • For more details, see Mathematics of the DFT (Music 320 text): • http://ccrma.stanford.edu/~jos/mdft/ Chapter 2 and Appendix B of • Spectral Audio Signal Processing (our text): http://ccrma.stanford.edu/~jos/sasp/ 1 Domains of Definition The Fourier Transform can be defined for signals that are Discrete or Continuous Time • Finite or Infinite Duration • This results in four cases: Time Duration Finite Infinite Fourier Series (FS) Fourier Transform (FT) cont. P + jω t ∞ jωt X(k)= x(t)e− k dt X(ω)= x(t)e− dt time 0 k = Z ,..., + ω Z(−∞ , + ) t −∞ ∞ ∈ −∞ ∞ Discrete FT (DFT) Discrete Time FT (DTFT) discr. N 1 + − jω n ∞ jωn X(k)= x(n)e− k X(ω)= x(n)e− time n=0 n= k =0, X1,...,N 1 ω X( −∞π, +π) n − ∈ − discrete freq. k continuous freq. ω 2 Geometric Interpretation of the Fourier Transform In all four cases, X(ω)= x,s h ωi where sω is a complex sinusoid at radian frequency ω rad/s: ejωt (Fourier transform case), • ejωn (DTFT case, T =1/f =1), • s ejωkt (Fourier series case), • ej2πkn/N (DFT case). • Geometrically, X(ω)= x,s is proportional to the h ωi coefficient of projection of the signal x onto the signal sω. 3 Signal and Transform Notation n,k Z (integers) or Z (integers modulo N) • ∈ N x(n) R (reals) or C (complex numbers) • ∈ x CN means x is a length N complex sequence • ∈ x = x( ) • · X = DFT(x) CN , or • ∈ x X ↔ where “ ” is read as “corresponds to”. ↔ X(k)= DFT (x)= DFT (x) C • k N,k ∈ x(n)= IDFT (X)= IDFT (X) • n N,n C DTFT DFT C For x ∞, X = (x)= (x) 2∞π • ∈ ∞ ∈ x = conjugate of x • ∠x = phase of x • The notation XY or X Y denotes the vector containing · (XY )k = X(k)Y (k), k =0,...,N 1. This is denoted by ‘X .* Y’ in Matlab, where X and−Y may a pair of column vectors, or a pair of row vectors. 4 The Discrete Fourier Transform The “kth bin” of the Discrete Fourier Transform (DFT) is defined as N 1 − ∆ ∆ ∆ jω tn X(k) = DFT (x) = x,s = x(t )e− k k h ki n n=0 X ∆ s (n) = ejωktn; k =0, 1,...,N 1 k − k 2πk ω =∆ 2π f = ; t =∆ nT k N s NT n The DFT is proportional the coefficients of projection of the signal vector x onto the N sinusoidal basis signals sk, k =0, 1,...,N 1: − X(k)= x,s h ki The normalized DFT is precisely the coefficients of projection of the signal vector x onto the N normalized sinusoidal basis signals s˜ = s / s = s /√N: k k k kk k X˜ (k)= x, s˜ h ki 5 Inverse DFT The inverse DFT is given by N 1 N 1 − x,s 1 − k jωktn x(tn)= h 2isk(tn)= X(ωk)e sk N Xk=0 k k Xk=0 It can be interpreted as the superposition of the projections, i.e., the sum of the sinusoidal basis signals weighted by their respective coefficients of projection: x,sk x = h 2isk sk Xk k k The inverse normalized DFT is cleaner: x = x, s˜ s˜ h ki k Xk 6 The DFT, Cont’d There are several ways to think about the DFT: 1. Projection onto the set of “basis” sinusoids (frequencies at N roots of unity) 2. Coordinate transformation (“natural” RN basis to “sinusoidal” basis) 3. Matrix multiplication X = W∗x, jω tn where W∗[k,n]= e− k 4. Sampled uniform filter bank output This course will emphasize interpretations 1 and 4. 7 Properties of the DFT We are going to be performing manipulations on signals and their Fourier Transform throughout this class. It is important to understand how changes we make in one domain affect the other domain. The Fourier theorems are helpful for this purpose. Derivations of the Fourier theorems for the DTFT case may be found in Chapter 2 of the text, and in Mathematics of the DFT1 (Music 320 text) for the DFT case. 1http://ccrma.stanford.edu/~jos/mdft/Fourier Theorems.html 8 Linearity αx + βx αX + βX 1 2 ↔ 1 2 or DFT(αx + βx ) = α DFT(x )+ β DFT(x ) 1 2 · 1 · 2 α, β C ∈ x ,x ,X ,X CN 1 2 1 2 ∈ The Fourier Transform “commutes with mixing.” 9 Symmetries for Real Signals If a time-domain signal x is real, then its Fourier transform X is conjugate symmetric (Hermitian): x RN X( k)= X(k) ∈ ⇔ − or Real Hermitian ↔ Hermitian symmetry implies Real part Symmetric (even): • re X( k) = re X(k) { − } { } Imaginary part Antisymmetric (skew-symmetric, odd): • im X( k) = im X(k) { − } − { } Magnitude Symmetric (even): • X( k) = X(k) | − | | | Phase Antisymmetric (odd): • ∠X( k)= ∠X(k) − − 10 Time Reversal Definition: Flip (x) =∆ x( n) =∆ x(N n) n − − Note: x(n) =∆ x(n mod N) for signals in CN (DFT case). When computing a sampled DTFT using the DFT, we interpret time indices n =1, 2,...,N/2 1 as positive time indices, and n = N 1,N 2,...,N/− 2 as the negative time indices n =− 1, 2−,..., N/2. Under this interpretation, the Flip− operator− simply− reverses a signal in time. Fourier theorems: Flip(x) Flip(X) ↔ for x CN . In the typical special case of real signals (x R∈N ), we have Flip(X)= X so that ∈ Flip(x) X ↔ Time-reversing a real signal conjugates its spectrum 11 Shift Theorem The Shift operator is defined as Shift (y) =∆ y(n l). l,n − Since indexing is defined modulo N, Shiftl(y) is a circular right-shift by l samples. j( )l Shift (y) e− · Y l ↔ or, more loosely, jωl y(n l) e− Y (ω) − ↔ i.e., jωkl DFTk[Shiftl(y)] = e− Y (ωk) jω l e− k = Linear Phase Term, slope = l − ∠Y (ω ) += ω l • k − k Multiplying a spectrum Y by a linear phase term • jω l e− k with phase slope l corresponds to a circular right-shift in the time domain− by l samples: negative slope time delay • ⇒ positive slope time advance • ⇒ 12 Convolution The cyclic convolution of x and y is defined as N 1 − (x y)(n) =∆ x(m)y(n m), x,y CN ∗ − ∈ m=0 X Cyclic convolution is also called circular convolution, since y(n m) =∆ y(n m (mod N)). − − Convolution is cyclic in the time domain for the DFT and FS cases, and acyclic for the DTFT and FT cases. The Convolution Theorem is then (x y) X Y ∗ ↔ · 13 Linear Convolution of Short Signals x(t) h y(t) = (x∗h)(t) Convolution theorem for DFTs: (h x) H X ∗ ↔ · or DFT (h x)= H(ω )X(ω ) k ∗ k k where h,x CN , and H and X are the N-point DFTs of h and x,∈ respectively. DFT performs circular (or cyclic) convolution: N 1 − y(n) =∆ (x h)(n) =∆ x(m)h(n m) ∗ − N m=0 X where (n m) means “(n m) modulo N” − N − Another way to look at this is as the inner product of x, and Shiftn[Flip(h)], i.e., y(n)= x, Shift [Flip(h)] h n i 14 FFT Convolution The convolution theorem h x H X shows us that there are two ways to perform∗ circular↔ · convolution. direct calculation of the summation = (N 2) • O frequency-domain approach = (NlgN) • O Fourier Transform both signals • Perform term by term multiplication of the • transformed signals Inverse transform the result to get back to the • time domain Remember ... this still gives us cyclic convolution Idea: If we add enough trailing zeros to the signals being convolved, we can get the same results as in acyclic convolution (in which the convolution summation goes from m =0 to ). ∞ Question: How many zeros do we need to add? N N N ∗ = Nx Nh Nx +Nh -1 15 If we perform an acyclic convolution of two signals, x • and h, with lengths Nx and Nh, the resulting signal is length N = N + N 1. y x h − Therefore, to implement acyclic convolution using the • DFT, we must add enough zeros to x and y so that the cyclic convolution result is length Ny or longer. If we don’t add enough zeros, some of our • convolution terms “wrap around” and add back upon others (due to modulo indexing). This can be called time domain aliasing. • We typically zero-pad even further (to the next power • of 2) so we can use the Cooley-Tukey FFT for maximum speed A sampling-theorem based insight: Zero-padding in the time domain results in more samples (closer spacing) in the frequency domain. This can be thought of as a higher ‘sampling rate’ in the frequency domain. If we have a high enough frequency-domain sampling rate, we can avoid time domain aliasing. 16 Example FFT Convolution % matlab/fftconvexample.m x = [1 2 3 4 5 6]; h = [1 1 1]; nx = length(x); nh = length(h); nfft = 2^nextpow2(nx+nh-1) xzp = [x, zeros(1,nfft-nx)]; hzp = [h, zeros(1,nfft-nh)]; X = fft(xzp); H = fft(hzp); Y = H .* X; y = real(ifft(Y)) Program output: octave:10> fftconvexample nfft = 8 y = 1 3 6 9121511 6 17 FFT Convolution vs.