of 35/35
Discrete Fourier Transform Discrete Fourier Transform Nuno Vasconcelos UCSD
• date post

02-Aug-2020
• Category

Documents

• view

7

0

Embed Size (px)

Transcript of Discrete Fourier TransformDiscrete Fourier Transform · – inconvenient to evaluate numerically in...

• Discrete Fourier TransformDiscrete Fourier Transform

Nuno VasconcelosUCSD

• 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 Transform2211][)( ωω ωω eennxX njnj∑∑ −−2121

2211

2211

1 2

)(1][

],[),(

ωωωω

ωω

ωω ddeeXnnx

eennxX

njnj

jj

n n

∫∫

∑∑

=

=

• note that this is a continuous function of frequency

2121221 ),()2(],[ ωωωω

πddeeXnnx ∫∫=

q y– inconvenient to evaluate numerically in DSP hardware– we need a discrete version

this is the 2D Discrete Fourier Transform (2D DFT)

2

– this is the 2D Discrete Fourier Transform (2D-DFT)

• before that we consider the sampling problem

• Sampling in 2D

• consider an analog signal xc(t1,t2) and let its analog Fourier transform be X (Ω1 Ω2)Fourier transform be Xc(Ω1,Ω2)– we use capital Ω to emphasize that this is analog frequency

• sample with period (T1,T2) to obtain a discrete-space signal

222111 ;2121),(],[

TntTntcttxnnx

===

3

• Sampling in 2D

• relationship between the Discrete-Space FT of x[n1,n2]and the FT of x (t1 t2) is simple extension of 1D resultand the FT of xc(t1,t2) is simple extension of 1D result

∑ ∑∞ ∞

⎟⎠

⎞⎜⎜⎝

⎛ −−= 221121

2,21),( c Tr

TrX

TTX πωπωωω

DSFT of x[n1,n2] FT of xc(ω1,ω2)

−∞= −∞= ⎠⎝1 2 2121 r r TTTT

“discrete spectrum” “analog spectrum”

• Discrete Space spectrum is sum of replicas of analog• Discrete Space spectrum is sum of replicas of analog spectrum– in the “base replica” the analog frequency Ω1 (Ω2) is mapped

i t th di it l f T ( T )4

into the digital frequency Ω1T1 (Ω2T2)– discrete spectrum has periodicity (2π,2π)

• For exampleΩ2

Ω’

Ω”ω2

Ω’

Ω1

Ω”T2

ω1

2π−Ω”T2

2

1

''''''

TT

Ω=→ΩΩ=→Ω

βα

ω1

Ω’T1

2π2π

• no aliasing if

2π−Ω’T1

⎧ Ω≤Ω '2' TT π

ω12π⇔

⎩⎨⎧

Ω−≤ΩΩ−≤Ω

22

11

'2''2

TTTT

ππ

⎨⎧ Ω≤

⇔'/1 πT

5⎩⎨ Ω≤

⇔''/2 πT

• Aliasing• the frequency (Ω’/π,Ω’’/π)

is the critical sampling frequency

• below it we havealiasing

ω2

aliasing

ω1

• this is just like the 1D case, but now there are morenow there are more possibilities for overlap

6

• Reconstruction• if there is no aliasing we can recover the signal in a way

similar to the 1D case

( ) ( )∑ ∑∞ ∞

−−=

2222

1111

2121

sinsin],[),(c

TntT

TntTnnxtty π

π

π

π

t i 2D th ibiliti th i 1D

( ) ( )∑ ∑−∞= −∞= −−1 2 222

2111

1

n n TntT

TntT

ππ

• note: in 2D there are many more possibilities than in 1D– e.g. the sampling grid does not have to be rectangular, e.g.

hexagonal sampling when T2 = T1/sqrt(3) and

⎩⎨⎧

= ==otherwise0

odd or even both21;2121

,),(],[ 222111

nnttxnnx TntTntc

7– in practice, however, one usually adopts the rectangular grid

• • a sequence of images obtained by down-sampling without any filteringg

• aliasing: the low-frequency parts are

li t d th h t th8

replicated throughout the low-res image

• The role of smoothing

none

some

l ta lot

9• too little leads to aliasing• too much leads to loss of information

• Aliasing in video• video frames are the result of temporal sampling

– fast moving objects are above the critical frequency– above a certain speed they are aliased and appear to move

backwards– this was common in old western movies and become known as

the “wagon wheel” effect– here is an example: super-resolution increases the frame rate

and eliminates aliasing

from “Space-TimeResolution in Video” by yE. Shechtman, Y. Caspi and M. Irani

(PAMI 2005).

10

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

frequency intervals

22

211

12,22121

),(],[k

Nk

NXkkX πωπωωω ===

• this turns out to make the 2D-DFT somewhat harder to work with than the DSFT

it i th i 1D– 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

11

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

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

[ ] [ ][ ]

21121 ,,nnNnnx

nNnxnnx∀+=

+=

• note that

[ ] 21221 , ,, nnNnnx ∀+=

∑ ∑∞

−∞=

−∞=

−−=1 2

21212121 ],[),(

n n

jnjn rrnnxrrX

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

ith th 2D DSFT th Z t f ill k h

12

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

• 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

222211 nkjnkj

ππ

( )10 ,10 ,,

22

1121

222

111

−≤≤−≤≤××

NkNkeekkX

nkN

jnkN

j

– this is a simple consequence of the fact that

10 22 ≤≤ Nk

22 kk ππ

is an orthonormal basis of the space of periodic sequences

10 ,10 , 221122

222

111 −≤≤−≤≤× NkNkee

nkN

jnkN

j ππ

13

– is an orthonormal basis of the space of periodic sequences

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

( ) [ ] 22111 2

221 1 nkjnkjN N ππ −−− −

( ) [ ] 2221111 2

221 1

0 02121 ,,

N N

Nj

Nj

n neennxkkX

ππ

∑∑= =

=

[ ] [ ] 2221111

1

2

2

221

0

1

021

2121 ,

1,nk

Njnk

NjN

k

N

keekkX

NNnnx

ππ

∑∑−

=

=

=

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

1010 ≤≤≤≤ NkNk• like the DSFT,

properties of the 2D DFS are identical to those of the 1D DFS

10 ,10 2211 −≤≤−≤≤ NkNk

14

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

• Periodic convolution• like the Fourier transform,

– the inverse transform of multiplication is convolution

[ ] [ ] ( ) ( )2121

2121 ,,,, kkYkkXnnxnnxDFS

×↔∗

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

],[],[],[ 221121211 2

knknhkkxnnyk k

−−= ∑ ∑∞

−∞=

−∞=

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

infinite

15

infinite

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

convolution• instead of the regular definition

],[],[* 221121 knknhkkxyx −−= ∑ ∑∞ ∞

• which, from now on, we refer to as linear convolution

],[],[ 2211211 2

yk k∑ ∑

−∞= −∞=

• periodic convolution only considers one period of our sequences

1 11 2N N− −

h l diff i i h i li i

],[ ],[ 22111

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k

−−= ∑ ∑= =

o

16

• the only difference is in the summation limits

• 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)n2 n2

(1) (2)*(3) (4)

(1) (2)

(3) (4)

n1 n1

(1) (2)*(1) (2)

(3) (4)

(1) (2)

(1) (2)

(3) (4)

• as before we need four steps],[ 21 nnx ],[ 21 nnh

17

• as before, we need four steps

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

consider one period only

],[ ],[ 22111

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k−−= ∑ ∑

=

=

o

k2 k2

(3) (4)

k1 k1(1) (2)

we next proceed exactly as before

],[ 21 kkx ],[ 21 kkh

18

we next proceed exactly as before

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

1 11 2N N− −

2

],[ ],[ 22110 0

21

1

1

2

2

knknhkkxhxk k

−−= ∑ ∑= =

o

k2

(1)(2)

k2

(3) (4)

k2

(1) (2)

k1

( )( )

(3)(4)

k1(1) (2) k1

(1) (2)

(3) (4)1

],[],[ 2121 kkhkkg −−=],[ 21 kkh ],[ 21 kkh −

19

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

1 11 2N N− −

],[ ],[ 22110 0

21

1

1

2

2

knknhkkxhxk k

−−= ∑ ∑= =

o

k2

(1)(2)

k2(1)(2)

(3)(4)

n2

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

k1

( )( )

(3)(4)

k1n1

],[],[ 2121 kkhkkg −−=][

],[ 2211knknh

nknkg =−−

20

],[ 2211 knknh −−

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

k2k2

k

(1)(2)n2

k k1(3)(4)

n1

k1

th t t ld b t i t i lti l th t

],[ 21 kkx],[

],[

2211

2211

knknhnknkg−−

=−−

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

][][1 11 2

kkhkkhN N

∑ ∑− −

21

],[],[ 22110 0

211 2

knknhkkxhxk k

−−= ∑ ∑= =

o

• 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 periodonly care about what happens in the fundamental period• we use the periodicity to fill the values missing in the

flipped sequencek2

(4)(3)

k2

n

k1(1) (2)

(4)( )

k1

(1)(2)

(3)(4)

n2

=

],[ 2211 knknh −−

n1

],[ 2211 knknh −−

22

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

and sum

],[ ],[ 22111

0

1

021

1

1

2

2

knknhkkxhxN

k

N

k−−= ∑ ∑

=

=

o

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

3x1+1x1=4

k1x =

k1k1(1) (2)

(4)(3)3x1+1x1=4

][ kkx ][ nny],[ 2211 knknh −−

23

],[ 21 kkx ],[ 21 nny],[ 2211

• Periodic convolution• note: the sequence that results from the convolution is

also periodic• it is important to keep in mind what we have done• it is important to keep in mind what we have done

– we work with a single period (the fundamental period) to make things manageableb t b th t h i di– 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

k2 k2,

can make thefundamentalperiod change k1 k1shift

24

considerably by(1,1)

• 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 Fourierthe DFS is the easiest route to learn about the discrete Fourier

transform (DFT)

• recall that the DFT is obtained by sampling the DSFT

22

211

12,22121

),(],[k

Nk

NXkkX πωπωωω ===

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

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

25

pp p q y galiasing in time

• Discrete Fourier Transform• 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 thaty y g p g– 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– this is strange: when I flip a signal (e.g. convolution) it wraps around the sequence borders

– well, in 2D it gets much stranger

th l I k h t d t d thi i t• 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

26

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

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

22

211

12,22121

),(],[k

Nk

NXkkX πωπωωω ===

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

[ ]⎪⎧

• Discrete Fourier Transform• comparing this

[ ]⎪⎧

• Discrete Fourier Transform• we see that inside the boxes

110 Nk

• Discrete Fourier Transform• note from

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

that working in the DFT domain is equivalent to– working in the DFS domain

[ ] [ ] [ ]212121 21 NN [ ] [ ] [ ]212121 21 NN

– extracting the fundamental period at the end

• we can summarize this as

[ ] [ ] [ ] [ ]2121

2121 ,

,,

, kkXkkXnnxnnx

truncate

eperiodiciz

DFS

eperiodiciz

t t←→

↔←→

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

eperiodiciztruncate

30

• Discrete Fourier Transform

[ ] [ ] [ ] [ ]2121

2121 ,

,,

, kkXkkXnnxnnx

truncate

DFS

eperiodiciz→

↔→

• this trick can be used to derive all the DFT properties

[ ] [ ] [ ] [ ]21212121 ,,,, kkXkkXnnxnnxeperiodiciztruncate

←↔←

• e.g. what is the inverse transform of a phase shift?– let’s follow the steps

22 kk ππ

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

[ ] [ ] 22211122

2121 ,,mk

Njmk

Nj

eekkXkkYππ

−−

=

[ ] [ ] 22211122

2121 ,,mk

Njmk

Nj

eekkXkkYππ

−−

=

31

• Discrete Fourier Transform

[ ] [ ] [ ] [ ]2121

2121 ,

,,

, kkXkkXnnxnnx

truncate

DFS

eperiodiciz

←→

↔←→

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

eperiodiciztruncate←←

DFS (page 142 on Lim) that we get a shift in space

[ ] [ ]221121 ,, mnmnxnny −−=

– 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

[ ] [ ] [ ]21221121 ,,, 21 nnRmnmnxnny NN ×−−=

32

y q y goriginal periodic, shifting, and taking the fundamental period

• Examplek2 k2

periodicize

k1 k1

shift by (1,1)

k2k2

2

k

truncate

k1k1

33

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

• Example• for this reason it is called a circular shift

k2

i l hift

k2

k1

circular shift by (1,1)

k1

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

i di t i f thperiodic extension of the sequence• we will see that this shows up in the properties of the

DFT,

34

,• namely that convolution becomes circular convolution

• 35