Environmental Data Analysis with MatLab 2nd Edition Lecture 13: Filter Theory SYLLABUS Lecture 01 Lecture 02 Lecture 03 Lecture 04 Lecture 05 Lecture 06 Lecture 07 Lecture 08 Lecture 09 Lecture 10 Lecture 11 Lecture 12 Lecture 13 Lecture 14 Lecture 15 Lecture 16 Lecture 17 Lecture 18 Lecture 19 Lecture 20 Lecture 21 Lecture 22 Lecture 23 Lecture 24 Lecture 25 Lecture 26 Using MatLab Looking At Data Probability and Measurement Error Multivariate Distributions Linear Models The Principle of Least Squares Prior Information Solving Generalized Least Squares Problems Fourier Series Complex Fourier Series Lessons Learned from the Fourier Transform Power Spectra Filter Theory Applications of Filters Factor Analysis Orthogonal functions Covariance and Autocorrelation Cross-correlation Smoothing, Correlation and Spectra Coherence; Tapering and Spectral Analysis Interpolation Linear Approximations and Non Linear Least Squares Adaptable Approximations with Neural Networks Hypothesis testing Hypothesis Testing continued; F-Tests Confidence Limits of Spectra, Bootstraps Goals of the lecture develop the Linear Filter as a way to describe the way past events influence present-time observations sometimes, no past history is needed Thermometer measuring temperature θ(t) Flame with time-varying heat h(t) Flame instantaneously heats the thermometer Thermometer retains no heat θ(t) h(t) this idea described as a linear model θ1= g 1 h 1 ... θ10= g 1 h 10 θ11= g 1 h11 θ12= g 1 h 12 ... θN= g 1 h N where g 1 is a constant But sometimes, past history is needed Thermometer measuring temperature θ(t) Steel plate Flame with time-varying heat h(t) Heats takes time to seep through plate Plate retains heat θ(t=t’) history of h(t) for time t<t’ But sometimes, past history is needed Thermometer measuring temperature q(t) Steel plate “causal”: only past effects present (not future) Flame with time-varying heat h(t) Heats takes time to seep through plate Plate retains heat q(t=t’) history of h(t) for time t<t’ this idea described as a linear model ... θ10= g 1 h 10 + g 2 h 9 + g 3 h 8 + g 4 h 7 + … θ11= g 1 h 11 + g 2 h 10 + g 3 h 9 + g 4 h 8 + … θ12= g 1 h 12 + g 2 h 11 + g 3 h 10 + g 4 h 9 + … ... where g 1, g 2, g 3, … are constants called a “filter” Special case: temperature depends only on the time elapsed since the flame was turned on, and not on the experiment as performed on Monday or Wednesday q(t) q(t) same shape experiment is “timeshift invariant” this idea described as a linear model ... θ10= g 1 h 10 + g 2 h 9 + g 3 h 8 + g 4 h 7 + … θ11= g 1 h 11 + g 2 h 10 + g 3 h 9 + g 4 h 8 + … θ12= g 1 h 12 + g 2 h 11 + g 3 h 10 + g 4 h 9 + … ... coefficients all the same … filter is time-shift invariant … where g 1, g 2, g 3, … are constants called a filter this idea written as a summation this idea written as a summation output input filter “convolution”, not multiplication this idea written as matrix equation filter output input we’ve heard the word “convolution” before in Lecture 11 it’s the name of this integral but the integral can be approximated as the summation we’ve just seen so, mathematically, what we’re doing is “convolution” convolutions can be written two ways ... θ10= g 1 h 10 + g 2 h 9 + g 3 h 8 + g 4 h 7 + … θ11= g 1 h 11 + g 2 h 10 + g 3 h 9 + g 4 h 8 + … θ12= g 1 h 12 + g 2 h 11 + g 3 h 10 + g 4 h 9 + … ... g inside matrix h inside matrix implying that the convolution operation is symmetric g*h = h*g meaning of the filter g suppose the input is a spike h = [1, 0, 0, 0 … 0]T output then the output is the filter input filter so the filter represents the “impulse response” of the experiment A) Input is spike h(t), W spike 0 time , t, after impulse q(t), K B) Output is impulse response 0 time , t, after impulse A) h(t), W spike of amplitude, h(t0) time, t h(t0)g(t-t0) q(t). K B) t0 t0 time, t example: heat-generating layer z-axis soil z observation point z=0 soil heat-generating layer known impulse response based on known physics of heat transfer known impulse response soil density soil heat capacity, 1500 kg/m3 800 J/kg-K distance from center of layer soil thermal diffusivity. 1.25×10-6 m2/s A) -3 Dtg(t)g(t) x 10 5 htruehtrue(t) (t), W/m2 0 0 50 100 150 B) 250 300 time, days 350 400 450 500 250 300 time, days 350 400 450 500 250 300 time, days 350 400 450 500 time t, days 10 0 -10 0 50 100 150 200 time t, days C) q trueqtrue1(t) (t), K 200 0.5 0 0 50 100 150 200 time t, days The Method solve using least-squares … well, use damped least square, just in case qobs(t) (t), K htruehtrue(t) (t), W/m2 q obs A) 0.5 0 0 50 100 150 200 B) 250 300 time, days 350 400 450 500 250 300 time, days 350 400 450 500 250 300 time, days 350 400 450 500 time t, days 10 0 -10 0 50 100 150 200 time t, days C) ), hest(t) hest(t) W/m2 10 0 -10 0 50 100 150 200 time t, days qobs(t) (t), K htruehtrue(t) (t), W/m2 q obs noise in data … A) 0.5 0 0 50 100 150 200 B) 250 300 time, days 350 400 450 500 250 300 time, days 350 400 450 500 250 300 time, days 350 time t, days 10 0 -10 0 50 100 150 200 time t, days C) … is amplified ), hest(t) hest(t) W/m2 10 0 -10 0 50 100 150 200 time t, days 400 450 500 Try adding prior information of smoothness (minimize second derivative) obs(t), K q qobs(t) htruehtrue(t) (t), W/m2 W/m2 hest(t) ), hest(t) A) 0.5 0 0 50 100 150 200 250 300 time, days 350 400 450 500 250 300 time, days 350 400 450 500 time t, days B) 10 0 -10 0 50 100 150 200 time t, days C) 10 much less noise 0 -10 0 50 100 150 200 250 300 time, days time t, days 350 400 450 500 Tips on filter calculations with MatLab you should avoid constructing the matrix G= because it contains so many redundant elements Tip #1 use the conv() function to calculate the convolution q = g * h not the matrix multiplication q=Gh tmp = conv(g, h); q=tmp(1:N); note that we truncate the output of conv(), so that is has the same length, N, as the input time series Tip #2 use the bicg() solver, together with the function filterrfun() to solve Fq=h by generalized least squares not matrix division hest=(FTF)\(FTq) it implements the matrix multiplications, GT(Gv), using the timeseries g, and does not ever construct G filterrfun() is described in the text