Hossein Sameti Department of Computer Engineering Sharif University of Technology The DTFT is defined using an infinite sum over a discrete time signal and yields a continuous function X(ω) ◦ not very useful because the outcome cannot be stored on a PC. Now introduce the Discrete Fourier Transform (DFT), which is discrete and can be stored on a PC. We will show that the DFT yields a sampled version of the DTFT. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 2 C. C. X () CTFT {x(t )} x(t )e jt dt x(t ) D. D. D. periodic D. n Complex x(n) X ( z ) z{x(n)} x(n) z n n Int. ~ ~ ~ N 1 ~ X (k ) DFS {x(n)} x(n)e x ( n) N 1 X (k ) DFT {x(n)} x(n)e finite j 2kn N n 0 periodic x(n) finite X ( ) DTFT {x(n)} x(n)e jn x(n) Inf. or Finite C. j 2kn N n 0 Int. 3 X () CTFT {x(t )} x(t )e jt dt x(t ) x(n) X ( ) DTFT {x(n)} x(n)e jn n x(n) ~ X ( z ) z{x(n)} x(n) z n n ~ x ( n) x(n) ~ N 1 ~ X (k ) DFS {x(n)} x(n)e j 2kn N n 0 N 1 X (k ) DFT {x(n)} x(n)e j 2kn N n 0 4 ~ ~ x(n) x(n kN) N : period ~ • Decompose x(n) in terms of complex exponentials that are periodic with period N. j 2kn ~ N 1 1 x ( n) X ( k )e N N k 0 • How many exponentials? N ek ( n ) e j 2kn N k 0,1,..., N 1 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 5 ek ( n ) e j 2kn N k 0,1,..., N 1 Exponentials that are periodic with period N. ek (n) ek rN (n) arbitrary integer 1 * Proof: ek rN (n) e j 2 ( k rN ) n N ek rN (n) e ek rN (n) e j 2kn N j 2kn j 2rnN N .e N ek (n) e0 (n) eN (n) e2 N (n) .... e1 (n) eN 1 (n) e2 N 1 (n) .... 6 ~ x ( n) N 1 1 X ( k )e N k 0 Answer: j 2kn N How to find X(k)? N 1 ~ X ( k ) x ( n )e j 2kn N n 0 Proof : substitute X(k) in the first equation. •It can also easily be shown that X(k) is periodic with period N: X (k ) X (k rN ) arbitrary integer Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 7 ~ Analysis: N 1 ~ X ( k ) x ( n )e j 2kn N n 0 1 N 1 ~ x ( n) X ( k )e N k 0 ~ Synthesis: Periodic N pt. seq. in time domain j 2kn N Periodic N pt. seq. in freq. domain Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 8 ~ x(n) (n rN ) r 1 -N ~ N 1 ~ X ( k ) x ( n )e j 2kn N N 1 ( n )e n 0 1 1 0 N j 2kn N n 0 1 -N … 1 0 e … n j 2k ( 0 ) N 1 1 N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology n 9 ~ x(n) (n rN ) (eq.1) r N 1 ~ ~ X ( k ) x ( n )e j 2kn N n 0 1 N 1 ~ x ( n) X ( k )e N k 0 ~ (eq.1) & (eq.2) N 1 ( n )e j 2kn N n 0 j 2kn N N 1 1 e N k 0 j 2kn N e j 2k ( 0 ) N (eq.2) (n rN ) 1 e r 1 N 1 N j 2kn N k 0 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 10 Shift property: ~ ~ x ( n) X (k ) ~ x(n n0 ) e j 2kn0 N ~ X (k ) Periodic convolution: ~ ~ ~ N 1 ~ ~ x1 x 2 x 3 x1 (m) x 2 (n m) m0 ~ Period N ~ ~ X 1 (k ) X 2 (k ) X 3 (k ) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 11 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 12 In the list of properties: 𝑊𝑁 = 𝑒 𝑗2𝜋 𝑁 𝑊𝑁 𝑘𝑛 =𝑒𝑘 (𝑛) Where: ek (n) e j 2kn N k 0,1,..., N 1 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 13 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 14 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 15 x(n) X (k ) N pt. N pt. N pt. DFT N pt. DTFT DFT DFS Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 16 1) Start with a finite-length seq. x(n) with N points (n=0,1,…, N-1). ~ 2) Make x(n) periodic with period N to get x(n) ~ x ( n) x ( n ) R N ( n ) ~ Extracts one period of x(n) 1 n 0,1,..., N 1 R N ( n) otherwise 0 ~ x(n) x(n rN ) r Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 17 ~ ~ 3) Take DFS of x(n) X (k ) ~ 4) Take one period of X (k ) to get DFT of x(n): X (k ) ~ X (k ) X (k ) RN (k ) x(n) N pt. ~ ~ x ( n) X (k ) X (k ) N pt. periodic N pt. N pt. periodic Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 18 x(n) 3 2 1 1 0 ~ 3 3 x ( n) 3 2 2 1 1 ~ 2 1 1 1 0 X (k ) n 2 3 1 0 0 k 2 3 1 X (k ) n 2 3 1 1 1 2 3 k 19 Definition of DFT: 2kn N 1 j x ( n )e N X (k ) n 0 0 0k N otherwise N pt. DFT of x(n) 2kn 1 N 1 j X ( k )e N 0n N x ( n) N k 0 0 otherwise Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 20 1 0 n 5 x ( n) 0 otherwise 2kn 4 j x ( n )e 5 0k 5 X (k ) n 0 0 otherwise k 0 5 X (k ) 0 otherwise X (k ) ? 1 e j 2k 0k 5 j 2k X (k ) 5 1 e 0 otherwise 21 Mehrdad Fatourechi, Electrical and Computer Engineering, University of British Columbia, Summer 2011 22 2kn N 1 j x ( n )e N X (k ) n 0 0 X ( ) x(n)e n jn 0k N otherwise N 1 x(n)e jn n 0 X ( ) 2k X (k ) N 0 0k N otherwise DFT thus consists of equally-spaced samples of DTFT. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 23 X ( ) 3 8 pt. sequence 2k 8 2 3 8 pt. DFT k 0,1,..., 7 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 24 So far we calculated the N pt. DFT of a seq. x(n) with N non-zero values: X ( ) 2k X (k ) N 0 0k N otherwise Suppose we pad this N pt. seq. with (M-N) zeros to get a sequence with length M. 3 x(n) We can now take an M-pt. 2 DFT of the signal x(n) 1 1 0 1 2 3 n Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 25 2kn M 1 j x ( n)e M X (k ) n 0 0 N pt. DFT 0k M otherwise M pt. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 26 x(n) 3 2 1 0 1 1 n 2 3 2kn 3 j x ( n )e 4 4 pt. DFT: X (k ) n 0 0 2kn 5 j x ( n )e 6 6 pt. DFT: X (k ) n 0 0 2kn 7 j x ( n )e 8 8 pt. DFT: X (k ) n 0 0 2kn 99 j x(n)e 100 100 pt. DFT: X (k ) n 0 0 0k 4 otherwise 0k 6 otherwise How are these related to each other? 0k 8 otherwise 0 k 100 otherwise 27 X ( ) Going from N pt. to 2N pt. DFT 0 2 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 28 N pt. seq. N pt. N pt. DFT 2N pt. N pt. seq. padded with N zeros 2N pt. DFT What is the minimum number of N needed to recover x(n)? Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 29 Assume y(n) is a signal of finite or infinite extent. Y ( ) DTFT { y(n)} • Sample Y ( ) at N equally-spaced points. Y ( ) 2k X (k ) N pt. sequence. N IDFT { X (k )} x(n) N pt. sequence. What is the relationship between x(n) and y(n)? What happens if N is larger , equal or less than the length of y(n)? Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 30 We start with x(n) and find its relationship with y(n): 2kn 1 N 1 j X ( k )e N 0n N x(n) N k 0 0 otherwise Y ( ) 2k X (k ) N Change the order of summation: 2km 2kn 1 N 1 j j ( y ( m)e N )e N 0n N x(n) N k 0 m 0 otherwise 2k ( m n ) N 1 j 1 N y ( m) e 0n N x ( n) m N k 0 0 otherwise Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 31 2k ( m n ) N 1 j 1 N y ( m) e x ( n) m N k 0 0 0n N otherwise However, we have shown that: 1 N 1 j x ( n) 1.e N k 0 ~ 2kn N (n rN ) r ~ X (k ) 1 0 k N 1 f (n) (n rN ) f (n m) (n m rN ) r y ( m) f ( n m ) x(n) m 0 r 0n N otherwise Convolution with train of delta functions Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 32 y (n rN ) x(n) r 0 0n N otherwise One period of the replicated version of y(n) • Examples If we sample Y ( ) at a sampling rate that is higher than the number of points in y(n), we should be able to recover y(n). Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 33 Shift property: 0k N x(n) DFT X (k ) N pt. seq. x(n n0 ) DFT X (k )e j 2n0 k N 0k N The above relationship is not correct, because of the definition of DFT. The signal should only be non-zero for the first N points. ~ x(n n0 ) RN (n) DFT X (k )e j 2n0 k N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 34 In the list of properties: 𝑊𝑁 = 𝑒 where: 𝑗2𝜋 𝑁 , 𝑊𝑁 𝑘𝑛 =𝑒𝑘 (𝑛) ek (n) e j 2kn N k 0,1,..., N 1 ~ and where: x[((n n0 )) N ] x(n n0 ) RN (n) 1 n 0,1,..., N 1 RN ( n ) otherwise 0 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 35 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 36 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 37 Using DFT to calculate linear convolution Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 38 We are familiar with, “linear convolution”. Question: Can DFT be used for calculating the linear convolution? The answer is: NO! (at least not in its current format) We now examine how DFT can be applied in order to calculate linear convolution. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 39 • Linear convolution: x3 (n) x1 (k ) x2 (n k ) x1 (n) x2 (n) x3 (n) k Application in the analysis of LTI systems • Periodic convolution: ~ ~ ~ N 1 ~ ~ x1 x 2 x 3 x1 (m) x 2 (n m) m0 A seq. with period N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 40 • Circular convolution: x1 x 2 x 3 N pt. seq. • Circular convolution is closely related to periodic convolution. ~ ~ x 3 (n) x1 (n) x 2 (n) [ x1 (n) x 2 (n)]. RN (n) X 3 (k ) X 1 (k ). X 2 (k ) N pt. DFT of x3 N pt. DFT of x1 N pt. DFT of x2 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 41 x1 (n) (n 1) x2 (n) : N Circular convolution? pt. seq. Make x1 (n) an N pt. seq. 0 0 n 1 x1 (n) 1 n 1 0 1 n N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 42 43 ~ ~ x 3 (n) x1 (n) x 2 (n) [ x1 (n) x 2 (n)]. RN (n) We know from DFS properties: ~ ~ ~ ~ x1 x 2 x 3 ~ ~ ~ ~ X 1 (k ) X 2 (k ) X 3 (k ) X 1 (k ) DFS {x1 (n)} ~ ~ X 2 (k ) DFS {x 2 (n)} ~ ~ X 3 (k ) DFS {x 3 (n)} ~ ~ ~ X 1 (k ) X 2 (k ) RN (k ) X 3 (k ) RN (k ) X 1 (k ). X 2 (k ) X 3 (k ) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 44 ~ ~ x 3 (n) x1 (n) x 2 (n) [ x1 (n) x 2 (n)]. RN (n) X 1 (k ). X 2 (k ) X 3 (k ) If we multiply the DFTs of two N pt. sequences, we get the DFT of their circular convolution and not the DFT of their linear convolution. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 45 1 0 n L x1 (n) x2 (n) 0 otherwise Calculate N pt. circular convolution of x1 and x2 for the following two cases of N: 1) N=L 2) N=2L Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 46 2kn L 1 j x ( n )e L X ( k ) n 0 0 1 0 n L 1 x1 (n) 0 otherwise 0 k L 1 otherwise N pt. DFT of x1 k 0 L X 1 (k ) X 2 (k ) 0 otherwise X 3 (k ) X 1 (k ). X 2 (k ) IDFT L2 k 0 0 otherwise L 0 n L 1 x3 ( n ) otherwise 0 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 47 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 48 • Pad each signal with L extra zeros to get an 2L pt. seq.: N=2L pt. DFT of x1 2kn 2 L 1 j x ( n )e 2 L X (k ) n 0 0 0 k 2L 1 otherwise Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 49 Same as linear convolution!! 50 Our hypothesis is that if we pad two DT signals with enough zeros so that its length becomes N, we can use DFT to calculate linear convolution. x1 (n) L pt. seq. NL x 2 ( n) P pt. seq. NP Goal: calculate x3 (n) x1 (n) * x2 (n) Using DFT Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 51 x3 (n) x1 (n) * x2 (n) X 3 ( ) X 1 ( ) X 2 ( ) X ( ) DTFT {x(n)} x(n)e jn n To get DFT, we have to sample the above DTFT at N equally-spaced points: Y (k ) X 3 ( ) 2k N IDFT {Y (k )} Solution to the problem statement x3 (n rN ) r 0 0n N otherwise (Eq.1) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 52 On the other hand, we know that: Y (k ) X 3 ( ) 2k X 1 ( ) 2k X 2 ( ) 2k N N pt. DFT of x1 N N N pt. DFT of x2 IDFT {Y (k )} x1 (n) x 2 (n) (Eq.1) (Eq.2) x1 ( n) x 2 ( n) Circular convolution (Eq.2) x (n rN ) r 3 0 0n N otherwise Replicated version of the linear convolution Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 53 In other words, the N pt. circular convolution of two DT signals is the same as their linear convolution, if we make the result of linear convolution periodic with period N and extract one period. x3 (n) L P 1 To avoid aliasing: N L P 1 We can thus use DFT in order to calculate the linear convolution of two sequences! Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 54 1) Start with x1 (n) L pt. seq. x 2 ( n) P pt. seq. 2) Choose N L P 1 3) Pad x1 (n) with N-L zeros to get N points. 4) Pad x2 (n) with N-P zeros to get N points. 5) Calculate the N pt. DFTs of the above two sequences and multiply them together. 6) Calculate IDFT of the resulting N pt. sequence. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 55 y(n) x(n) h(n) A very long sequence An FIR filter with a limited number of taps (P) • Examples of this situation? Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 56 Solution to the problem Overlap - add Main idea: using the following property: [ x1(n) x2 (n)] * h(n) x1(n) * h(n) x2 (n) * h(n) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 57 Segment the long sequence into non-overlapping chunks of data with the length of L. Convolve each chunk with h(n) to get (L+P-1) new points. Add the results of the convolution of all chunks to get the final answer. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 58 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 59 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 60 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 61 Discussed DFS and DFT and examined the relationship between DFT and DTFT Showed how DFT can be used for calculating convolution sum. Next: Fast Fourier Transform Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 62