Lecture 16: Discrete Fourier Transform, Spherical Harmonics - - PowerPoint PPT Presentation

lecture 16 discrete fourier transform spherical harmonics
SMART_READER_LITE
LIVE PREVIEW

Lecture 16: Discrete Fourier Transform, Spherical Harmonics - - PowerPoint PPT Presentation

Lecture 16: Discrete Fourier Transform, Spherical Harmonics COMPSCI/MATH 290-04 Chris Tralie, Duke University 3/8/2016 COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics Announcements Mini Assignment 3 due


slide-1
SLIDE 1

Lecture 16: Discrete Fourier Transform, Spherical Harmonics

COMPSCI/MATH 290-04

Chris Tralie, Duke University

3/8/2016

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-2
SLIDE 2

Announcements

⊲ Mini Assignment 3 due Sunday 3/13 11:55PM ⊲ Group Assignment 2 Out around Friday/Saturday, due Monday 3/28 ⊲ Final projects assigned, first milestone due Wednesday 4/6 ⊲ Midterm Thursday

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-3
SLIDE 3

Table of Contents

◮ Numpy Squared Euclidean Distances ⊲ Discrete Fourier Transform ⊲ Spherical Harmonics

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-4
SLIDE 4

Numpy: More Broadcasting

import numpy as np import matplotlib.pyplot as plt X = np.arange(4) Y = np.arange(6) Z = X[:, None] + Y[None, :] print Z

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-5
SLIDE 5

Squared Euclidean Distances in Matrix Form

Notice that || a − b||2 = ( a − b) · ( a − b) || a − b||2 = a · a + b · b − 2 a · b

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-6
SLIDE 6

Squared Euclidean Distances in Matrix Form

Notice that || a − b||2 = ( a − b) · ( a − b) || a − b||2 = a · a + b · b − 2 a · b Given points clouds X and Y expressed as 2 × M and 2 × N matrices, respectively, write code to compute an M × N matrix D so that D[i, j] = ||X[:, i] − Y[:, j]||2 Without using any for loops! Can use for ranking with Euclidean distance or D2 shape histograms, for example

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-7
SLIDE 7

Brute Force Nearest Neighbors

import numpy as np import matplotlib.pyplot as plt t = np.linspace(0, 2*np.pi, 100) X = np.zeros((2, len(t))) X[0, :] = t X[1, :] = np.cos(t) Y = np.zeros((2, len(t))) Y[0, :] = t Y[1, :] = np.sin(t**1.2) ##FILL THIS IN TO COMPUTE DISTANCE MATRIX D idx = np.argmin(D, 1) #Find index of closest point in Y to point in X plt.plot(X[0, :], X[1, :], ’.’) plt.hold(True) plt.plot(Y[0, :], Y[1, :], ’.’, color = ’red’) for i in range(len(idx)): plt.plot([X[0, i], Y[0, idx[i]]], [X[1, i], Y[1, idx [i]]], ’b’) plt.axes().set_aspect(’equal’, ’datalim’); plt.show()

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-8
SLIDE 8

Mini Assignment 3 API

def getCentroid(PC): return np.zeros((3, 1)) #Dummy value def getCorrespondences(X, Y, Cx, Cy, Rx): return np.zeros(X.shape[1], dtype=np.int64) #dummy value def getProcrustesAlignment(X, Y, idx): return (Cx, Cy, R) #what the ICP algorithm did def doICP(X, Y, MaxIters): CxList = [np.zeros((3, 1))] CyList = [np.zeros((3, 1))] RxList = [np.eye(3)] #TODO: Fill the rest of this in return (CxList, CyList, RxList)

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-9
SLIDE 9

Table of Contents

⊲ Numpy Squared Euclidean Distances ◮ Discrete Fourier Transform ⊲ Spherical Harmonics

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-10
SLIDE 10

Discrete Cosine Integration

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-11
SLIDE 11

Discrete Cosine Integration

What is

N=kT

  • t=1

cos2(2πt T ) ? Note that cos2(A) = 1+cos(2A)

2

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-12
SLIDE 12

Discrete Cosine Integration

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-13
SLIDE 13

Discrete Cosine Integration

Why is N=kT

t=1

cos( 2πt

T ) sin( 2πt T ) zero?

Note that cos(A) sin(A) = 1 2 sin(2A)

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-14
SLIDE 14

Discrete Cosine Integration

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-15
SLIDE 15

Discrete Cosine Integration

Why does the product of two different cosines integrate to zero? cos(A + B) = cos(A) cos(B) − sin(A) sin(B)

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-16
SLIDE 16

Discrete Cosine Integration

Why does the product of two different cosines integrate to zero? cos(A + B) = cos(A) cos(B) − sin(A) sin(B) Hint: cos(A + B) + cos(A − B) =?

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-17
SLIDE 17

Discrete Cosine Integration

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-18
SLIDE 18

Discrete Cosine Integration

Dot product interpretation

  • s1 =
  • 1, cos

2π T1

  • , cos

2π2 T1

  • . . . , cos

2πN T1

  • s2 =
  • 1, cos

2π T2

  • , cos

2π2 T2

  • . . . , cos

2πN T2

  • Dot product is linear!
  • s2 · (a

s1 + b s2) = a s1 · s2 + b s2 · s2 Can use this type of dot product / integration to detect / test for the presence of different frequencies

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-19
SLIDE 19

Cosine Phase Separation

The general form of a sinusoid is A cos(ωt + φ) A cos(ωt + φ) = A cos(φ) cos(ωt) − A sin(φ) sin(ωt)

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-20
SLIDE 20

Cosine Phase Separation

The general form of a sinusoid is A cos(ωt + φ) A cos(ωt + φ) = A cos(φ) cos(ωt) − A sin(φ) sin(ωt) cos(ωt)(A cos(ωt+φ)) = A cos(φ) cos2(ωt)−A cos(ωt) sin(φ) sin(ωt)

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-21
SLIDE 21

Cosine Phase Separation

The general form of a sinusoid is A cos(ωt + φ) A cos(ωt + φ) = A cos(φ) cos(ωt) − A sin(φ) sin(ωt) cos(ωt)(A cos(ωt+φ)) = A cos(φ) cos2(ωt)−A cos(ωt) sin(φ) sin(ωt) ⊲ The “cosine component” of the sinusoid is A cos(φ) ⊲ The “sinusoid component” of the sinusoid is A sin(φ)

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-22
SLIDE 22

Cosine Phase Separation

The general form of a sinusoid is A cos(ωt + φ) A cos(ωt + φ) = A cos(φ) cos(ωt) − A sin(φ) sin(ωt) cos(ωt)(A cos(ωt+φ)) = A cos(φ) cos2(ωt)−A cos(ωt) sin(φ) sin(ωt) ⊲ The “cosine component” of the sinusoid is A cos(φ) ⊲ The “sinusoid component” of the sinusoid is A sin(φ) ⊲ The magnitude A of this sinusoid is

  • (A cos(φ))2 + (A sin(φ))2 = A (sanity check)

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-23
SLIDE 23

Sinusoidal Coordinates Basis

For a signal of length N (let N be odd for the moment), define the following matrix F =                 1 1 1 . . . 1 1 cos( 2π

N )

cos(2 2π

N )

. . . cos((N − 1) 2π

N )

sin( 2π

N )

sin(2 2π

N )

. . . sin((N − 1) 2π

N )

1 cos( 4π

N )

cos(2 4π

N )

. . . cos((N − 1) 4π

N )

sin( 4π

N )

sin(2 4π

N )

. . . sin((N − 1) 4π

N )

. . . . . . . . . . . . . . . 1 cos( ((N−1)π

N

) cos(2 (N−1)π

N

) . . . cos((N − 1) (N−1)π

N

) sin( (N−1)π

N

) sin(2 (N−1)π

N

) . . . sin((N − 1) (N−1)π

N

)                 COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-24
SLIDE 24

Each row is perpendicular to each other row. This means that Fx Is a high dimensional rotation! This means these sinusoids form a basis for all signals of length N. This is known as the Discrete Fourier Transform

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-25
SLIDE 25

Discrete Fourier Transform: Example

Show sinusoidal addition

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-26
SLIDE 26

Discrete Fourier Transform: Example

Show sinusoidal addition

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-27
SLIDE 27

Discrete Fourier Transform: Formal Definition

The formal definition of the Discrete Fourier Transform uses complex numbers to store the phase, for convenience F[k] =

N−1

  • t=0

X[n]e−i2π k

N n

F[k] =

N−1

  • t=0

X[n] cos

  • 2π k

N n

  • + i

N−1

  • t=0

X[n] sin

  • −2π k

N n

  • F[k] = Re(F[k]) + iImag(F[k])

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-28
SLIDE 28

Inverse Discrete Fourier Transform

DFT decomposed X into a bunch of sinusoids, now add them back together X[n] =

N−1

  • k=0

F[k]ei2π k

N n COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics

slide-29
SLIDE 29

Functions on The Circle

COMPSCI/MATH 290-04 Lecture 16: Discrete Fourier Transform, Spherical Harmonics