11
The Fast Fourier Transform Andreas Klappenecker

The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

  • Upload
    lykiet

  • View
    217

  • Download
    0

Embed Size (px)

Citation preview

Page 1: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

The Fast Fourier Transform Andreas Klappenecker

Page 2: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Fourier Transform in Matrix Form

For a polynomial A(x) = a0 + a1x + ... + an-1xn-1 of degree n-1, a conversion from coefficient representation to p.v. representation at n distinct points 1, 𝜔, ..., 𝜔n-1 can be done as follows:

0

BBB@

y0y1...

yn�1

1

CCCA=

0

BBB@

1 1 1 · · · 11 ! !2 · · · !n�1

......

.... . .

...

1 !n�1 !2(n�1) · · · !(n�1)2

1

CCCA

0

BBB@

a0a1...

an�1

1

CCCA

Page 3: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Fast Fourier Transform

Evaluate a degree n-1 polynomial A(x) = a0 + ... + an-1 xn-1 at its nth roots of unity: ω0, ω1 1, …, ωn-1.

Divide. Divide the polynomial into even and odd powers.

A(x) = Aeven(x2) + x Aodd(x2).

Conquer. Evaluate Aeven(x) and Aodd(x) at the ½nth roots of unity: ν0, ν1, …, νn/2-1.

Combine.

A(ωk) = Aeven(νk) + ωk Aodd(νk), 0 ≤ k < n/2

A(ωk+n/2) = Aeven(νk) - ωk Aodd(νk), 0 ≤ k < n/2

Page 4: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Fourier Transform in Matrix Form

0

BBB@

A(1)A(!)...

A(!n�1)

1

CCCA=

0

BBB@

1 1 1 · · · 11 ! !2 · · · !n�1

......

.... . .

...

1 !n�1 !2(n�1) · · · !(n�1)2

1

CCCA

0

BBB@

a0a1...

an�1

1

CCCA

Split into even and odd powers (green and gray)

Realize that 1, ꙍ, …,ꙍn/2-1,-1,-ꙍ,…,-ꙍn/2-1 (upper/lower part)

Each gray column vector is two copies of the same vector

Page 5: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Reorganization0

BBB@

A(1)A(!)...

A(!n�1)

1

CCCA=

0

BBB@

1 1 1 · · · 11 ! !2 · · · !n�1

......

.... . .

...

1 !n�1 !2(n�1) · · · !(n�1)2

1

CCCA

0

BBB@

a0a1...

an�1

1

CCCA

P =

0

BBBBBBBBBBBB@

1 0 0 0 · · · 0 00 0 1 0 · · · 0 0

...0 0 0 0 · · · 1 00 1 0 0 · · · 0 00 0 0 1 · · · 0 0

...0 0 0 0 · · · 0 1

1

CCCCCCCCCCCCA

Idea: Put grey columnstogether, and green columns together

Page 6: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Reorganization

= Fn/2

Fn/2

Page 7: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Reorganization

= Fn/2

Fn/2Fn/2

Fn/2 DFn/2

-DFn/2

D = diag(1,ω, ω2, …, ωn/2−1)

Page 8: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Fast Fourier Transform

Fn =

✓I DI �D

◆✓Fn/2 00 Fn/2

◆P

P =

0

BBBBBBBBBBBB@

1 0 0 0 · · · 0 00 0 1 0 · · · 0 0

...0 0 0 0 · · · 1 00 1 0 0 · · · 0 00 0 0 1 · · · 0 0

...0 0 0 0 · · · 0 1

1

CCCCCCCCCCCCA

D = diag(1,ω, ω2, …, ωn/2−1)

Page 9: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Fast Fourier Transform

Evaluate a degree n-1 polynomial A(x) = a0 + ... + an-1 xn-1 at its nth roots of unity: ω0, ω1 1, …, ωn-1.

Divide. Divide the polynomial into even and odd powers.

A(x) = Aeven(x2) + x Aodd(x2).

Conquer. Evaluate Aeven(x) and Aodd(x) at the ½nth roots of unity: ν0, ν1, …, νn/2-1.

Combine.

A(ωk) = Aeven(νk) + ωk Aodd(νk), 0 ≤ k < n/2

A(ωk+n/2) = Aeven(νk) - ωk Aodd(νk), 0 ≤ k < n/2

Page 10: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

FFT AlgorithmFFT(n, a0,a1,…,an-1) {

if (n == 1) return a0 (e0,e1,…,en/2-1) ← FFT(n/2, a0,a2,a4,…,an-2)

(d0,d1,…,dn/2-1) ← FFT(n/2, a1,a3,a5,…,an-1)

for k = 0 to n/2 - 1 { ωk ← e2πik/n

yk ← ek + ωk dk yk+n/2 ← ek - ωk dk }

return (y0,y1,…,yn-1)

}

Page 11: The Fast Fourier Transform - faculty.cs.tamu.edufaculty.cs.tamu.edu/klappi/csce411-s19/csce411-divideconquer4.pdf · Fourier Transform in Matrix Form For a polynomial A(x) = a 0 +

Summary

The FFT evaluates a polynomial of degree n-1 at n-th roots of unity in O(n log n) steps.

Inverse of FFT just as fast.

Can multiply two polynomials of degree n-1 in O(n log n) time using FFT of length 2n.

Find more details in CLRS or Kleinberg/Tardos.