38
The Fast Fourier Transform Derek L. Smith SIAM Seminar on Algorithms - Fall 2014 University of California, Santa Barbara October 15, 2014

The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

The Fast Fourier Transform

Derek L. SmithSIAM Seminar on Algorithms - Fall 2014

University of California, Santa Barbara

October 15, 2014

Page 2: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Table of Contents

History of the FFT

The Discrete Fourier Transform

The Fast Fourier Transform

MP3 Compression via the DFT

The Fourier Transform in Mathematics

Page 3: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Table of Contents

History of the FFT

The Discrete Fourier Transform

The Fast Fourier Transform

MP3 Compression via the DFT

The Fourier Transform in Mathematics

Page 4: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Navigating the Origins of the FFT

The Royal Observatory, Greenwich, inLondon has a stainless steel strip on theground marking the original location ofthe prime meridian. There’s also aplaque stating that the GPS referencemeridian is now 100m to the east.

This photo is the culmination ofhundreds of years of mathematicaltricks which answer the question: Howto construct a more accurate clock? Ormap? Or star chart?

Page 5: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Time, Location and the Stars

The answer involves a naturallyoccurring reference system.Throughout history, humanshave measured their locationon earth, in order to moreaccurately describe the positionof astronomical bodies, in orderto build better time-keepingdevices, to more successfullynavigate the earth, to moreaccurately record the stars...and so on... and so on...

Page 6: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Time, Location and the Stars

Transoceanic exploration previously required a vessel stocked withmaps, star charts and a highly accurate clock. Institutions such asthe Royal Observatory primarily existed to improve a nations’navigation capabilities. The current state-of-the-art includesatomic clocks, GPS and computerized maps, as well as a wholeconstellation of government organizations.

This cycle of continual improvement has fueled manymathematical discoveries and it is within this story that we find theorigins of the Fast Fourier Transform. In particular, the FFT grewout of mathematical techniques for determining the orbit ofplanetary bodies.

Page 7: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Orbit as a Periodic Curve

The orbit of a body like a planet can be modeled by a curve

c : [0,T ]→ R3,

For a given time 0 ≤ t ≤ T , the function produces a location

c(t) = (x(t), y(t), z(t))

in some unspecified coordinate system. We assume the motion isperiodic with period T to extend the function to any time:

c(t + T ) = c(t) (t ∈ R).

Example. The Earth’s orbit is approximately circular (eccentricity0.01671123) with period 365.256 days.

Page 8: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Orbit Determination

Imagine an Earth-bound observatory as it tracks a planet. Theastronomers record a sequence of observations derived from the(unknown) orbital curve c : [0,T ]→ R3, with the intention ofpredicting the future location of the body. The problem ofrecovering the function c from observations is called orbitdetermination.

Because the underlying function c is periodic, the derivedobservations are also periodic. Due to work in orbital mechanics,numerous techniques were developed to approximate periodicfunctions using linear combinations of trigonometric functions.

Page 9: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Spotting a Missing ’Planet’

The planets Mecury, Venus, Mars, Jupiter and Saturn were knownto the Babylonians. The 18th century brought the discovery ofUranus, whose nearly circular orbit was relatively easy todetermine. The location of Uranus fit the Titus-Bode law, whichalso predicted a planet between Mars and Jupiter.

At the beginning of the 19th century, Giuseppe Piazza observed anobject in this predicted location. It was smaller than any objectknown to date. At 950km in diameter, Ceres is the largest objectin the asteroid belt between Mars and Jupiter. Discovered on 1January 1801, Piazzi made 21 observations over 42 days beforelosing the object in the sun. A race ensued to recover the orbit ofCeres and capture new observations of the presumed planet.

Page 10: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Enter Gauss

After working in number theory and completing a dissertation onthe fundamental theorem of algebra, the twenty four year old CarlFriedrich Gauss turned to the problem of determining the orbit ofCeres from Piazzi’s limited number of observations.

Gauss developed a technique based on Kepler’s laws of motion andthe theory of conic sections. An overview of the method andfurther resources can be found in this presentation. Based on hispredictions, Ceres was again observed in December of 1801.

Here are a few amazing facts about Gauss’ method.

1. Requires only three Earth-based measurements.

2. One of the first demonstrations of the method of least squares.

3. Developed the FFT to quickly interpolate periodic functions.

Page 11: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Table of Contents

History of the FFT

The Discrete Fourier Transform

The Fast Fourier Transform

MP3 Compression via the DFT

The Fourier Transform in Mathematics

Page 12: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

The Discrete Fourier Transform

Problem Given N equally spaced measurements of a periodicfunction, write down an interpolating trigonometric polynomial.

The answer to this problem is prescribed by the discrete Fouriertransform (DFT). Given the sequence x0, x1, . . . , xN−1 of Ncomplex-valued measurements, define

x̂k =1√N

N−1∑n=0

xn exp(−2πikn/N) (k = 0, 1, . . . ,N − 1).

This expression defines a linear transformation F : CN → CN

called the discrete Fourier tranform.

Page 13: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Interpolating Polynomial

Figure: Original function in blue,16 samples and interpolant in red.

Given the DFT of N equallyspaced samples of a periodicfunction

g : [0, 1]→ C,

we can write an interpolatingtrigonometric polynomial as

g̃(t) =∑|n|≤N/2

x̂n exp(2πint)

using that the DFT is periodic.

Page 14: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

DFT as Coordinate Transformation

Let N = 8 and ω8 = exp(−2πi/8). Consider the vectors

u0 =1√8〈1, 1, . . . , 1〉

u1 =1√8〈1, ω8, ω

28, . . . , ω

78〉

...

uk =1√8〈1, ωk

8 , ω2k8 , . . . , ω7k

8 〉

...

u7 =1√8〈1, ω7

8, ω148 , . . . , ω

498 〉

which are sampled versions of the complex exponentials. Theseeight vectors form an orthonormal basis for C8.

Page 15: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Orthogonality

Given the definition

uk =1√8〈1, ωk

8 , ω2k8 , . . . , ω7k

8 〉

consider the inner product

uTk u∗k ′ =

1

8

7∑n=0

exp(−2πikn/N) exp(2πik ′n/8)

=1

8

7∑n=0

ω(k−k ′)n8 = δkk ′ .

This follows from the sum of thegeometric progression, or by the visualproof to the right.

Figure: A visualization ofthe roots of unity W 3n

8 ,corresponding to k = 6and k ′ = 3.

Page 16: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Basis as Sampled Complex Exponential

Figure: This graph depicts u3overlayed on f3; the real part inblue and the imaginary part in red.

We have sampled the function

f3(t) =1√8

exp(−2πi(3t))

uniformly at values

t ∈{

0,1

8,

2

8, . . . ,

7

8

}resulting in

u3 =1√8〈1, ω3

8, ω68, . . . , ω

218 〉.

Page 17: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

DFT in Matrix Form

Focusing again on N = 8, we can write the DFT in matrix form

x̂0x̂1x̂2x̂3x̂4x̂5x̂6x̂7

=

1√8

1 1 1 1 1 1 1 11 ω8 ω2

8 ω38 ω4

8 ω58 ω6

8 ω78

1 ω28 ω4

8 ω68 ω8

8 ω108 ω12

8 ω148

1 ω38 ω6

8 ω98 ω12

8 ω158 ω18

8 ω218

1 ω48 ω8

8 ω128 ω16

8 ω208 ω24

8 ω288

1 ω58 ω10

8 ω158 ω20

8 ω258 ω30

8 ω358

1 ω68 ω12

8 ω188 ω24

8 ω308 ω36

8 ω428

1 ω78 ω14

8 ω218 ω28

8 ω358 ω42

8 ω498

x0x1x2x3x4x5x6x7

.

Or, more compactly, x̂ = W x, where W is the Vandermode matrix.Observe that the k-th row and column is simply the vector uk .Hence the matrix W is unitary, W ∗W = I .

This formulation yields a cost of O(N2) multiplication operations.

Page 18: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Table of Contents

History of the FFT

The Discrete Fourier Transform

The Fast Fourier Transform

MP3 Compression via the DFT

The Fourier Transform in Mathematics

Page 19: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

The Discrete Fourier Transform

Recall that given a vector x = 〈x0, x1, . . . , xN−1〉 ∈ CN its discreteFourier transform is another vector x̂ ∈ CN given by

x̂k =1√N

N−1∑n=0

xnωnkN (k = 0, 1, . . . ,N − 1)

where ωN = exp(−2πi/N).

Problem. How to compute the DFT more efficiently?

The Trick. Focus on the case N = 2m. Then we can partition xinto even- and odd-indexed components and write the DFT as twoDFTs of length m.

Page 20: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

The Fast Fourier Transform

Details for N = 2m:

x̂k =1√N

N−1∑n=0

xnωnkN

=1√N

m−1∑n=0

x2nω2nkN +

1√N

m−1∑n=0

x2n+1ω(2n+1)kN

=1√N

m−1∑n=0

x2nωnkm +

ωN√N

m−1∑n=0

x2n+1ωnkm

When N = 2m, a divide and conquer scheme leads to theconceptually simple, recursive radix-2 formulation.

Page 21: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

WARNING!

DO NOT IMPLEMENT YOURSELF!

While it seems easy, refrain from reinventing the wheel (except foreducational purposes). Even the creators of Matlab have notattempted to implement the FFT. They chose to use the FastestFourier Transform in the West (FFTW).

You may also investigate hardware vendor-provided libraries.

Page 22: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Computational Cost of FFT

Let’s count the number of multiplications for the case N = 24.

16-point DFT 162 = 256 multipliesTwo 8-point DFTs 2 ∗ (82) = 128 multipliesFour 4-point DFTs 2 ∗ 2 ∗ (42) = 64 multipliesEight 2-point DFTs 2 ∗ 2 ∗ 2 ∗ (22) = 64 multiplies

The recursive formulation of the radix-2 algorithm has acomplexity of O(N log2N) multiplication operations. In fact, thisis the complexity for a general value of N.

The efficiency of the FFT can also be viewed as a specialfactorization of the Vandermonde matrix.

Page 23: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Variations of the FFT

There are numerous variations of the FFT algorithm.

1. Cooley-Tukey (arbitrary length)

2. Rader (prime length)

3. Bluestein (arbitrary length)

The recursive nature of the FFT depends on the factorization ofthe length

N = N1N2 . . .Nm.

FFTW is fast partly because it cleverly combines the abovealgorithms based on N and the machine architecture.

Page 24: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Table of Contents

History of the FFT

The Discrete Fourier Transform

The Fast Fourier Transform

MP3 Compression via the DFT

The Fourier Transform in Mathematics

Page 26: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Recording Sound

A description of the previous schematic.

1. Sound is the propagation of mechnical waves through the air.

2. A microphone converts pressure variations into voltagefluctuations.

3. An analog-to-digital converter creates a sequence of samplesfrom electrical signal. For CD-quality sound, 44100 samplesoccur each second and each is measured with 16-bit accuracy.

4. The samples are commonly encoded in a PCM format likeWAV or AIFF.

We model a (single-channel) sound file as an element of RN whereeach component has value in the range [−1, 1]. Note that N is theproduct of the length of the recording and the sample rate.

Page 27: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Compression of Data and Sound Perception

The MP3 format is a lossy compression scheme; information isdiscarded to acheive smaller file size. But how to decide what datato through away? In the time-domain, it’s not clear how toproceed without significantly affecting sound quality.

The key insight for the MP3 format relies on perception of soundin the human brain. The first step is to understand that the brainessentially performs a Fourier transform on sound. If one played apure sinusoidal sound through a speaker, a listener would recognizethe sound as consisting of a single frequency.

Page 28: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Frequency Masking

This signal exhibits two clusters ofenergy, close together in frequency butone of much greater amplitude. Due toa phenomenon called auditory masking,the average human would havedifficulty perceiving the frequencieshighlighted in red.

Using spectrum analysis and limitationsof human hearing, we can decide whatdata in frequency space to discard!

Figure: Magnitude ofDFT of signal of lengthN = 100.

Page 29: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

The Basic MP3 Algorithm

Input: sampled sound as a vector in RN .

1. Subdivide sound file into small snippets called ’frames’.

2. For each frame:

2.1 Compute DFT vector.2.2 Apply frequency masking to approximate spectrum.2.3 Losslessly compress (zip) modified DFT vector.

To decode, unzip and perform an inverse DFT on each frame.Both encoding and decoding require the FFT.

The JPEG algorithm is structurally similar, using knowledge ofhuman vision to decide which Fourier coefficients to discard.

Page 30: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Table of Contents

History of the FFT

The Discrete Fourier Transform

The Fast Fourier Transform

MP3 Compression via the DFT

The Fourier Transform in Mathematics

Page 31: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

The Fourier Transform

The DFT is one of many version of a very general tool called theFourier transform, which is used in many branches of modernmathematics. We considered the DFT as a linear operator on thevector space CN , but we could also consider the vector x as adiscrete complex-valued function

x : ZN → C.

That is, x is a map from the cyclic group ZN into the complexnumbers C. Here ZN is the set {0, 1, 2, . . . ,N − 1} with modularaddition as the operation. We were able to decompose thefunction x into a linear combination of special functions

uk : ZN → C (k = 0, 1, 2, . . . ,N − 1)

called characters.

Page 32: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Harmonic Analysis

In general, we may begin with any locally compact abelian groupG and consider complex-valued functions

f : G → C.

The field of harmonic analysis studies the characters of G andattempts to decompose functions like f in terms of the characters(which also forms a locally compact abelian group).

The most familiar choices of G are

1. ZN

2. Z3. T = [−π, π]

4. R.

Page 33: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Theory of Fourier Series

For a periodic functionf : T→ C

the Fourier transform is given by

c(n) =1√2π

∫ π

−πf (x) exp(−inx) dx (n ∈ Z).

This expression defines a function c : Z→ C, so we say that T isthe dual group to Z. We can invert the transform by the formula

f (x) =1√2π

∞∑n=−∞

c(n) exp(inx).

The Fourier transform on T and R is an essential tool in the theoryof partial differential equations, as discovered by Joseph Fourier inhis work on the heat equation.

Page 34: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Linear Partial Differential Equations

An evolution equation is a partial differential equation whichdescribes the time evolution of a physical system starting from agiven initial configuration.

Example. The solution to the initial value problem{∂tv + ∂3xv = 0

v(x , 0) = v0(x)

with x , t ∈ R is provided by Fourier analysis

v(x , t) = [e−itξ3v̂0]∨(x) = V (t)v0.

That is, we take Fourier transform of initial data, multiply thespectrum by e−itξ

3and then take inverse transform. It can then be

proved using this formula that many properties of the solution areinherited from the initial data.

Page 35: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Nonlinear Partial Differential Equations

What about the nonlinear KdV equation?{∂tu + ∂3xu + u∂xu = 0

u(x , 0) = u0(x)

Using Duhamel’s principle for inhomogeneous differentialequations, we can represent the solution (implicitly) as acombination of a linear and inhomogeneous term

u(x , t) = V (t)u0 +

∫ t

0V (t − t ′)(u∂xu)(x , t ′) dt ′.

Using the linear theory and the contraction mapping principle, onecan prove existence of solutions to this integral equation. Thisrepresentation also allows one to show that many properties of thesolution are inherited from the initial data.

Page 36: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Fourier Transform in Applied Mathematics

Signal ProcessingMuch of the history of the FFT is tied to the field of signalprocessing, from Gauss’ work to that of Cooley and Tukey. Thelater were concerned with analyzing seismographic data to detectSoviet nuclear tests. The DFT and related Z-transform areessential in designing digital filters. Computer scientists study thediscrete Fourier analysis of boolean functions.

AnalysisIn functional analysis, the Gelfand representation is ageneralization of the Fourier transform. The Hilbert transformprovides a connection between complex and Fourier analysis. TheKakeya problem has connections to harmonic analysis andgeometric measure theory.

Page 37: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

Fourier Transform in Pure Mathematics

Algebra and TopologyThe Fourier transform may be viewed as a specific case ofrepresentation theory. The theory can be easily extended toarbitrary finite groups and, with more work, to compact topologicalgroups via the Peter-Weyl Theorem.

Number TheoryFourier analysis can be used to understand the Hardy-LittlewoodCircle Method, which has been used to attack Goldbach’sconjecture. Shor’s algorithm is a technique for factoring integersusing the quantum Fourier tranform. The discrete Fouriertransform may also be generalized for functions taking values inarbitrary fields. This so-called “number theoretic transform” findsapplication in efficiently multiplying large integers using a versionof the FFT.

Page 38: The Fast Fourier Transformweb.math.ucsb.edu/~dls/Expository/2014-10-FFT.pdf · origins of the Fast Fourier Transform. In particular, the FFT grew out of mathematical techniques for

[1] James W. Cooley and John W. Tukey, An algorithm for the machinecalculation of complex Fourier series, Math. Comp. 19 (1965), 297–301.MR0178586 (31 #2843)

[2] Michael T. Heideman, Don H. Johnson, and C. Sidney Burrus, Gauss andthe history of the fast Fourier transform, Arch. Hist. Exact Sci. 34 (1985),no. 3, 265–277, DOI 10.1007/BF00348431. MR815154 (87f:01018)