the discrete fourier transform. the fourier transform “the fourier transform is a mathematical...

36
The Discrete Fourier Transform

Upload: roderick-griffith

Post on 28-Dec-2015

245 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

The Discrete Fourier Transform

Page 2: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

The Fourier Transform

• “The Fourier transform is a mathematical operation with many applications in physics and engineering that expresses a mathematical function of time as a function of frequency, known as its frequency spectrum.”

– from http://en.wikipedia.org/wiki/Fourier_transform

Page 3: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

The Fourier Transform

• “For instance, the transform of a musical chord made up of pure notes (without overtones) expressed as amplitude as a function of time, is a mathematical representation of the amplitudes and phases of the individual notes that make it up.”

– from http://en.wikipedia.org/wiki/Fourier_transform

Page 4: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Amplitude & phase

• f(x) = sin( x + ) +

– is the amplitude– is the frequency– is the phase– is the DC offset

Page 5: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

More generally

• f(x) = 1 sin( 1 x + 1 ) + 2 sin( 2 x + 2 ) +

Page 6: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

The Fourier Transform

• “The function of time is often called the time domain representation, and the frequency spectrum the frequency domain representation.”

– from http://en.wikipedia.org/wiki/Fourier_transform

Page 7: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Applications

• differential equations• geology• image and signal processing• optics• quantum mechanics• spectroscopy

Page 8: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

REVIEW OF COMPLEX NUMBERS

Page 9: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex numbers

Complex numbers . . .

•extend the 1D number line to the 2D plane

•are numbers that can be put into the rectangular form, a+bi where i2 = -1, and a and b are real numbers.

Page 10: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex numbers(rectangular form)

yixz

Page 11: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex numbers

Complex numbers . . .•a is the real part; b is the imaginary part

•If a is 0, then a+bi is purely imaginary; if b is 0, then a+bi is a real number.

•originally called “fictitious” by Girolamo Cardano in the 16th century

Page 12: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex arithmetic

• add/subtract

– add/subtract the real and imaginary parts separately

Page 13: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex arithmetic

• complex conjugate

– often denoted as

– negate only the imaginary part

zor *z

Page 14: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex arithmetic

• inverse

wherez is a complex numberz bar is the length or magnitude of za is the real partb is the imaginary part

22

1

ba

z

zz

z

z

Page 15: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex arithmetic

• multiplication (FOIL)

iadbcbdacdicbia

Page 16: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex arithmetic

• division

dic

dic

dic

bia

idc

adbc

dc

bdac

dic

bia

2222

complex conjugate of denominator

Page 17: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Complex numbers(polar form)

sin

cos

andinteger an is

tanarg

where

sin cos

1

22

)2(

ry

rx

n

x

yz

yxzr

er

rir

er

iyxz

ni

i

Page 18: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

exponential vs. trigonometric

2cos

2sin

sincos

ixix

ixix

ix

eex

i

eex

xixe

Leonhard Euler 1707-1783

(phasor form)

Page 19: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

DFT(DISCRETE FOURIER TRANSFORM)

Page 20: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

DFT

• Say we have a sequence of N (possibly complex) numbers, x0 … xN-1.

• The DFT produces a sequence of N (typically complex) numbers, X0 … XN-1, via the following:

1

0

2N

n

nink

Nk

exX

Page 21: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

DFT & IDFT

• The DFT (Discrete Fourier Transform) produces a sequence of N (typically complex) numbers, X0 … XN-1, via the following:

• The IDFT (Inverse DFT) is defined as follows:

1

0

2N

n

nink

Nk

exX

1

0

21 N

k

nikk

Nk

eXN

x

Page 22: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Calculating the DFT

So how can we actually calculate ?

1

0

2N

n

nink

Nk

exX

Page 23: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Calculating the DFT

• So how can we calculate ?

• Let’s use this relationship:

• Then

• So what does this mean?

1

0

2N

n

nink

Nk

exX

1

0

2sin2cosN

nNk

Nk

nk ninxX

xixeix sincos

Page 24: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Interpretation of DFT

Back to the polar form:

– r/N is the amplitude and is the phase of a sinusoid with frequency k/N into which xn is decomposed

1

0

2sin2cosN

nNk

nNk

nk nixnxX

Page 25: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

CALCULATING THE DFT USING EXCEL

Page 26: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

x_n X_ 1 X_ 2N x b sin(b x) b2 sin(b2 x) 0.5*sin(b x) + 0.5*sin(b2 x) real imag real imag real imag

500 0 0.05 0.00 0.1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.001 0.05 0.10 0.07 0.07 0.00 0.07 0.00 0.07 0.002 0.10 0.20 0.15 0.15 0.00 0.15 0.00 0.15 -0.013 0.15 0.30 0.22 0.22 0.00 0.22 -0.01 0.22 -0.024 0.20 0.39 0.29 0.29 0.00 0.29 -0.01 0.29 -0.035 0.25 0.48 0.36 0.36 0.00 0.36 -0.02 0.36 -0.056 0.30 0.56 0.43 0.43 0.00 0.43 -0.03 0.43 -0.067 0.34 0.64 0.49 0.49 0.00 0.49 -0.04 0.49 -0.098 0.39 0.72 0.55 0.55 0.00 0.55 -0.06 0.54 -0.119 0.43 0.78 0.61 0.61 0.00 0.61 -0.07 0.59 -0.14

10 0.48 0.84 0.66 0.66 0.00 0.66 -0.08 0.64 -0.1611 0.52 0.89 0.71 0.71 0.00 0.70 -0.10 0.68 -0.1912 0.56 0.93 0.75 0.75 0.00 0.74 -0.11 0.71 -0.2213 0.61 0.96 0.78 0.78 0.00 0.77 -0.13 0.74 -0.2514 0.64 0.99 0.81 0.81 0.00 0.80 -0.14 0.76 -0.2815 0.68 1.00 0.84 0.84 0.00 0.82 -0.16 0.78 -0.3116 0.72 1.00 0.86 0.86 0.00 0.84 -0.17 0.79 -0.3417 0.75 0.99 0.87 0.87 0.00 0.85 -0.18 0.79 -0.3618 0.78 0.97 0.88 0.88 0.00 0.86 -0.20 0.79 -0.3819 0.81 0.95 0.88 0.88 0.00 0.85 -0.21 0.78 -0.4020 0.84 0.91 0.88 0.88 0.00 0.85 -0.22 0.77 -0.4221 0.87 0.86 0.87 0.87 0.00 0.84 -0.23 0.75 -0.4422 0.89 0.81 0.85 0.85 0.00 0.82 -0.23 0.72 -0.4523 0.91 0.75 0.83 0.83 0.00 0.79 -0.24 0.69 -0.4524 0.93 0.68 0.80 0.80 0.00 0.77 -0.24 0.66 -0.4625 0.95 0.60 0.77 0.77 0.00 0.74 -0.24 0.63 -0.4526 0.96 0.52 0.74 0.74 0.00 0.70 -0.24 0.59 -0.4527 0.98 0.43 0.70 0.70 0.00 0.66 -0.23 0.55 -0.4428 0.99 0.33 0.66 0.66 0.00 0.62 -0.23 0.50 -0.4329 0.99 0.24 0.62 0.62 0.00 0.58 -0.22 0.46 -0.4130 1.00 0.14 0.57 0.57 0.00 0.53 -0.21 0.42 -0.3931 1.00 0.04 0.52 0.52 0.00 0.48 -0.20 0.37 -0.37

X_0

Page 27: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Check w/ matlab/octave% see http://www.mathworks.com/help/matlab/ref/fft.html

N = 256; % # of samplesn = (0:N-1); % subscriptsb1 = 0.5; % freq 1b2 = 2.5; % freq 2

xn = 0.5 * sin( b1*n ) + 0.2 * sin( b2*n );

plot( xn );Xn = fft( xn );plot( abs(Xn(1:N/2)) );

X0real = xn .* cos( -2*pi*n*0/N );X0imag = xn .* sin ( -2*pi*n*0/N );

X1real = xn .* cos( -2*pi*n*1/N );X1imag = xn .* sin ( -2*pi*n*1/N );

X2real = xn .* cos( -2*pi*n*2/N );X2imag = xn .* sin ( -2*pi*n*2/N );

X3real = xn .* cos( -2*pi*n*3/N );X3imag = xn .* sin ( -2*pi*n*3/N );... Note: .* is element-wise (rather

than matrix) multiplication in matlab.

Page 28: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering
Page 29: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Add random noise.% see http://www.mathworks.com/help/matlab/ref/fft.html

N = 256; % # of samplesn = (0:N-1); % subscriptsb1 = 0.5; % freq 1b2 = 2.5; % freq 2r = randn( 1, N ); % noisexn = 0.5 * sin( b1*n ) + 0.2 * sin( b2*n ) + 0.5 * r;plot( xn );Xn = fft( xn );plot( abs(Xn(1:N/2)) );

X0real = xn .* cos( -2*pi*n*0/N );X0imag = xn .* sin ( -2*pi*n*0/N );

X1real = xn .* cos( -2*pi*n*1/N );X1imag = xn .* sin ( -2*pi*n*1/N );

X2real = xn .* cos( -2*pi*n*2/N );X2imag = xn .* sin ( -2*pi*n*2/N );

X3real = xn .* cos( -2*pi*n*3/N );X3imag = xn .* sin ( -2*pi*n*3/N );...

Page 30: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Signal without and with noise.

Page 31: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Signal with noise.FFT of noisy signal (two major components are still apparent).

Page 32: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Example of differences in phase.

xn = 0.5 * sin( b1*n ) + 0.2 * sin( b2*n )xn = 0.5 * sin( b1*n – 0.5 ) + 0.2 * sin( b2*n )

Page 33: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Computational complexity:DFT vs. FFT

• The DFT is O(N2) complex multiplications.• In 1965, Cooley (IBM) and Tukey (Princeton) described

the FFT, a fast way (O(N log2 N)) to compute the FT using digital computers.– It was later discovered that Gauss described this algorithm

in 1805, and others had “discovered” it as well before Cooley and Tukey.

– “With N = 106, for example, it is the difference between, roughly, 30 seconds of CPU time and 2 weeks of CPU time on a microsecond cycle time computer.” – from Numerical Recipes in C

Page 34: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Extending the DFT to 2D(and higher)

• Let f(x,y) be a 2D set of sampled points. Then the DFT of f is the following:

• (Note that engineers often use i for amps (current) so they use j for -1 instead.)

1

0

1

0

//2

1

0

1

0

//2

,,

,1

,

M

u

N

v

NvyMuxj

M

x

N

y

NvyMuxj

evuFyxf

eyxfMN

vuF

Page 35: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

Extending the DFT to 2D(and higher)

• In fact, the 2D DFT is separable so it can be decomposed into a sequence of 1D DFTs.

• And this can be generalized to higher and higher dimensions as well.

1

0

/21

0

/2 ,11

,N

y

NvyjM

x

Nuxj eyxfN

eM

vuF

Page 36: The Discrete Fourier Transform. The Fourier Transform “The Fourier transform is a mathematical operation with many applications in physics and engineering

The classical “Gibbs phenomenon”

• Visit http://en.wikipedia.org/wiki/Square_wave.

• Hear it at http://www.youtube.com/watch?v=uIuJTWS2uvY.