dream

46
DREAM PLAN IDEA IMPLEMENTATION 1

Upload: beata

Post on 11-Jan-2016

28 views

Category:

Documents


0 download

DESCRIPTION

DREAM. IDEA. PLAN. IMPLEMENTATION. Introduction to Image Processing. Present to: Amirkabir University of Technology (Tehran Polytechnic) & Semnan University. Dr. Kourosh Kiani Email: [email protected] Email: [email protected] Email : [email protected] - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: DREAM

1

DREAMDREAM

PLANPLANIDEAIDEA

IMPLEMENTATIONIMPLEMENTATION

Page 3: DREAM

3

Introduction to Image ProcessingIntroduction to Image Processing

Dr. Kourosh KianiEmail: [email protected]: [email protected]: [email protected]: www.kouroshkiani.com

Present to:Amirkabir University of Technology (Tehran

Polytechnic) & Semnan University

Page 4: DREAM

4

Lecture 09

Discrete Fourier Transform

(DFT )of 1D signal

Page 5: DREAM

Discrete Time Periodic Signals

A discrete time signal x[n] is periodic with period N if and only if

][][ Nnxnx for all n .

Definition:

N

][nx

n

Meaning: a periodic signal keeps repeating itself forever!

Page 6: DREAM

Example: a Sinusoid

[ ] 2cos 0.2 0.9x n n

Consider the Sinusoid:

It is periodic with period since 10N

][29.02.0cos2

9.0)10(2.0cos2]10[

nxn

nnx

for all n.

Page 7: DREAM

General Periodic Sinusoid

n

N

kAnx 2cos][

Consider a Sinusoid of the form:

It is periodic with period N since

][22cos

)(2cos][

nxknN

kA

NnN

kANnx

for all n.

with k, N integers.

Page 8: DREAM

1.03.0cos5][ nnxConsider the sinusoid:

It is periodic with period since 20N

][231.03.0cos5

1.0)20(3.0cos5]20[

nxn

nnx

for all n.

We can write it as:

1.0

20

32cos5][ nnx

Example of Periodic Sinusoid

Page 9: DREAM

nN

kj

Aenx

2

][

Consider a Complex Exponential of the form:

for all n.

It is periodic with period N since

Periodic Complex Exponentials

][

][

22

)(2

nxeAe

AeNnx

jkn

Nkj

NnN

kj

1

Page 10: DREAM

njejnx 1.0)21(][

Consider the Complex Exponential:

We can write it as

Example of a Periodic Complex Exponential

nj

ejnx

20

12

)21(][

and it is periodic with period N = 20.

Page 11: DREAM

Goal:

We want to write all discrete time periodic signals in terms of a common set of “reference signals”.

Reference Frames

It is like the problem of representing a vector in a reference frame defined by

• an origin “0”

• reference vectors

x

,..., 21 ee

x

01e

2e

Reference Frame

Page 12: DREAM

Reference Frames in the Plane and in Space

For example in the plane we need two reference vectors

x

01e

2e21,ee

Reference Frame

… while in space we need three reference vectors 321 ,, eee

0

1e

2e

Reference Frame

x

3e

Page 13: DREAM

A Reference Frame in the Plane

If the reference vectors have unit length and they are perpendicular (orthogonal) to each other, then it is very simple:

2211 eaeax

0

11ea

22ea

Where projection of along

projection of along1a

2a 2e1e

x

x

The plane is a 2 dimensional space.

Page 14: DREAM

A Reference Frame in the Space

If the reference vectors have unit length and they are perpendicular (orthogonal) to each other, then it is very simple:

332211 eaeaeax

0

11ea

22ea

Where projection of along

projection of along

projection of along

1a

2a 2e1e

x

x

The “space” is a 3 dimensional space.

3a x

3e

33ea

Page 15: DREAM

Example: where am I ?

N

E0

1e

2e

x

m300

m200

Point “x” is 300m East and 200m North of point “0”.

Page 16: DREAM

Reference Frames for Signals

We want to expand a generic signal into the sum of reference signals.

The reference signals can be, for example, sinusoids or complex exponentials

n

][nx

reference signals

Page 17: DREAM

Back to Periodic Signals

A periodic signal x[n] with period N can be expanded in terms of N complex exponentials

1,...,0 ,][2

Nkenen

N

kj

k

as

1

0

][][N

kkk neanx

Page 18: DREAM

A Simple Example

Take the periodic signal x[n] shown below:

n0

1

2

Notice that it is periodic with period N=2.

Then the reference signals are

nnj

nnj

ene

ene

)1(][

11][

2

12

1

2

02

0

We can easily verify that (try to believe!):

nn

nenenx

)1(5.015.1

][5.0][5.1][ 10

for all n.

Page 19: DREAM

Another Simple Example

Take another periodic signal x[n] with the same period (N=2):

n0

3.0

3.1

Then the reference signals are the same0

22

0

12

21

[ ] 1 1

[ ] ( 1)

j n n

j n n

e n e

e n e

We can easily verify that (again try to believe!):

nn

nenenx

)1(8.015.0

][8.0][5.0][ 10

for all n.

Same reference signals, just different coefficients

Page 20: DREAM

Orthogonal Reference Signals

Notice that, given any N, the reference signals are all orthogonal to each other, in the sense

kmN

kmnene

N

nmk if

if 0][][

1

0

*

1

0 2

)(221

0

21

0

*

1

1][][

N

n N

kmj

kmjn

N

kmjN

n

nN

kmjN

nmk

e

eeenene

Since

by the geometric sum

Page 21: DREAM

… apply it to the signal representation …

k

N

m

N

nmkm

N

nk

nx

N

mmm

N

nk

Nanenea

neneanenx

1

0

1

0

*

1

0

*

][

1

0

1

0

*

][][

][][][][

and we can compute the coefficients. Call then kNakX ][

1,...,0 ,][][1

0

2

NkenxNakX

N

n

knNj

k

Page 22: DREAM

Discrete Fourier Series

1,...,0 ,][][1

0

2

NkenxkX

N

n

knNj

Given a periodic signal x[n] with period N we define the

Discrete Fourier Series (DFS) as

Since x[n] is periodic, we can sum over any period. The general definition of Discrete Fourier Series (DFS) is

1,...,0 ,][][][1 20

0

NkenxnxDFSkX

Nn

nn

knNj

for any0n

Page 23: DREAM

Inverse Discrete Fourier Series

1

0

2

][1

][][N

k

knNjekX

NkXIDFSnx

The inverse operation is called Inverse Discrete Fourier Series (IDFS), defined as

Page 24: DREAM

Revisit the Simple Example

Recall the periodic signal x[n] shown below, with period N=2:

n0

1

2

1,0,)1(21)1](1[]0[][][1

0

2

2

kxxenxkX kk

n

nkj

Then 1]1[,3]0[ XX

Therefore we can write the sequence as

n

k

knjekXkXIDFSnx

)1(5.05.1

][2

1][][

1

0

2

2

Page 25: DREAM

Example of Discrete Fourier Series

Consider this periodic signal

The period is N=10. We compute the Discrete Fourier Series

25

102 29 4

210 10

100 0

1 if 1, 2,...,9

[ ] [ ]15 if 0

j k

j kn j kn

j k

n n

ek

X k x n e ee

k

][nx

n010

1

Page 26: DREAM

… now plot the values …

0 2 4 6 8 100

5magnitude

0 2 4 6 8 10-2

0

2phase (rad)

k

k

|][| kX

][kX

Page 27: DREAM

Example of DFS

Compute the DFS of the periodic signal

)5.0cos(2][ nnx

Compute a few values of the sequence

,...0]3[,2]2[,0]1[,2]0[ xxxx

and we see the period is N=2. Then

k

n

knjxxenxkX )1(]1[]0[][][

1

0

2

2

which yields

2]1[]0[ XX

Page 28: DREAM

Signals of Finite Length

All signals we collect in experiments have finite length

)(tx )(][ snTxnx

ss TF

1

MAXTMAX SN T F

Example: we have 30ms of data sampled at 20kHz (ie 20,000 samples/sec). Then we have

points data 60010201030 33 N

Page 29: DREAM

Series Expansion of Finite Data

We want to determine a series expansion of a data set of length N.

Very easy: just look at the data as one period of a periodic sequence with period N and use the DFS:

n

1N0

Page 30: DREAM

Discrete Fourier Transform (DFT)

Given a finite interval of a data set of length N, we define the Discrete Fourier Transform (DFT) with the same expression as the Discrete Fourier Series (DFS):

21

0

[ ] [ ] [ ] , 0,..., 1N j kn

N

n

X k DFT x n x n e k N

And its inverse

21

0

1[ ] [ ] [ ] , 0,..., 1

N j knN

n

x n IDFT X k X k e n NN

Page 31: DREAM

Signals of Finite Length

All signals we collect in experiments have finite length in time

)(tx )(][ snTxnx

ss TF

1

MAXTMAX SN T F

Example: we have 30ms of data sampled at 20kHz (ie 20,000 samples/sec). Then we have

points data 60010201030 33 N

Page 32: DREAM

Series Expansion of Finite Data

We want to determine a series expansion of a data set of length N.

Very easy: just look at the data as one period of a periodic sequence with period N and use the DFS:

n

1N0

Page 33: DREAM

Discrete Fourier Transform (DFT)

Given a finite of a data set of length N we define the Discrete Fourier Transform (DFT) with the same expression as the Discrete Fourier Series (DFS):

21

0

[ ] [ ] [ ] , 0,..., 1N j kn

N

n

X k DFT x n x n e k N

and its inverse

21

0

1[ ] [ ] [ ] , 0,..., 1

N j knN

n

x n IDFT X k X k e n NN

Page 34: DREAM

Example of Discrete Fourier Transform

Consider this signal

The length is N=10. We compute the Discrete Fourier Transform

25

102 29 4

210 10

100 0

1 if 1, 2,...,9

[ ] [ ]15 if 0

j k

j kn j kn

j k

n n

ek

X k x n e ee

k

][nx

n0

9

1

Page 35: DREAM

…now plot the values…

0 2 4 6 8 100

5magnitude

0 2 4 6 8 10-2

0

2phase (rad)

k

k

|][| kX

][kX

Page 36: DREAM

Fs = 1000; % Sampling frequencyT = 1/Fs; % Sample timeL = 1000; % Length of signalt = (0:L-1)*T; % Time vector% Sum of a 50 Hz sinusoid and a 120 Hz sinusoidx = 0.7*sin(2*pi*50*t) + sin(2*pi*120*t); y = x + 2*randn(size(t)); % Sinusoids plus noisefigure (1);plot(Fs*t(1:50),y(1:50))title('Signal Corrupted with Zero-Mean Random Noise')xlabel('time (milliseconds)')

0 5 10 15 20 25 30 35 40 45 50-6

-4

-2

0

2

4

6Signal Corrupted with Zero-Mean Random Noise

time (milliseconds)

Page 37: DREAM

NFFT = 2^nextpow2(L); % Next power of 2 from length of yY = fft(y,NFFT)/L;f = Fs/2*linspace(0,1,NFFT/2+1);figure (2);% Plot single-sided amplitude spectrum.plot(f,2*abs(Y(1:NFFT/2+1))) title('Single-Sided Amplitude Spectrum of y(t)')xlabel('Frequency (Hz)')ylabel('|Y(f)|')

0 50 100 150 200 250 300 350 400 450 5000

0.1

0.2

0.3

0.4

0.5

0.6

0.7

0.8

0.9

1Single-Sided Amplitude Spectrum of y(t)

Frequency (Hz)

|Y(f

)|

Page 38: DREAM

Relation Between Dx and Du

For a signal f(x) with M points, let spatial resolution Dx be space between samples in f(x) and let frequency resolution Du be space between frequencies components in F(u), we have

xMu

DD

1

Example: for a signal f(x) with sampling period 0.5 sec, 100 point, we will get frequency resolution equal to

Hz02.05.0100

1

Du

This means that in F(u) we can distinguish 2 frequencies that are apart by 0.02 Hertz or more.

Page 39: DREAM

m = 4;n = 2^m-1;x = gf(randi([0 2^m-1],n,1),m); % Random vectory = fft(x); % Transform of xz = ifft(y); % Inverse transform of yck = isequal(z,x) % Check that ifft(fft(x)) recovers x.

[x z]= 5 5 2 2 3 3 0 014 1412 12 5 513 1312 12 9 9 6 6 5 5 1 1 5 5 8 8

Page 40: DREAM

>> a=[1 2 3 4 5 6]a = 1 2 3 4 5 6

>> b=fft(a')b= 21.0000 -3.0000 + 5.1962i -3.0000 + 1.7321i -3.0000 -3.0000 - 1.7321i -3.0000 - 5.1962i

Example in Matlab

>> c=ifft(b);>> a=c'

a =

1.0000 2.0000 3.0000 4.0000 5.0000 6.0000

Page 41: DREAM

Periodicity of 1-D DFT

0 N 2N-N

DFT repeats itself every N points (Period = N) but we usually display it for n = 0 ,…, N-1

We display only in this range

1

0

/2)(1

)(M

x

MuxjexfM

uF From DFT:

Page 42: DREAM

Conventional Display for 1-D DFT

0 N-1

Time Domain Signal

DFT

f(x))(uF

0 N-1

Low frequencyarea

High frequencyarea

The graph F(u) is not easy to understand !

Page 43: DREAM

)(uF

0-N/2 N/2-1

)(uF

0 N-1

Conventional Display for DFT : FFT Shift

FFT Shift: Shift center of thegraph F(u) to 0 to get betterDisplay which is easier to understand.

High frequency area

Low frequency area

Page 44: DREAM

0 200 400 600 800 1000 12000

200

400

600FFT

0 200 400 600 800 1000 12000

200

400

600FFTHIFT

y=rand(1024,1);z=fft(y)subplot(2,1,1)plot(abs(z))title('FFT')w=fftshift(z)subplot(2,1,2)plot(abs(w))title('FFTHIFT')

Page 45: DREAM

Questions? Discussion? Suggestions?

Page 46: DREAM

46