Lecture slides on the FFT

advertisement
Fast Fourier Transform
Background on Fourier series
• It can be shown that any continuous function x(t)
defined over T1 ≤ t ≤ T2 can be expressed as the
following infinite sum
$
x(t) = %
#$
z
$
k
(cos(k" 0 t) + i sin(k" 0t)) = x(t) = %
#$
z
k
exp(ik" 0 t)
zk are complex numbers x + iy, i = √-1
ω0 = 2 π /(T2 - T1)
!
• We call the infinite sum a Fourier series
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
2
Deriving a Fourier Series
• The coefficients zk are called the complex
amplitude of the kth component
• They may be obtained by the following formula
zk = 1T
$
%e
"ik# 0 t
x(t) dt
"$
• For example, the square wave may be expressed
!
as a sum of odd
harmonics:
A1*sin(x) + A2*sin(3x) + A3*sin(5x) + …
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
3
Fourier Series approximation
of a square wave
(2/π)∑ sin(kx)/k
k odd
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
4
Fourier transform
• For a continuous signal defined from + ∞ to -∞ there is a
continuous Fourier spectrum
• This is the Fourier transform
-∞
-iωt dt, where e -iωt = cos(ωt) - i sin(ωt)
X(ω) =⌠
⌡ x(t) e
-∞
• Whereas the harmonics corresponding to the zk have
frequencies that are discrete multiples of ω0 the harmonics
in the Fourier spectrum have all frequencies between
+ ∞ and -∞
• We can recover the original function with the inverse
-∞
transform
-1
x(t) = (2 π) ⌠ X(ω) e iωt d ω
⌡
-∞
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
5
Fourier transform of the square wave
Using the Fourier transform,
we can determine the
$
the coefficients zk = 1T % (cos(k" 0 t) + jsin(k" 0 t)) S(t) dt
#$
!
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
6
Computing Fourier transform
•
For a continuous function we can determine the coefficients using the
Fourier transform
zk = 1T
•
•
•
!
$
%e
"ik# 0 t
x(t) dt
"$
The Discrete Fourier Transform determines the coefficient for a discrete
function defined on uniformly spaced sampling points: O(N2) algorithm
!
1 N "1
N #1
i2 "kn / N
X(k) = $ x(n)e"i2 #kn / N
x(n)
=
X(k)e
$
n= 0
N n= 0
Fast Fourier Transform (FFT), Cooley and Tukey (1965)
Divide and conquer, O(N lg N)
!
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
7
Using the Discrete Fourier transform
• Consider the spectrum of the square wave
350
300
250
200
150
100
50
0
5/5/09
0
1
2
3
4
5
Scott B. Baden /CSE 262 / Sp 2009
6
7
8
Shifting
•
•
•
•
The FT is centered about the origin
But the DFT is centered about N/2
We need to correct with a circular shift operation
Or, multiply by (-1)k prior to taking the transform
350
300
250
200
150
100
50
0
5/5/09
0
1
2
3
4
5
6
7
Scott B. Baden /CSE 262 / Sp 2009
9
FFT
• Cooley and Tukey (1965), O(N lg N)
• Divide and conquer → iterative computation
• K = 0:N-1, M = N / 2
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
10
Recursive formulation
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
11
Iterative formulation
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
12
FFT “Butterfly graph”
• lg N stages
• At each iteration i, apply
a butterfly operation to
combine pairs of
elements spaced 2N-i units
apart
• “Twiddle” factors
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
13
A 2D Discrete Fourier Transform
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
15
1D Spatial Frequencies
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
1
2
3
4
5
6
7
1
0.5
0
-0.5
-1
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
16
1D Spatial Frequencies
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
17
2D Spatial Frequencies
5
1
0.9
4
0.8
0.7
3
0.6
0.5
2
0.4
1
0.3
0.2
0
0.1
0
0
1
2
3
4
5
6
7
-1
1
0.5
0
-0.5
-1
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
18
Implementing the 2D FFT
• The 2D FFT is separable
• We may express it in terms of 1D FFTs
• We take row transforms
– Apply the 1D FFT algorithm to each row
• Next take column transforms
– Apply the 1D FFT algorithm to each column
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
19
A few details
• The data end up in bit-reversed order
– Thus, element 17=010001 → 100010 = 34
• We use libraries to compute the FFTs
– MKLIB, ESSL
• Parallel libraries, e.g. PESSL
• Other algorithms
– FFTW “Fastest FFT in the West:” www.fft.org
– “Faster FFTs via Architecture Cognizance,” K. Gatlin and L. Carter,
PACT 2000
http://www.cs.ucsd.edu/users/carter/Papers/pact00.ps
5/5/09
Scott B. Baden /CSE 262 / Sp 2009
20
Download