introduction to fourier analysis –part 1cs510/yr2018sp/more... · introduction to fourier...

26
Introduction to Fourier Analysis – Part 1 CS 510 Lecture #6 January 29, 2018

Upload: others

Post on 27-Jul-2020

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Introduction to Fourier Analysis – Part 1

CS 510 Lecture #6

January 29, 2018

Page 2: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Why?

2/4/18

Get used to changing representations!

(and this particular transformation is ubiquitous and important)

2CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 3: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Why Fourier in Particular

• How much information can an image hold?– If I shrink it, then make it larger again, does it

look the same?– If I enlarge it and then shrink it again does it

look the same?– How about other transformations?

• How do I compare two images with different source resolutions?

2/4/18 CSU CS 510, ©Ross Beveridge & Bruce Draper 3

Page 4: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Image Data as a Function

2/4/18 4

Graphic from “Computer Graphics:Principles and Practice” by Foley, van Dam, Feiner & Hughes.

Þ g(x) =

u coordinate

Inte

nsity

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 5: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

2/4/18 5

Any repeating pattern can be built up from a sequence of sin/cosine waves.

Graphic adapted from http://www.revisemri.com/images/ft.gif

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 6: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

2/4/18 6

In th

e ex

trem

e, a

squa

re w

ave

Graphic from http://www.mechatronics.colostate.edu/figures/4-4.jpg

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 7: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Fourier Analysis ¹ Magic• Many textbooks make is obscure, but…• Rewrite a function f(x) over a finite range.

– In effect, we pretend it repeats– …and reconstruct it as a sum of sinusoids…

• For each sinusoid, we specify:– A frequency– An amplitude– A phase

2/4/18 7CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 8: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

The Sine Wave - Basics

2/4/18 8

Am

plitu

de

Period (Frequency = 1/Period)

Phase

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 9: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

The Sinusoid

2/4/18€

g x( ) = acos fx + φ( )Amplitude

Frequency

Phase

9CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 10: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Simplifying Phase• Phase – where wave crosses the x axis:

– If it crosses at 0 and -p, it’s a sine wave.– If it crosses at p/2 and - p/2, it a cosine wave.– In general, if it crosses at f and f + p radians,

it has phase f - p/2 (i.e., cosine, not sine)• f = 0 Þ cosine wave• f = p/2 Þ sine wave

• A wave with phase f can be expressed as:

2/4/18 10

cos x + φ( ) = αcos x( ) + βsin x( )

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 11: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Writing Phase

• Repeating the punchline from previous slide.

• A sinusoid of arbitrary phase can be written as the sum of a sine & cosine:

2/4/18€

cos x + φ( ) = αcos x( ) + βsin x( )

11CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 12: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Phase (II)

2/4/18 12

Where:

φ = tan−1 βα

&

' (

)

* +

cos θ + φ( ) = α 2 cos2 θ( ) + β2 sin2 θ( )

(q +f) still indicates that the curve has been shifted by f degrees.

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 13: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Therefore…

• Remaining problems– Now has twice as many terms (2 per frequency)– Must specify amplitude and frequency for each

2/4/18 13

g x( ) = a1 cos f1x( ) + b1 sin f1x( )+a2 cos f2x( ) + b2 sin f2x( )+a3 cos f3x( ) + b3 sin f3x( )+

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 14: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Visualization – Nice Introduction

2/4/18 14

http://www.tomasboril.cz/fourierseries3d/en/#

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 15: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Another great resource …

2/4/18 CSU CS 510, ©Ross Beveridge & Bruce Draper 15

Page 16: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

… I forgot to mention …

2/4/18 CSU CS 510, ©Ross Beveridge & Bruce Draper 16

Page 17: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Now, Per Frequency• For any given frequency f1 , we must

calculate the amplitude of the cosine and sine functions

• g(x) is infinite (x can be anything), so we have to fit the cosines and sines to all the data:

2/4/18 17

a1 = f x( )cos f1x( )dx−∞

+∞

∫ b1 = f x( )sin f1x( )dx−∞

+∞

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 18: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Representing Frequencies• Our function g(x) is infinitely repeating• Assume, WLOG, the unit of repetition is 1

– So g(0+x) = g(1+x) = g(2+x)…• Only cosines & sines with periods that are

integers make sense– Otherwise it wouldn’t repeat

• The cosine whose period is 1 is written as

2/4/18 18

cos 2πx( )

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 19: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Frequencies (cont).

• In general the frequency that repeats u times over the interval is written as

• Where u is any integer

2/4/18 19

cos 2πux( )

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 20: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

So, to rewrite g(x)• For every integer frequency u = 1, 2, 3, …

2/4/18 20

g x( ) = a1 cos 2π x( ) + b1 sin 2π x( )+ a2 cos 2π2x( ) + b2 sin 2π2x( )+ a3 cos 2π3x( ) + b3 sin 2π3x( )+ a4 cos 2π4x( ) + b4 sin 2π4x( )+…

au = g x( )cos 2πux( )dx−∞

∫ bu = g x( )sin 2πux( )dx−∞

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 21: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Fourier Transform

2/4/18 21

• Formally, the Fourier transform in 1D is:

Where:

u is an integer in the range from 0 to ¥–i is used to create a 2D vector spaceF(u) = au + ibu

F u( ) = f x( ) cos2πux − isin2πux[ ]dx−∞

+∞

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 22: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

The DC component• What happens when u = 0?

– cos(0) = 1, sin(0) = 0• So

– This is the average value (or “DC component”) of the function. For images, it is largely a function of lighting and camera gain.

2/4/18 22

F u = 0( ) = f x( ) cos2πux − isin2πux[ ]dx−∞

+∞

= f x( )−∞

+∞

∫ dx

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 23: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Inverse Fourier Transform

• What if I have F(u) for all u, and I want to recreate the original function g(x)?

• Well, sum it up for every u:

2/4/18 23€

f x( ) = F u( )−∞

+∞

∫ cos 2πux( ) + isin 2πux( )[ ]du

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 24: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Discrete Fourier Transform

2/4/18 24

• Problem: an image is not an analogue signal that we can integrate.

• Therefore for 0 £ x < N and 0 £ u <N/2:

And the discrete inverse transform is:

F u( ) = f x( ) cos 2πuxN

#

$ %

&

' ( − isin

2πuxN

#

$ %

&

' (

*

+ ,

-

. /

x=0

N −1

f x( ) =1N

F u( ) cos 2πuxN

#

$ %

&

' ( + isin

2πuxN

#

$ %

&

' (

)

* +

,

- .

x=0

N −1

CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 25: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Discrete vs. Continuous• Summation replaces integration

• Division by N (the number of discrete samples) makes the unit of repetition 1.

• For any signal (continuous or discrete)

– G(x) is called the spatial domain

– F(u) is called the frequency domain

2/4/18 25CSU CS 510, ©Ross Beveridge & Bruce Draper

Page 26: Introduction to Fourier Analysis –Part 1cs510/yr2018sp/more... · Introduction to Fourier Analysis –Part 1 CS 510 Lecture #6 January 29, 2018. Why? 2/4/18 Get used to changing

Spatial vs Frequency• Spatial domain representation size?

– Given N samples, it is size N

• Frequency domain representation size?– A total of N/2 frequencies– A complex number (2 values) per frequency

• The DFT is invertible, so the two representations are equivalent:– Exact same information and same size– The FFT is O(n log n)

2/4/18 26CSU CS 510, ©Ross Beveridge & Bruce Draper