+ All Categories
Home > Documents > Environmental Data Analysis with MatLab

Environmental Data Analysis with MatLab

Date post: 24-Feb-2016
Category:
Upload: keilah
View: 66 times
Download: 0 times
Share this document with a friend
Description:
Environmental Data Analysis with MatLab. Lecture 9: Fourier Series. SYLLABUS. - PowerPoint PPT Presentation
Popular Tags:
110
Environmental Data Analysis with MatLab Lecture 9: Fourier Series
Transcript
Page 1: Environmental Data Analysis with  MatLab

Environmental Data Analysis with MatLab

Lecture 9:

Fourier Series

Page 2: Environmental Data Analysis with  MatLab

Lecture 01 Using MatLabLecture 02 Looking At DataLecture 03 Probability and Measurement Error Lecture 04 Multivariate DistributionsLecture 05 Linear ModelsLecture 06 The Principle of Least SquaresLecture 07 Prior InformationLecture 08 Solving Generalized Least Squares ProblemsLecture 09 Fourier SeriesLecture 10 Complex Fourier SeriesLecture 11 Lessons Learned from the Fourier TransformLecture 12 Power SpectraLecture 13 Filter Theory Lecture 14 Applications of Filters Lecture 15 Factor Analysis Lecture 16 Orthogonal functions Lecture 17 Covariance and AutocorrelationLecture 18 Cross-correlationLecture 19 Smoothing, Correlation and SpectraLecture 20 Coherence; Tapering and Spectral Analysis Lecture 21 InterpolationLecture 22 Hypothesis testing Lecture 23 Hypothesis Testing continued; F-TestsLecture 24 Confidence Limits of Spectra, Bootstraps

SYLLABUS

Page 3: Environmental Data Analysis with  MatLab

temporal periodicitiesand their periods

astronomical

rotationdaily

revolutionyearly

other natural

ocean wavesa few seconds

anthropogenic

electric power60 Hz

Page 4: Environmental Data Analysis with  MatLab

spatial periodicitiesand their wavelengths

natural

sand duneshundreds of meters

tree ringsa few millimeters

anthropogenic

furrows plowedin a field

few tens of cm

Page 5: Environmental Data Analysis with  MatLab

Air temperatureBlack Rock Forest

365 days1 year

Page 6: Environmental Data Analysis with  MatLab

Air temperatureBlack Rock Forest

time, days

1 day

Page 7: Environmental Data Analysis with  MatLab

Stream FlowNeuse River

disc

harg

e, c

fs

time, days

365 days1 year

Page 8: Environmental Data Analysis with  MatLab

amplitude, C

lingo

temporal

f(t) = C cos{ 2π t / T }spatial

f(x) = C cos{ 2π x / λ }amplitude, C

period, T wavelength, λfrequency, f=1/T"cycles per (year,day,s)"

angular frequency, ω=2 π /T"radians per ..."

wavenumber, k=2 π / λ-

f(t) = C cos(ωt) f(x) = C cos(kx)

Page 9: Environmental Data Analysis with  MatLab

0 10 20 30 40 50 60 70 80 90-3

-2

-1

0

1

2

3

time, t

d(t)

cosine example

delay, t0

amplitude, C

period, T

d(t)

time, t

sinusoidal oscillationf(t) = C cos{ 2π (t-t0) / T }

Page 10: Environmental Data Analysis with  MatLab

pairing sines and cosinesto avoid using time delays

Page 11: Environmental Data Analysis with  MatLab

Fourier Serieslinear model containing nothing but

sines and cosines

Page 12: Environmental Data Analysis with  MatLab

A’s and B’s aremodel parameters

ω’s are auxiliary variables

Page 13: Environmental Data Analysis with  MatLab

Data series: spacing Dt, length T Mean of series in cos(0*t) termLowest frequency is 1 cycle/T

Freq. spacing Dw: 1,2,3,... cycles/T Highest frequency is (1 cycle)/2Dt

(cosine part only – a zigzag)

Nyquist frequency

Page 14: Environmental Data Analysis with  MatLab

-2 0 20

5

10

15

20

25

30

col 1

time,

s

-2 0 20

5

10

15

20

25

30

col 2

-2 0 20

5

10

15

20

25

30

col 3

-2 0 20

5

10

15

20

25

30

col 4

-2 0 20

5

10

15

20

25

30

col 5

-2 0 20

5

10

15

20

25

30

col 32cos(Δω t)cos(0t) sin(Δωt) cos(2Δω t) sin(2Δω t)cos(2pt/32 *16)frequency 0 = mean offset cos and sin of (2pt/32 x 1,2,3,...15) (1,2,3...15 cycles/record-length)

32 numbers in physical space 32 numbers in spectral space

Page 15: Environmental Data Analysis with  MatLab

problem of aliasing

frequencies higher than Nyquist(that is, periods shorter than 2Dt)masquerade as low frequencies

example

solution:use averages over Dt, not

instantaneous samples spaced Dt apart.

Page 16: Environmental Data Analysis with  MatLab

0 5 10 15 20-2

-1

0

1

2

time, t

d1(t)

0 5 10 15 20-2

-1

0

1

2

time, t

d2(t)d2(t)

d1(t)

time, t

time, t

d1 (t) = cos(w1t), with w1=2Dw

d2(t) = cos{w2t}, with w2=(2+N)Dw,

Page 17: Environmental Data Analysis with  MatLab

cos(ω t) has same shape as cos(-ω t) and

sin(ω t) has same shape as sin(-ω t) so really only the

0 to ωnypart of the ω-axis is unique

symmetry of sines and cosines

Page 18: Environmental Data Analysis with  MatLab

w

-wny wny 2wny 3wny0

equivalent points on the ω-axis

cos(ω t) = cos(ω t +2p) = cos(ω t -2p) = ...sin(ω t) = sin(ω t +2p) = sin(ω t -2p) = ...

so really only the0 to ωny

part of the ω-axis is unique

Page 19: Environmental Data Analysis with  MatLab

power spectral density

it is big at a frequency ω whenwhen sine or cosine at that frequency

has a large coefficient

Page 20: Environmental Data Analysis with  MatLab

alternatively, plotamplitude spectral density

Page 21: Environmental Data Analysis with  MatLab

0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.50

1000

2000

3000

frequency, cycles per day

spec

trum

0 100 200 300 400 500 600 700 800 900 10000

500

1000

1500

2000

period, days

spec

trum

365.2 d = 12 cycles per 4500d

period, days

frequency, cycles per day

ampl

itude

sp

ectra

l den

sity

182.6 days60.0 days

ampl

itude

sp

ectra

l den

sity

Stream FlowNeuse River

all interesting frequencies near origin

can plot period, T=1/f instead

5 cyclesper 4500d

6 per 4500d line is misleading! psd is discrete (should be bar plot)

7

Page 22: Environmental Data Analysis with  MatLab

purpose of the lecture

switch from Fourier Series containingsines and cosines

to Fourier Series containingcomplex exponentials

Page 23: Environmental Data Analysis with  MatLab

purpose of the lectureswitch from Fourier Series containing

sin(ωt) and cos(ωt)

to

Fourier series containing

exp(-iωt) and exp(+iωt)

Page 24: Environmental Data Analysis with  MatLab

review of complex numbers

Page 25: Environmental Data Analysis with  MatLab

imaginary unit

i

such thati2 = -1

Page 26: Environmental Data Analysis with  MatLab

complex number

a = ar + i ai

real part

imaginary part

Page 27: Environmental Data Analysis with  MatLab

adding complex numbers

a = ar + i ai b = br + i bic = a+b = (ar + i ai )+ (br + i bi ) = (ar + br )+ i(ai +bi ) cr ci … just add real and imaginary parts, separately

Page 28: Environmental Data Analysis with  MatLab

subtracting complex numbers

a = ar + i ai b = br + i bic = a-b = (ar + i ai )-(br + i bi ) =

(ar - br )+ i(ai - bi ) cr ci … just subtract real and imaginary parts, separately

Page 29: Environmental Data Analysis with  MatLab

multiplying complex numbersa = ar + i ai b = br + i bic = ab = (ar + i ai )(br + i bi ) == ar br + i ar bi + i ai br + i2 ai bi = (ar br - ai bi )+ i(ar bi + ai br ) cr ci … like multiplying polynomials

Page 30: Environmental Data Analysis with  MatLab

complex conjugate, a*a = ar + i ai a* = ar - i ai

Page 31: Environmental Data Analysis with  MatLab

absolute value, |a ||a | = [ ar2 + ai2 ]½

note |a |2 = a* a

Page 32: Environmental Data Analysis with  MatLab

MatLabhandles complex numbers completely transparently

a = 2 + 3*i;b = 4 + 6*i;

c = a+b;

works just fine

Page 33: Environmental Data Analysis with  MatLab

Warning!accidentally resetting i to something

other than i is so easy i=100;

(and then you get nonsense)

so execute aclear i;

at the top of your script if you plan to use i

Page 34: Environmental Data Analysis with  MatLab

or use the alternate notation

a = complex(2,3);b = complex(4,6);

c = a+b;

which is safer

Page 35: Environmental Data Analysis with  MatLab

end of review

Page 36: Environmental Data Analysis with  MatLab

Euler’s Formula

exp(iz) = cos(z) + i sin(z)

… where does that come from ???

Page 37: Environmental Data Analysis with  MatLab

any complex number can be written

z = r exp(iθ) where r = |z | and θ=tan-1(zi/zr)

Page 38: Environmental Data Analysis with  MatLab

Euler’s Formulascomplex exponentials can be written as sines and cosines

Page 39: Environmental Data Analysis with  MatLab

or reverse themsine and cosines can be written as complex exponentials

Page 40: Environmental Data Analysis with  MatLab

so a Fourier Seriesalternatively can be written

as a sum of sines and cosinesor a sum of complex exponentials

Page 41: Environmental Data Analysis with  MatLab

old-style Fourier Series

non-negative frequencies only,

from0 to ωny

sin=0 for 0 and ωny

Page 42: Environmental Data Analysis with  MatLab

new-style Fourier Seriesor “Inverse Discrete Fourier Transform”

non-negativefrequencies

negativefrequencies

added for compatibility with MatLab

Page 43: Environmental Data Analysis with  MatLab

why the weird ordering of frequencies?ωn = ( 0, Δω, 2Δω, …, N½ Δω, -( N½ -1) Δω, …, -2 Δω, -Δω )

same asωn = ( 0, Δω, 2Δω, …, N½ Δω, ( N½ +1) Δω, …, (N-1)Δω, NΔω )

non-negativefrequencies

negativefrequencies

non-negative frequencies up to

Nyquist

non-negative frequencies above the Nyquist

Page 44: Environmental Data Analysis with  MatLab

least-squares solution for the Fourier coefficients, Cn or “Discrete Fourier Transform”

… derivation requires complex version of least-

squares. See text for details …

Page 45: Environmental Data Analysis with  MatLab

MatLab

Fourier Coefficients Cj from time series dn

c = fft(d);

vector of N datavector of N complex Fourier

coefficients

Page 46: Environmental Data Analysis with  MatLab

MatLab

time series dn from Fourier Coefficients Cj d = ifft(c);

vector of N data

vector of N complex Fourier

coefficients

Page 47: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

Page 48: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

same number M of Fourier Coefficients as number N of data

Page 49: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

maximum time, for N data sampled at Dt

Page 50: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

time column-vector

Page 51: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

Nyquist frequency, fny

Page 52: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

frequency sampling, Δf

Page 53: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

frequency column- vector

Page 54: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

number of frequencies between 0 and Nyquist

Page 55: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

angular frequency sampling, Δω

Page 56: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf;

angular frequency

column- vector

Page 57: Environmental Data Analysis with  MatLab

standard setupM=N; tmax=Dt*(N-1); t=Dt*[0:N-1]'; fmax=1/(2.0*Dt); df=fmax/(N/2); f=df*[0:N/2,-N/2+1:-1]'; Nf=N/2+1; dw=2*pi*df; w=dw*[0:N/2,-N/2+1:-1]'; Nw=Nf; number of angular frequencies between 0 and Nyquist

Page 58: Environmental Data Analysis with  MatLab

Computing Power Spectral Density

% compute Fourier coefficients mest = fft(d);

% compute amplitude spectral density s=abs(mest(1:Nw));

% compute power spectral density s2=s^2;

Page 59: Environmental Data Analysis with  MatLab

Spectral Density

% compute Fourier coefficients mest = fft(d);

% compute amplitude spectral density s=abs(mest(1:Nw));

% compute power spectral density s2=s^2;

note that negative frequencies are discardedsince they are redundant

Page 60: Environmental Data Analysis with  MatLab

Why The Switch to Complex?

One function, exp(), is better than two, cos() & sin()exp() is algebraically simpler than cos() & sin(),

e.g. exp(a) / exp(b) = exp( a – b)which substantially simplifies formulas

Tradition – that’s the way everyone does it! Or more importantly, that’s the way MatLab does it.

Page 61: Environmental Data Analysis with  MatLab

di

ti Δt

time series

Page 62: Environmental Data Analysis with  MatLab

di

ti Δta time series is a discrete representation of a

continuous function

continuous function

Page 63: Environmental Data Analysis with  MatLab

d(t)

t

continuous function

What happens when to the Discrete Fourier Transform when we switch from discrete to continuous?

Page 64: Environmental Data Analysis with  MatLab

Discrete Fourier Transform

Fourier Transform

turns into

Page 65: Environmental Data Analysis with  MatLab

note the use of the tilde to distinguish a the Fourier Transform from the function itself.

The two functions are different!

Fourier Transform

Page 66: Environmental Data Analysis with  MatLab

function of timefunction of frequency

Fourier Transform

power spectral density = 2

Page 67: Environmental Data Analysis with  MatLab

function of time function of frequency

the inverse of the Fourier Transform is

Page 68: Environmental Data Analysis with  MatLab

Example of Fourier transform

the Fourier Transform of a spike

is constant

Page 69: Environmental Data Analysis with  MatLab

spike“Dirac Delta Function”

Normal curve with infinitesimal variance

infinitely highbut always has unit area

Page 70: Environmental Data Analysis with  MatLab

δ(t-t0)

t

depiction of spike

t0

Page 71: Environmental Data Analysis with  MatLab

important property of spike

Page 72: Environmental Data Analysis with  MatLab

t

since the spike is zero everywhere except t0

t0

tt0

f(t0)

f(t0)

this product …

… is equivalent to this one

Page 73: Environmental Data Analysis with  MatLab

so

Page 74: Environmental Data Analysis with  MatLab

use the previous result when computing the Fourier Transform of a spike

Page 75: Environmental Data Analysis with  MatLab

A spiky time series

has a “flat” Fourier Transform

and a “flat” power spectral density

Page 76: Environmental Data Analysis with  MatLab

0 50 100 150 200 250-1

-0.5

0

0.5

1

time, t

d(t)

-0.5 -0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.50

0.5

1

1.5

2

frequency, f

d(f)

A) spike function

B) its transform

frequency, f

time, t

d(t)

d(f)^

Page 77: Environmental Data Analysis with  MatLab

Property 1

the Fourier Transform of a Normal curve with variance σt2

is a Normal curve with variance σω2 =σt-2

Page 78: Environmental Data Analysis with  MatLab

let a2= ½σt-2

[cos(ωt ) + i sin(ωt )] dtcos(ωt ) dt + i sin(ωt ) dt

symmetric about zero antisymmetric about zeroso integral zero

Normal curve with variance a½ -2 = σt2

Page 79: Environmental Data Analysis with  MatLab

look up in table of integrals

Normal curve with variance 2a2 = σt-2

Page 80: Environmental Data Analysis with  MatLab

time series with broad featuresFourier Transform with mostly low frequencies

power spectral density with mostly low frequencies

time series with narrow featuresFourier Transform with both low and high frequenciespower spectral density with broad range of frequencies

Page 81: Environmental Data Analysis with  MatLab

increasing variance

time,

t

freq

uenc

y, f

A)

increasing variance

B)

tmax fmax

0 0

Page 82: Environmental Data Analysis with  MatLab

Property 2

the Fourier Transform of a spike

is constant

Page 83: Environmental Data Analysis with  MatLab

Property 3

the Fourier Transform of cos(ω0t )is a pair of spikes at frequencies ±ω0

Page 84: Environmental Data Analysis with  MatLab

cos(ω0t )has Fourier Trnsform

Page 85: Environmental Data Analysis with  MatLab

as is shown by inserting into the Inverse Fourier Transform

Page 86: Environmental Data Analysis with  MatLab

An oscillatory time series

has spiky Fourier Transformand a power spectral density with spectral peaks

Page 87: Environmental Data Analysis with  MatLab

Property 4

the area under a time series

is the zero-frequency value of the Fourier Transform

Page 88: Environmental Data Analysis with  MatLab
Page 89: Environmental Data Analysis with  MatLab

A time series with zero mean

has a Fourier Transformthat is zero at zero frequency

Page 90: Environmental Data Analysis with  MatLab

MatLab

dt=fft(d); area = real(dt(1));

Page 91: Environmental Data Analysis with  MatLab

Property 5

multiplying the Fourier Transform byexp( -i ω t0)delays the time series by t0

Page 92: Environmental Data Analysis with  MatLab

use transformation of variablest’ = t - t0and notedt’ = dtandt±∞ corresponds to t’±∞

Page 93: Environmental Data Analysis with  MatLab

0 50 100 150 200 250-1

-0.5

0

0.5

1

time, t

d(t)

0 50 100 150 200 250-1

-0.5

0

0.5

1

time, t

d shifte

d(t)d(t)

time, t

time, t

d(t)

dshift

ed(t)

Page 94: Environmental Data Analysis with  MatLab

MatLab

t0 = t(16); ds=ifft(exp(-i*w*t0).*fft(d));

Page 95: Environmental Data Analysis with  MatLab

Property 6

multiplying the Fourier Transform byi ωdifferentiates the time series

Page 96: Environmental Data Analysis with  MatLab
Page 97: Environmental Data Analysis with  MatLab

use integration by partsand assume that the times series is zeroas t±∞

dvu uv duv

Page 98: Environmental Data Analysis with  MatLab

0 50 100 150 200 250-1

0

1

time, t

d(t)

0 50 100 150 200 250-0.02

0

0.02

time, t

dd/d

t(t)

0 50 100 150 200 250-0.02

0

0.02

time, t

dd/d

t(t)

time, t

A)

B)

C)

d(t)

dd/dt

dd/dt

Page 99: Environmental Data Analysis with  MatLab

MatLab

dddt=ifft(i*w.*fft(d));

Page 100: Environmental Data Analysis with  MatLab

Property 7

dividing the Fourier Transform byi ωintegrates the time series

Page 101: Environmental Data Analysis with  MatLab

this is another derivation byintegration by parts

but we’re skipping it here

Page 102: Environmental Data Analysis with  MatLab

Fourier Transform of integral of d(t)

note that the zero-frequency value is undefined(divide by zero)

this is the “integration constant”

Page 103: Environmental Data Analysis with  MatLab

0 50 100 150 200 250-1

0

1

time, t

d(t)

0 50 100 150 200 250-100

0

100

time, t

inte

gral

0 50 100 150 200 250-100

0

100

time, t

inte

gral

time, t

A)

B)

C)

d(t)

d

(t) d

t

d(t)

dt

Page 104: Environmental Data Analysis with  MatLab

MatLab

int2=ifft(i*fft(d).*[0,1./w(2:N)']');

set to zero to avoid dividing by zero (equivalent to an

integration constant of zero)

Page 105: Environmental Data Analysis with  MatLab

Property 8

Fourier Transform of theconvolution of two time series

is the product of their transforms

Page 106: Environmental Data Analysis with  MatLab

What’s a convolution ?

Page 107: Environmental Data Analysis with  MatLab

the convolution of f(t) and g(t)is the integral

which is often abbreviated f(t) *g(t)not multiplication

not complex conjugation(too many uses of the asterisk!)

Page 108: Environmental Data Analysis with  MatLab

uses of convolutions will be presented in the lecture after next

right now, just treat it as a mathematical quantity

Page 109: Environmental Data Analysis with  MatLab
Page 110: Environmental Data Analysis with  MatLab

transformation of variablest’ = t-τ so dt’ = dt and t’±∞ when t±

reverse order of integration

change variables: t’ = t-τ

use exp(a+b)=exp(a)exp(b)

rearrange into the product of two separate Fourier Transforms


Recommended