Environmental Data Analysis with MatLab
Lecture 9:
Fourier Series
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
purpose of the lecture
detect and quantify periodicities in data
importance of periodicities
Stream FlowNeuse River
disc
harg
e, c
fs
time, days
365 days1 year
Air temperatureBlack Rock Forest
365 days1 year
Air temperatureBlack Rock Forest
time, days
1 day
temporal periodicitiesand their periods
astronomical
rotationdaily
revolutionyearly
other natural
ocean wavesa few seconds
anthropogenic
electric power60 Hz
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 }
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
angular frequency, ω=2 π /T wavenumber, k=2 π / λ-
f(t) = C cos(ωt) f(x) = C cos(kx)
spatial periodicitiesand their wavelengths
natural
sand duneshundreds of meters
tree ringsa few millimeters
anthropogenic
furrows plowed
in a fieldfew tens of cm
pairing sines and cosinesto avoid using time delays
derived using trig identity
A B
A BA=C cos(ωt0)B=C sin(ωt0) A2=C cos2 (ωt0)B2=C sin2 (ωt0)A2+B2=C2 [cos2 (ωt0)+sin2 (ωt0)]= C2
Fourier Serieslinear model containing nothing but
sines and cosines
A’s and B’s aremodel parameters
ω’s are auxiliary variables
two choices
values of frequencies?
total number of frequencies?
surprising fact about time series with evenly sampled data
Nyquist frequency
values of frequencies?
evenly spaced, ωn = (n-1)Δ ω
minimum frequency of zero
maximum frequency of fnytotal number of frequencies? N/2+1
number of model parameters, M= number of data, N
implies
Number of Frequencieswhy N/2+1 and not N/2 ?
first and last sine are omitted from the Fourier Series since they are
identically zero:
-2 0 20
5
10
15
20
25
30
col 1
tim
e,
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(½NΔω t)
Nyquist Sampling Theorem
when m=n+Nanother way of stating it
note evenly sampled times
ωn = (n-1)Δ ω and tk = (k-1) Δt
Step 1: Insert discrete frequencies and times into l.h.s. of equations.
ωn = (n-1+N)Δ ω and tk = (k-1) Δt
Step 2: Insert discrete frequencies and times into r.h.s. of equations.
same as l.h.s.
same as l.h.s.
Step 3: Note that l.h.s equals r.h.s.
when m=n+Nor when
ωm=ωn+2ωny
only a 2ωny interval of the ω -axis is uniquesay from-ωny to +ωny
Step 4: Identify unique region of ω-axis
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
Step 5: Apply symmetry of sines and cosines
w
-wny wny 2wny 3wny0
equivalent points on the ω-axis
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,
problem of aliasing
high frequenciesmasquerading as low frequencies
solution:pre-process data to remove high
frequenciesbefore digitizing it
Discrete Fourier Series
d = Gm
Least Squares Solution mest = [GTG]-1 GTdhas substantial simplification
… since it can be shown that …
% N = number of data, presumed even% Dt is time sampling intervalt = Dt*[0:N-1]’;
Df = 1 / (N * Dt );Dw = 2 * pi / (N * Dt);
Nf = N/2+1;Nw = N/2+1;
f = Df*[0:N/2];w = Dw*[0:N/2];
frequency and time setupin MatLab
% set up G G=zeros(N,M); % zero frequency column G(:,1)=1; % interior M/2-1 columns for i = [1:M/2-1] j = 2*i; k = j+1; G(:,j)=cos(w(i+1).*t); G(:,k)=sin(w(i+1).*t); end % nyquist column G(:,M)=cos(w(Nw).*t);
Building G in MatLab
gtgi = 2* ones(M,1)/N; gtgi(1)=1/N; gtgi(M)=1/N; mest = gtgi .* (G'*d);
solving for model parameters in MatLab
how to plot the model parameters?A’s and B ’splot
against frequency
power spectral density
big at frequency ω when
when sine or cosine at the frequency
has a large coefficient
alternatively, plot
amplitude spectral density
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 days
period, days
frequency, cycles per day
ampl
itud
e sp
ectr
al d
ensi
ty
182.6 days60.0 days
ampl
itud
e sp
ectr
al d
ensi
ty
Stream FlowNeuse River
all interesting frequencies near origin,so plot period, T=1/f instead