# Environmental Data Analysis with MatLab Lecture 9: Fourier Series.

## Presentation on theme: "Environmental Data Analysis with MatLab Lecture 9: Fourier Series."— Presentation transcript:

Environmental Data Analysis with MatLab Lecture 9: Fourier Series

Lecture 01Using MatLab Lecture 02Looking At Data Lecture 03Probability and Measurement Error Lecture 04Multivariate Distributions Lecture 05Linear Models Lecture 06The Principle of Least Squares Lecture 07Prior Information Lecture 08Solving Generalized Least Squares Problems Lecture 09Fourier Series Lecture 10Complex Fourier Series Lecture 11Lessons Learned from the Fourier Transform Lecture 12Power Spectra Lecture 13Filter Theory Lecture 14Applications of Filters Lecture 15Factor Analysis Lecture 16Orthogonal functions Lecture 17Covariance and Autocorrelation Lecture 18Cross-correlation Lecture 19Smoothing, Correlation and Spectra Lecture 20Coherence; Tapering and Spectral Analysis Lecture 21Interpolation Lecture 22 Hypothesis testing Lecture 23 Hypothesis Testing continued; F-Tests Lecture 24 Confidence Limits of Spectra, Bootstraps SYLLABUS

purpose of the lecture detect and quantify periodicities in data

importance of periodicities

Stream Flow Neuse River discharge, cfs time, days 365 days 1 year

Air temperature Black Rock Forest 365 days 1 year

Air temperature Black Rock Forest time, days 1 day

temporal periodicities and their periods astronomical rotation daily revolution yearly other natural ocean waves a few seconds anthropogenic electric power 60 Hz

delay, t 0 amplitude, C period, T d(t) time, t sinusoidal oscillation f(t) = C cos{ 2π (t-t 0 ) / 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 periodicities and their wavelengths natural sand dunes hundreds of meters tree rings a few millimeters anthropogenic furrows plowed in a field few tens of cm

pairing sines and cosines to avoid using time delays

derived using trig identity AB

AB A=C cos(ωt 0 ) B=C sin(ωt 0 ) A 2 =C cos 2 (ωt 0 ) B 2 =C sin 2 (ωt 0 ) A 2 +B 2 =C 2 [cos 2 (ωt 0 )+sin 2 (ωt 0 )] = C 2

Fourier Series linear model containing nothing but sines and cosines

A ’s and B’s are model 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 f ny total number of frequencies? N/2+1 number of model parameters, M = number of data, N

implies

Number of Frequencies why N/2+1 and not N/2 ? first and last sine are omitted from the Fourier Series since they are identically zero:

cos(Δω t)cos(0t)sin(Δωt)cos(2Δω t)sin(2Δω t) cos(½NΔω t)

Nyquist Sampling Theorem when m=n+N another way of stating it note evenly sampled times

ω n = (n-1) Δ ω and t k = (k-1) Δ t Step 1: Insert discrete frequencies and times into l.h.s. of equations.

ω n = (n-1+N) Δ ω and t k = (k-1) Δ t Step 2: Insert discrete frequencies and times into r.h.s. of equations.

same as l.h.s. Step 3: Note that l.h.s equals r.h.s.

when m=n+N or when ω m =ω n +2ω ny only a 2ω ny interval of the ω -axis is unique say 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 ω ny part of the ω -axis is unique Step 5: Apply symmetry of sines and cosines

  ny  ny  ny  ny  equivalent points on the ω -axis

d 2 (t) d 1 (t) time, t d  (t) = cos(   t), with   =2  d  (t) = cos{   t}, with   =(2+N) ,

problem of aliasing high frequencies masquerading as low frequencies solution: pre-process data to remove high frequencies before digitizing it

Discrete Fourier Series d = Gm

Least Squares Solution m est = [G T G] -1 G T d has substantial simplification … since it can be shown that …

% N = number of data, presumed even % Dt is time sampling interval t = 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 setup in 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 ’s plot 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

365.2 days period, days frequency, cycles per day amplitude spectral density 182.6 days 60.0 days amplitude spectral density Stream Flow Neuse River all interesting frequencies near origin, so plot period, T=1/f instead