Hossein Sameti Department of Computer Engineering Sharif University of Technology Many real-life systems can be modeled by LTI systems use convolution for computing the output use DFT to compute convolution Fast Fourier Transform (FFT) is a method for calculating Discrete Fourier Transform (DFT) Only faster! 0k N X ( k ) x ( n )e 0 Definition of DFT: otherwise How many computations? N 1 j 2 kn N n 0 N pt. DFT of x(n) Q: For each k: How many adds and how many mults? A: (N-1) complex adds and N complex mults. How many k values do we have? N Num.Comput N ( N 1) N 2 2N 2 O( N 2 ) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 2 2kn N 1 j x ( n )e N X (k ) n 0 0 0k N otherwise Direct computation: O( N 2 ) Ideal case: O(Const.) O( N log 2N ) FFT: Example: N Direct FFT 10^3 O(10^6) O(10^3*log10^3)=O(10^4) 10^6 O(10^12) O(10^6*log10^6)=O(2*10^7) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 3 FFT Decimation in time Decimation in frequency Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 4 2kn N 1 j x ( n )e N X (k ) n 0 0 0k N otherwise • The main idea: use the divide and conquer method •It works by recursively breaking down a problem into two or more sub-problems of the same (or related) type, until these become simple enough to be solved directly. •The solutions to the sub-problems are then combined to give a solution to the original problem. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 5 2kn N 1 j x ( n )e N X (k ) n 0 0 N 1 X (k ) x(n)e 0k N N: power of 2 otherwise j n 0 2kn N N 1 x(n)e j 2kn N n 0 n: even n: even n=2r n: odd n:0N-2 r:0N/2-1 n: odd n=2r+1 n:1N-1 r:0N/2-1 N 1 2 X ( k ) x ( 2r )e r 0 2k ( 2 r ) j N N 1 2 x(2r 1)e j 2k ( 2 r 1) N r 0 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 6 N 1 2 X ( k ) x ( 2r )e N 1 2 2k ( 2 r ) j N x(2r 1)e r 0 X ( k ) g ( r )e 2k ( 2 r ) j N r 0 2kr j X ( k ) g ( r )e N / 2 r 0 Suppose: G (k ) g (r )e j 2kr N /2 r 0 j N 1 2 h( r )e j 2k ( 2 r 1) N r 0 N 1 2 X (k ) G (k ) e 2k ( 2 r 1) N r 0 N 1 2 N 2 1 j 2k N N 2k 1 2kr j j 2 N e h ( r )e N / 2 r 0 N 2kr 2 1 j H ( k ) h ( r )e N / 2 r 0 H (k ) •What are G(k) and H(k)? 7 N 2 1 G ( k ) g ( r )e X (k ) G (k ) e j 2k N H (k ) r 0 N 2 1 j 2kr N /2 j 2k N /2 H ( k ) h( r )e r 0 •In G(k) and H(k), k varies between 0 and N/2-1. •However, in X(k) , k varies between 0 and N-1. Solution: use the relationship between DFS and DFT. We thus need to replicate G(k) and H(k) “once”, to get X(k). Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 8 N 2 g(r) x(n) G (k ) N 2 pt. DFT After replication + N 2 h(r) N 2 X (k ) pt. DFT H (k ) W k N e j 2k N (twiddle factor) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 9 X (0) G(0) WN0 H (0) N 2 g(r) G ( 0) N X ( ) G(0) WNN / 2 H (0) 2 0 pt. DFT G( N 1 2 N ) G(0) 2 N N 1 2 x(n) H (0) N 2 pt. DFT h(r) 0 H( X (k ) G (k ) e j 2k N H (k ) N 1 2 N ) H (0) 2 N N 1 2 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 10 X (k ) G(k ) WNk H (k ) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 11 N/2 pt. DFT block Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 12 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 13 r(0) r(1) N 1 R(k ) r (n)e N 2 j 2kn N n 0 R(k ) r (0)e j 2k ( 0 ) 2 r (1)e j 2k (1) 2 R(k ) r (0) r (1)e jk Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 14 r(0) r(1) R(k ) r (0) r (1)e jk k 0 R(0) r (0) r (1) R(0) x(0) x(4) k 1 R(1) r (0) r (1) R(1) x(0) x(4) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 15 Flow graph of a the 2-pt. DFT Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 16 N How many stages do we have? log 2 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 17 W N r 2 N e 2 N j (r ) N 2 e j e 2 r N j .e 2 r N j 2 N ( ) N 2 W r N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 18 W N r 2 N W r N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 19 2 mults+ 2 adds 1 mult+ 2 adds Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 20 In-place computation (only N storage locations are needed) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 21 •How many stages do we have log 2N •Each stage has N inputs and N outputs. •Each butterfly has 2 inputs and 2 outputs. N •Each stage has 2 butterflies. •Each butterfly needs 1 mult and 2 adds. Total number of operations: N 2 log 2N N log N adds 2 N N N log 2 log N mults 2 2 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 22 input indexing is shuffled. Output indexing is in order. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 23 [1 0 0] [0 0 1] X (0) 0 [0 0 0] [0 0 0] 0 X (1) 1 [0 0 1] [1 0 0] 4 X (2) 2 [0 1 0] [0 1 0] 2 X (3) 3 [0 1 1] [1 1 0] 6 X (4) 4 [1 0 0] [0 0 1] 1 X (5) 5 [1 0 1] [1 0 1] 5 X (6) 6 [1 1 0] [0 1 1] 3 X (7) 7 [1 1 1] [1 1 1] 7 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 24 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 25 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 26 2kn N 1 j x ( n )e N X (k ) n 0 0 0k N otherwise • The main idea: use the divide and conquer method (this time in the frequency domain) • Divide the computation into two parts: even indices of k and odd indices of k. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 27 2kn N 1 j x ( n )e N X (k ) n 0 0 0k N otherwise N 1 k 2r X (2r ) x(n)e j 2 ( r ) n N /2 n 0 N 1 2 X ( 2 r ) x ( n )e j 2 ( r ) n N /2 n 0 n m N 2 N 1 2 X ( 2r ) x ( n)e n0 j 2 ( r ) n N /2 N 1 x ( n) e N n 2 N 1 2 N 0r 2 j 2 ( r ) n N /2 N j x ( m )e m0 2 1 2 ( r )(m N ) 2 N /2 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 28 N 1 2 X ( 2 r ) x ( n )e 2 ( r ) n j N /2 n 0 N 1 2 X ( 2 r ) x ( n )e N 1 2 N j x ( m )e m0 2 2 ( r ) n j N /2 n 0 N 1 2 2 ( r ) m N /2 N 1 2 N x ( n )e n 0 2 N X (2r ) ( x(n) x(n )) e n 0 2 j 2 ( r ) n N /2 j 2 ( r ) n N /2 N 0r 2 g (n) N/2 pt. DFT of g(n) Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 29 N 1 2 N j X (2r ) ( x(n) x(n )) e n 0 2 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 2 ( r ) n N /2 30 N 1 k 2r 1 X (2r 1) x(n)e j 2 ( 2 r 1) n N n 0 N 1 2 X (2r 1) x(n)e j 2 ( 2 r 1) n N n 0 n m N 1 2 X (2r 1) x(n)e n 0 j N 1 x(n)e n N 2 2 ( 2 r 1) n N N 1 2 N 0r 2 j 2 ( 2 r 1) n N N 2 N j x ( m )e m0 2 2 ( 2 r 1)(m N ) 2 N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 31 N 1 2 X (2r 1) x(n)e j 2 ( 2 r 1) n N n 0 N 1 2 X (2r 1) x(n)e 2 ( 2 r 1) n j N n 0 e N 1 2 N j x ( m )e m0 2 j 2 N ( 2 r 1) 2 N 2 ( 2 r 1)(m N 1 2 N ) 2 N N j x ( m )e m0 2 2 ( 2 r 1)(m ) N -1 N 1 2 X (2r 1) x(n)e n 0 2 ( 2 r 1) n j N N 1 2 N j x ( n )e n 0 2 2 ( 2 r 1)(n ) N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 32 N 1 2 X (2r 1) x(n)e 2 ( 2 r 1) n j N n 0 N 1 2 N 1 2 N j x ( n )e n 0 2 N j X (2r 1) ( x(n) x(n )) e n 0 2 N 1 2 2 ( 2 r 1)(n ) N 2 ( 2 r 1) n N N j X (2r 1) [( x(n) x(n )) e n 0 2 2n N ]e j 2 ( r ) n N /2 h(n) N/2 pt. DFT of h(n) e j 2n N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 33 N 1 2 N j X (2r 1) [( x(n) x(n )) e n 0 2 2n N Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology ]e j 2 ( r ) n N /2 34 35 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 36 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 37 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 38 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 39 Change x with X (i.e., input nodes with output nodes) Change X with x (i.e., output nodes with input nodes) Reverse the order of the flow graphs. The same system function is achieved. Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 40 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 41 Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 42 How can we deal with twiddle factors? Should we store them in a table (i.e, use a lookup table) or should we calculate them? What happens if N is not a factor of 2? It can be shown that if N=RQ, then an N pt. DFT can be expressed in terms of R Q-pt. DFT or Q R pt. DFTs (Cooley-Tukey algorithm). Hossein Sameti, Dept. of Computer Eng., Sharif University of Technology 43