5 6 Convolution and FFT Fast Fourier Transform



![Polynomials: Coefficient Representation Polynomial. [coefficient representation] Add: O(n) arithmetic operations. Evaluate: O(n) using Horner's Polynomials: Coefficient Representation Polynomial. [coefficient representation] Add: O(n) arithmetic operations. Evaluate: O(n) using Horner's](https://slidetodoc.com/presentation_image_h2/4a97b20db34fcf3a52d04e82201fd60d/image-4.jpg)

![Polynomials: Point-Value Representation Polynomial. [point-value representation] Add: O(n) arithmetic operations. Multiply: O(n), but need Polynomials: Point-Value Representation Polynomial. [point-value representation] Add: O(n) arithmetic operations. Multiply: O(n), but need](https://slidetodoc.com/presentation_image_h2/4a97b20db34fcf3a52d04e82201fd60d/image-6.jpg)


















- Slides: 24

5. 6 Convolution and FFT

Fast Fourier Transform: Applications. Optics, acoustics, quantum physics, telecommunications, control systems, signal processing, speech recognition, data compression, image processing. DVD, JPEG, MP 3, MRI, CAT scan. Numerical solutions to Poisson's equation. n n n The FFT is one of the truly great computational developments of this [20 th] century. It has changed the face of science and engineering so much that it is not an exaggeration to say that life as we know it would be very different without the FFT. 2

Fast Fourier Transform: Brief History Gauss (1805, 1866). Analyzed periodic motion of asteroid Ceres. Runge-König (1924). Laid theoretical groundwork. Danielson-Lanczos (1942). Efficient algorithm. Cooley-Tukey (1965). Monitoring nuclear tests in Soviet Union and tracking submarines. Rediscovered and popularized FFT. Importance not fully realized until advent of digital computers. 3
![Polynomials Coefficient Representation Polynomial coefficient representation Add On arithmetic operations Evaluate On using Horners Polynomials: Coefficient Representation Polynomial. [coefficient representation] Add: O(n) arithmetic operations. Evaluate: O(n) using Horner's](https://slidetodoc.com/presentation_image_h2/4a97b20db34fcf3a52d04e82201fd60d/image-4.jpg)
Polynomials: Coefficient Representation Polynomial. [coefficient representation] Add: O(n) arithmetic operations. Evaluate: O(n) using Horner's method. Multiply (convolve): O(n 2) using brute force. 4

Polynomials: Point-Value Representation Fundamental theorem of algebra. A degree n polynomial with complex coefficients has n complex roots. Corollary. A degree n-1 polynomial A(x) is uniquely specified by its evaluation at n distinct values of x. y yj = A(xj) xj x 5
![Polynomials PointValue Representation Polynomial pointvalue representation Add On arithmetic operations Multiply On but need Polynomials: Point-Value Representation Polynomial. [point-value representation] Add: O(n) arithmetic operations. Multiply: O(n), but need](https://slidetodoc.com/presentation_image_h2/4a97b20db34fcf3a52d04e82201fd60d/image-6.jpg)
Polynomials: Point-Value Representation Polynomial. [point-value representation] Add: O(n) arithmetic operations. Multiply: O(n), but need 2 n-1 points. Evaluate: O(n 2) using Lagrange's formula. 6

Converting Between Two Polynomial Representations Tradeoff. Fast evaluation or fast multiplication. We want both! Representation Multiply Evaluate Coefficient O(n 2) O(n) Point-value O(n) O(n 2) Goal. Make all ops fast by efficiently converting between two representations. O(n log n) coefficient representation point-value representation 7

Converting Between Two Polynomial Representations: Brute Force Coefficient to point-value. Given a polynomial a 0 + a 1 x +. . . + an-1 xn -1, evaluate it at n distinct points x , . . . , x. 0 n-1 O(n 2) for matrix-vector multiply O(n 3) for Gaussian elimination Vandermonde matrix is invertible iff x i distinct Point-value to coefficient. Given n distinct points x 0, . . . , xn-1 and values y 0, . . . , yn-1, find unique polynomial a 0 + a 1 x +. . . + an-1 xn-1 that has given values at given points. 8

Coefficient to Point-Value Representation: Intuition Coefficient to point-value. Given a polynomial a 0 + a 1 x +. . . + an-1 xn-1, evaluate it at n distinct points x 0, . . . , xn-1. Divide. Break polynomial up into even and odd powers. A(x) = a 0 + a 1 x + a 2 x 2 + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7. Aeven(x) = a 0 + a 2 x + a 4 x 2 + a 6 x 3. Aodd (x) = a 1 + a 3 x + a 5 x 2 + a 7 x 3. A(-x) = Aeven(x 2) + x Aodd(x 2). A(-x) = Aeven(x 2) - x Aodd(x 2). n n n Intuition. Choose two points to be 1. A(-1) = Aeven(1) + 1 Aodd(1). A(-1) = Aeven(1) - 1 Aodd(1). n n Can evaluate polynomial of degree n at 2 points by evaluating two polynomials of degree ½n at 1 point. 9

Coefficient to Point-Value Representation: Intuition Coefficient to point-value. Given a polynomial a 0 + a 1 x +. . . + an-1 xn-1, evaluate it at n distinct points x 0, . . . , xn-1. Divide. Break polynomial up into even and odd powers. A(x) = a 0 + a 1 x + a 2 x 2 + a 3 x 3 + a 4 x 4 + a 5 x 5 + a 6 x 6 + a 7 x 7. Aeven(x) = a 0 + a 2 x + a 4 x 2 + a 6 x 3. Aodd (x) = a 1 + a 3 x + a 5 x 2 + a 7 x 3. A(-x) = Aeven(x 2) + x Aodd(x 2). A(-x) = Aeven(x 2) - x Aodd(x 2). n n n Intuition. Choose four points to be 1, i. A(-1) = Aeven(-1) + 1 Aodd( 1). A(-1) = Aeven(-1) - 1 Aodd(-1). Can evaluate polynomial of degree n A(-i) = Aeven(-1) + i Aodd(-1). at 4 points by evaluating two polynomials A(-i) = Aeven(-1) - i Aodd(-1). of degree ½n at 2 points. n n 10

Discrete Fourier Transform Coefficient to point-value. Given a polynomial a 0 + a 1 x +. . . + an-1 xn-1, evaluate it at n distinct points x 0, . . . , xn-1. Key idea: choose xk = k where is principal nth root of unity. Discrete Fourier transform Fourier matrix Fn 11

Roots of Unity Def. An nth root of unity is a complex number x such that xn = 1. Fact. The nth roots of unity are: 0, 1, …, n-1 where = e 2 i / n. Pf. ( k)n = (e 2 i k / n) n = (e i ) 2 k = (-1) 2 k = 1. Fact. The ½nth roots of unity are: 0, 1, …, n/2 -1 where = e 4 i / n. Fact. 2 = and ( 2)k = k. 2 = 1 = i 3 1 n=8 4 = 2 = -1 0 = 1 7 5 6 = 3 = -i 12

Fast Fourier Transform Goal. Evaluate a degree n-1 polynomial A(x) = a 0 +. . . + an-1 xn-1 at its nth roots of unity: 0, 1, …, n-1. Divide. Break polynomial up into even and odd powers. Aeven(x) = a 0 + a 2 x + a 4 x 2 + … + an/2 -2 x(n-1)/2. Aodd (x) = a 1 + a 3 x + a 5 x 2 + … + an/2 -1 x(n-1)/2. A(x) = Aeven(x 2) + x Aodd(x 2). n n n Conquer. Evaluate degree Aeven(x) and Aodd(x) at the ½nth roots of unity: 0, 1, …, n/2 -1. Combine. A( k+n) = Aeven( k) + k Aodd( k), 0 k < n/2 A( k+n) = Aeven( k) - k Aodd( k), 0 k < n/2 n k = ( k)2 = ( k+n)2 n k+n = - k 13

FFT Algorithm fft(n, a 0, a 1, …, an-1) { if (n == 1) return a 0 (e 0, e 1, …, en/2 -1) FFT(n/2, a 0, a 2, a 4, …, an-2) (d 0, d 1, …, dn/2 -1) FFT(n/2, a 1, a 3, a 5, …, an-1) for k = k yk+n/2 } 0 to n/2 - 1 { e 2 ik/n e k + k d k e k - k d k return (y 0, y 1, …, yn-1) } 14

FFT Summary Theorem. FFT algorithm evaluates a degree n-1 polynomial at each of the nth roots of unity in O(n log n) steps. assumes n is a power of 2 Running time. T(2 n) = 2 T(n) + O(n) T(n) = O(n log n) coefficient representation point-value representation 15

Recursion Tree a 0, a 1, a 2, a 3, a 4, a 5, a 6, a 7 perfect shuffle a 0 , a 2 , a 4 , a 6 a 0 , a 4 a 1, a 3, a 5, a 7 a 2 , a 6 a 3 , a 7 a 1, a 5 a 0 a 4 a 2 a 6 a 1 a 5 a 3 a 7 000 100 010 110 001 101 011 111 "bit-reversed" order 16

Point-Value to Coefficient Representation: Inverse DFT Goal. Given the values y 0, . . . , yn-1 of a degree n-1 polynomial at the n points 0, 1, …, n-1, find the unique polynomial a 0 + a 1 x +. . . + an-1 xn-1 that has given values at given points. Inverse DFT Fourier matrix inverse (Fn)-1 17

Inverse FFT Claim. Inverse of Fourier matrix is given by following formula. Consequence. To compute inverse FFT, apply same algorithm but use -1 = e -2 i / n as principal nth root of unity (and divide by n). 18

Inverse FFT: Proof of Correctness Claim. Fn and Gn are inverses. Pf. summation lemma Summation lemma. Let be a principal nth root of unity. Then Pf. n n n If k is a multiple of n then k = 1 sums to n. Each nth root of unity k is a root of xn - 1 = (x - 1) (1 + x 2 +. . . + xn-1). if k 1 we have: 1 + k(2) +. . . + k(n-1) = 0 sums to 0. ▪ 19

Inverse FFT: Algorithm ifft(n, a 0, a 1, …, an-1) { if (n == 1) return a 0 (e 0, e 1, …, en/2 -1) FFT(n/2, a 0, a 2, a 4, …, an-2) (d 0, d 1, …, dn/2 -1) FFT(n/2, a 1, a 3, a 5, …, an-1) for k = k yk+n/2 } 0 to n/2 - 1 { e-2 ik/n (ek + k dk) / n (ek - k dk) / n return (y 0, y 1, …, yn-1) } 20

Inverse FFT Summary Theorem. Inverse FFT algorithm interpolates a degree n-1 polynomial given values at each of the nth roots of unity in O(n log n) steps. assumes n is a power of 2 O(n log n) coefficient representation O(n log n) point-value representation 21

Polynomial Multiplication Theorem. Can multiply two degree n-1 polynomials in O(n log n) steps. coefficient representation FFT coefficient representation O(n log n) inverse FFT O(n log n) point-value multiplication O(n) 22

Course summary Major computational problems: § § § § DFS BFS Dijkstra’s algorithm Bellman-Ford algorithm Scheduling algorithms (e. g. interval partitioning) Knapsack – fractional, 0, 1 -version, integer version String similarity and edit distance – Smith-Waterman algorithm RNA folding Network flow k-connectivity Maximum matching in a bipartite graph Sorting Integer multiplication (Karatsuba’s algorithm) Fast Fourier Transform Polynomial multplication 23

Course summary Major computational problems (color coded by technique): § § § § • Generic DFS • Greedy BFS • Dynamic programming Dijkstra’s algorithm • Iterative improvement Bellman-Ford algorithm Scheduling algorithms (e. g. interval partitioning) • Divide and conquer Knapsack – fractional, 0, 1 -version, integer version String similarity and edit distance – Smith-Waterman algorithm RNA folding Network flow k-connectivity Maximum matching in a bipartite graph Sorting Integer multiplication (Karatsuba’s algorithm) Fast Fourier Transform Polynomial multiplication 24