discrete fourier transform - svcl · 2006-05-16 · the discrete-space fourier transform • as in...

38
Discrete Fourier Transform Nuno Vasconcelos UCSD

Upload: others

Post on 02-Aug-2020

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform

Nuno VasconcelosUCSD

Page 2: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Image formation• we have been studying the process of image formation• three questions

– what 3D point projects into pixel (x,y)?– what is the light incident on the pixel?– what is the pixel color?

• these determine the image value at the pixel

α1

α2

incident light

reflected light

image brightness2

Page 3: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Geometry• geometry answers the first question• pinhole camera:

– point (x,y,z) in 3D scene projected into image pixel of coordinates (x’, y’)

– according to the perspective projection equation:

⎟⎟⎟

⎜⎜⎜

⎛=⎟⎟

⎞⎜⎜⎝

zy

zx

fyx

''

3

Page 4: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Lambertian surfaces• we have a very simple equation

– when surface is Lambertian and source a PS @ infinity– “image power = source power x object albedo x

cos(light direction, surface normal)”

4

sPnPEPP ai

rr).()()( 00ρ

π=

θ

θ2

image brightness

Po

Pi

V

E θ

Lightdirection

nr

sr

Page 5: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Spectral albedos• with color, everything is replicated at each wavelength

• different objects have different spectral albedo, and that is why we perceive color

5

Page 6: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Images• the incident light is collected by an image sensor

– that transforms it into a 2D signal

θ

θ2

Po

Pi

V

E

6

Page 7: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

2D-DSP• in summary:

– image is a N x M array of pixels– each pixel contains three colors– overall, the image is a 2D discrete-space

signal– each entry is a 3D vector

– for simplicity, we consider only singlechannel images

– but everything extends to color in a straightforward manner

},...,0{},...,0{),,,(],[

2

121

MnNnbgrnnx

∈∈=

},...,0{},...,0{],,[

2

121

MnNnnnx

∈∈

7

Page 8: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Separable sequences• a trivial concept,

– but probably the only real novelty in 2D-DSP– very important in practice, because it reduces 2D problem to

collection on 1D problems

• Definition: a sequence is separable if and only if

where f[.] and g[.] are 1D functions

• note: there are many examples of separable sequences• but most sequences are not separable

][][],[ 2121 ngnfnnx ×=

8

Page 9: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Linear Shift Invariant (LSI) systems• straightforward extension of LTI systems

• Definition: a system T that maps x[n1,n2] into y[n1,n2] isLSI if and only if– it is linear

– it is shift invariant

{ }{ } { }

],[],[],[],[

],[],[

212211

212211

212211

nnbynnaynnxbTnnxaT

nnbxnnaxT

+=+==+

{ } ],[],[ 22112211 mnmnymnmnxT −−=−−

9

Page 10: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

2D convolution• the operation

is the 2D convolution of x and h– we will denote it by

• this is of great practical importance:– for an LSI system the response to any input can be obtained by

the convolution with this impulse response– the IR fully characterizes the system– it is all that I need to measure

],[],[],[ 221121211 2

knknhkkxnnyk k

−−= ∑ ∑∞

−∞=

−∞=

],[],[],[ 212121 nnhnnxnny ∗=

10

Page 11: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Separable systems• Definition: a system is separable if and only if its

impulse response is a separable sequence

• in this case the convolution simplifies• step1) for every k1,

– f[k1,n2] is 1D convolution of x[k1,n2] and h2[n2]

– which means: “convolve the columns of x with h2to obtain columns of f”

][][],[ 221121 nhnhnnh ×=

][],[],[ 222121 nhnkxnkf ∗=

n1

n2

n1

n2

*h2

],[ 21 nnx ],[ 21 nnf

11

Page 12: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Separable systems• step2) for every n2,

– y[n1,n2] is 1D convolution of f[n1,n2] and h1[n1]

– which means: “convolve the rows of f with h1 to obtain rows of y”

][],[],[ 112121 nhnnfnny ∗=

n2

n1

n2

12

n1

*

h1],[ 21 nny],[ 21 nnf

Page 13: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

The Discrete-Space Fourier Transform• as in 1D, an important concept in linear system analysis

is that of the Fourier transform• the Discrete-Space Fourier Transform is the 2D

extension of the Discrete-Time Fourier Transform

• note that this is a continuous function of frequency– inconvenient to evaluate numerically in DSP hardware– we need a discrete version– this is the 2D Discrete Fourier Transform (2D-DFT)

2121221

2121

2211

2211

1 2

),()2(

1],[

],[),(

ωωωωπ

ωω

ωω

ωω

ddeeXnnx

eennxX

njnj

njnj

n n

∫∫

∑∑

=

= −−

13

Page 14: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

2D-DFT

14

• the 2D-DFT is obtained by sampling the DSFT at regular frequency intervals

• this turns out to make the 2D-DFT somewhat harder to work with than the DSFT– it is the same as in 1D– you might remember that the inverse transform of the product of

two DFTs is not the convolution of the associated signals– but, instead, the “circular convolution”– where does this come from?

• it is better understood by first considering the 2D Discrete Fourier Series (2D-DFS)

22

211

12,22121 ),(],[

kN

kN

XkkX πωπωωω

===

Page 15: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

2D-DFS• it is the natural representation for a periodic sequence• a sequence x[n1,n2] is periodic of period N1xN2 if

• note that

• makes no sense for a periodic signal– the sum will be infinite for any pair r1,r2

– neither the 2D DSFT or the Z-transform will work here

[ ] [ ][ ] 21221

21121

, ,, ,,

nnNnnxnNnxnnx

∀+=+=

∑ ∑∞

−∞=

−∞=

−−=1 2

21212121 ],[),(

n n

jnjn rrnnxrrX

15

Page 16: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

2D-DFS• the 2D-DFS solves this problem• it is based on the observation that

– any periodic sequence can be represented as a weighted sum of complex exponentials of the form

– this is a simple consequence of the fact that

– is an orthonormal basis of the space of periodic sequences

( )10 ,10 ,,

22

11

22

21

222

111

−≤≤−≤≤××

NkNkeekkX

nkN

jnkN

j ππ

10 ,10 , 2211

2222

211

1 −≤≤−≤≤× NkNkeenk

Njnk

Nj ππ

16

Page 17: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

2D-DFS• the 2D-DFS relates x[n1,n2] and X[k1,k2]

• note that X[k1,k2] is also periodic outside

• like the DSFT, – properties of the 2D-DFS are identical to those of the 1D-DFS– with the straightforward extension of separability

( ) [ ]

[ ] [ ] 222

111

1

1

2

2

222

111

1

1

2

2

221

0

1

021

2121

221

0

1

02121

,1,

,,

nkN

jnkN

jN

k

N

k

nkN

jnkN

jN

n

N

n

eekkXNN

nnx

eennxkkX

ππ

ππ

∑∑

∑∑−

=

=

−−−

=

=

=

=

10 ,10 2211 −≤≤−≤≤ NkNk

17

Page 18: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• like the Fourier transform,

– the inverse transform of multiplication is convolution

– however, we have to be careful about how we define convolution– since the sequences have no end, the standard definition

makes no sense– e.g. if x and h are both positive sequences, this will allways be

infinite

[ ] [ ] ( ) ( )2121

2121 ,,,, kkYkkXnnxnnxDFS

×↔∗

],[],[],[ 221121211 2

knknhkkxnnyk k

−−= ∑ ∑∞

−∞=

−∞=

18

Page 19: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• to deal with this, we introduce the idea of periodic

convolution• instead of the regular definition

• which, from now on, we refer to as linear convolution• periodic convolution only considers one period of our

sequences

• the only difference is in the summation limits

],[ ],[* 2211211 2

knknhkkxyxk k

−−= ∑ ∑∞

−∞=

−∞=

],[ ],[ 2211

1

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k−−= ∑ ∑

=

=

o

19

Page 20: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• this is simple, but produces a convolution which is

substantially different• let’s go back to our example, now assuming that the

sequences have period (N1=3,N2=2)

• as before, we need four steps

n1

n2

n1

n2

(1) (2)

20

*(3) (4)

(1) (2)

(3) (4)

(1) (2)

(3) (4)

(1) (2)

(3) (4)

],[ 21 nnx ],[ 21 nnh

Page 21: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• step 1): express sequences in terms of (k1, k2), and

consider one period only

we next proceed exactly as before

k1

k2

k1

k2

(1) (2)

(3) (4)

],[ ],[ 2211

1

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k

−−= ∑ ∑−

=

=

o

],[ 21 kkx ],[ 21 kkh

21

Page 22: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• step 2): invert h(k1, k2)

k1

k2

(1)(2)

(3)(4)

],[],[ 2121 kkhkkg −−=

k1

k2

(1) (2)

(3) (4)

],[ 21 kkh

k1

k2

(1) (2)

(3) (4)

],[ 21 kkh −

1

2

],[ ],[ 2211

1

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k

−−= ∑ ∑−

=

=

o

22

Page 23: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• step 3): shift g(k1, k2) by (n1, n2)

],[ ],[ 2211

1

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k

−−= ∑ ∑−

=

=

o

k1

k2

(1)(2)

(3)(4)

k2

(1)(2)

(3)(4)

n

n2

this sendswhatever is at (0,0) to (n1,n2)

k11

],[],[

2211

2211

knknhnknkg−−

=−−

],[],[ 2121 kkhkkg −−=

23

Page 24: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• e.g. for (n1,n2) = (1,0)

the next step would be to point-wise multiply the two signals and sum

k1

k2

(1)(2)

(3)(4)

n1

n2

k1

k2

],[ 21 kkx],[

],[

2211

2211

knknhnknkg−−

=−−

],[ ],[ 2211

1

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k

−−= ∑ ∑−

=

=

o

24

Page 25: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• this is where we depart from linear convolution• remember that the sequences are periodic, and we really

only care about what happens in the fundamental period• we use the periodicity to fill the values missing in the

flipped sequence

k1

k2

(1)(2)

(3)(4)

n1

n2

],[ 2211 knknh −−

k1

k2

(1) (2)

(4)(3)

=

],[ 2211 knknh −−

25

Page 26: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution• step 4): we can finally point-wise multiply the two signals

and sum

– e.g. for (n1,n2) = (1,0)

k1

k2

],[ 21 kkx

x =k1

k2

],[ 21 nny

],[ ],[ 2211

1

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k

−−= ∑ ∑−

=

=

o

k1

k2

(1) (2)

(4)

],[ 2211 knknh −−

(3)3x1+1x1=4

26

Page 27: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Periodic convolution

27

• note: the sequence that results from the convolution is also periodic

• it is important to keep in mind what we have done– we work with a single period (the

fundamental period) to make things manageable– but remember that we have periodic sequences– it is like if we were peeking through a window– if we shift, or flip the sequence we need to remember that – the sequence does not simply move out of the window, but the

next period walks in!!!– note, that this

can make thefundamentalperiod changeconsiderably

k1

k2

k1

k2

shiftby

(1,1)

Page 28: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform• all of this is interesting,

– but why do I care about periodic sequences?– all images are finite, I could never have such a sequence

• while this is true– the DFS is the easiest route to learn about the discrete Fourier

transform (DFT)

• recall that the DFT is obtained by sampling the DSFT

– we know that when we sample in space we have aliasing in frequency

– well, the same happens when we sample in frequency: we get aliasing in time

22

211

12,22121 ),(],[

kN

kN

XkkX πωπωωω

===

28

Page 29: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform

29

• this means that– even if we have a finite sequence– when we compute the DFT we are effectively working with a

periodic sequence

• you may recall from 1D signal processing that– when you multiply two DFTs, you do not get convolution in time– but instead something called circular convolution– this is strange: when I flip a signal (e.g. convolution) it wraps

around the sequence borders– well, in 2D it gets much stranger

• the only way I know how to understand this is to– think about the underlying periodic sequence– establish a connection between the DFT and the DFS of that

sequence– use what we have seen for the DFS to help me out with the DFT

Page 30: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform• let’s start by the relation between DFT and DFS• the DFT is defined as

(here X(ω1,ω2) is the DSFT) which can be written as

22

211

12,22121 ),(],[

kN

kN

XkkX πωπωωω

===

[ ] [ ]

[ ] [ ]⎪⎩

⎪⎨

<≤<≤

=

⎪⎩

⎪⎨

<≤<≤

=

∑∑

∑∑

=

=

−−−

=

=

otherwiseNnNn

eekkXNNnnx

otherwiseNkNk

eennxkkX

nkN

jnkN

jN

k

N

k

nkN

jnkN

jN

n

N

n

000

,1,

000

,,,

22

11221

0

1

021

2121

22

11221

0

1

021

21

222

111

1

1

2

2

222

111

1

1

2

2

ππ

ππ

30

Page 31: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform• comparing this

with the DFS

[ ] [ ]

[ ] [ ]⎪⎩

⎪⎨

<≤<≤

=

⎪⎩

⎪⎨

<≤<≤

=

∑∑

∑∑

=

=

−−−

=

=

otherwiseNnNn

eekkXNNnnx

otherwiseNkNk

eennxkkX

nkN

jnkN

jN

k

N

k

nkN

jnkN

jN

n

N

n

000

,1,

000

,,,

22

11221

0

1

021

2121

22

11221

0

1

021

21

222

111

1

1

2

2

222

111

1

1

2

2

ππ

ππ

[ ] [ ]

[ ] [ ] 222

111

1

1

2

2

222

111

1

1

2

2

221

0

1

021

2121

221

0

1

02121

,1,

,,

nkN

jnkN

jN

k

N

k

nkN

jnkN

jN

n

N

n

eekkXNN

nnx

eennxkkX

ππ

ππ

∑∑

∑∑−

=

=

−−−

=

=

=

=

31

Page 32: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform• we see that inside the boxes

the two transforms are exactly the same• if we define the indicator function of the box

• we can write

22

11

00

NkNk

<≤<≤

22

11

00

NnNn

<≤<≤

[ ]⎪⎩

⎪⎨⎧

<≤<≤

otherwiseNnNn

nnR NN

000

,1,22

11

2121

[ ] [ ] [ ]212121 ,,,21

nnRnnxnnx NN ×= [ ] [ ] [ ]212121 ,,,21

kkRkkXkkX NN ×=

32

Page 33: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform• note from

that working in the DFT domain is equivalent to– working in the DFS domain– extracting the fundamental period at the end

• we can summarize this as

• in this way, I can work with the DFT without having to worry about aliasing

[ ] [ ] [ ]212121 ,,,21

nnRnnxnnx NN ×= [ ] [ ] [ ]212121 ,,,21

kkRkkXkkX NN ×=

[ ] [ ] [ ] [ ]2121

2121 ,

,,

, kkXkkXnnxnnx

truncate

eperiodiciz

DFS

eperiodiciz

truncate←→

↔←→

33

Page 34: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform

• this trick can be used to derive all the DFT properties• e.g. what is the inverse transform of a phase shift?

– let’s follow the steps

– 1) periodicize: this causes the same phase shift in the DFS

[ ] [ ] [ ] [ ]2121

2121 ,

,,

, kkXkkXnnxnnx

truncate

eperiodiciz

DFS

eperiodiciz

truncate←→

↔←→

[ ] [ ] 222

111

22

2121 ,,mk

Njmk

Nj

eekkXkkYππ

−−

=

[ ] [ ] 222

111

22

2121 ,,mk

Njmk

Nj

eekkXkkYππ

−−

=

34

Page 35: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Discrete Fourier Transform

[ ] [ ] [ ] [ ]2121

2121 ,

,,

, kkXkkXnnxnnx

truncate

eperiodiciz

DFS

eperiodiciz

truncate←→

↔←→

– 2) compute the inverse DFS: it follows from the properties of the DFS (page 142 on Lim) that we get a shift in space

– 3) truncate: the inverse DFT is equal to one period of the shifted periodic extension of the sequence

– in summary, the new sequence is obtained by making the original periodic, shifting, and taking the fundamental period

[ ] [ ]221121 ,, mnmnxnny −−=

[ ] [ ] [ ]21221121 ,,,21

nnRmnmnxnny NN ×−−=

35

Page 36: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Example

• note that what leaves on one end, enters on the other

k1

k2

shift by (1,1)

k1

k2

periodicize

k1

k2

k1

k2

truncate

36

Page 37: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

Example• for this reason it is called a circular shift

• note that this is way more complicated than in 1D• to get it right we really have to think in terms of the

periodic extension of the sequence• we will see that this shows up in the properties of the

DFT, • namely that convolution becomes circular convolution

k1

k2

k1

k2

circular shift by (1,1)

37

Page 38: Discrete Fourier Transform - SVCL · 2006-05-16 · The Discrete-Space Fourier Transform • as in 1D, an important concept in linear system analysis is that of the Fourier transform

38