1 / 29

Applications of Filters

Applications of Filters. Running Average of length M. f = M -1 [1, 1, 1, … 1] T. f. M -1. 0. t 0. t M-1. time, t. … since no future values of x are available. Note that average is “delayed” …. 1. x. 0. t 0. t M-1. Could be ‘re-centered’ during plotting’. M -1. f * x. 0. t 0.

tait
Download Presentation

Applications of Filters

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Applications of Filters

  2. Running Average of length M f = M-1 [1, 1, 1, … 1]T f M-1 0 t0 tM-1 time, t

  3. … since no future values of x are available Note that average is “delayed” … 1 x 0 t0 tM-1 Could be ‘re-centered’ during plotting’ M-1 f*x 0 t0 tM-1 time, t center

  4. MatLab Example M = 30; % length of filter f = (1/M) * ones(M,1); y = conv(f,T); Note MatLab has an built-in convolution function If x has length N and y has length M then x*y has length N+M-1

  5. Laguardia Airport Mean Temperature 2 years of data Blue: daily mean temperature dataRed: 14 day running average

  6. Laguardia Airport Mean Temperature 2 years of data Blue: daily mean temperature dataRed: 30 day running average

  7. Laguardia Airport Mean Temperature 20 years of data Blue: daily mean temperature dataRed: 365 day running average Note “edge effect”

  8. Criticism of Running Average: it has sharp edges sharp edge f M-1 0 t0 tM-1 time, t The filter can produce rough results, because, as the filter advances in time, an outlier suddenly goes from being inside to outside

  9. Gaussian running average f M-1 0 t0 tM-1 time, t f 67% of area between t0 and tM-1 0 t0 tM-1 time, t Need to discard a bit of future here

  10. MatLab Example width = 14; % 67 percent width sigma = 14/2; % standard deviation M = 6*round(sigma/dt); % truncate filter at +/- 3 sigma delay = 3*sigma; % center of filter f = exp( -(t(1:M)-delay).^2 / (2*sigma*sigma) ); amp = sum(f); % normalize to unit amplitude f = f/amp;

  11. 14 day Gaussian filter 14 days

  12. Laguardia Airport Mean Temperature 2 years of data Blue: daily mean temperature dataRed: 14 day Gaussian running average

  13. Laguardia Airport Mean Temperature “Box car” “Gaussian” Blue: daily mean temperature dataRed: 14 day Gaussian running average

  14. Exponential was easy to implement recursively f M-1 0 t0 tM-1 time, t f 67% of area between t0 and tM-1 M-1 0 t0 tM-1 time, t

  15. Some calculations If f(t) = c-1 exp( -t/c ) What value of c puts A1 fraction of area between 0 and t1? A = 0t1c-1 exp( -t/c ) dt = exp(-t/c)| 0t1= 1- exp(-t1/c) Note A(t=)=1 So A1 = 1- exp(-t1/c) (1-A1) = exp(-t1/c) ln(1-A1) = (-t1/c) c = -t1 / ln(1-A1) and t1 = -c / ln(1-A1)

  16. MatLab Code width = 14; % 67% width c = -width/log(1.0-0.67); % constant in exponential M = 6*round(width/dt); % truncate filter at 6 widths delay = -width/log(1.0-0.50); % delay at 50% of area f = exp( -t(1:M)/c ); amp = sum(f); % normalize to sum to unity f = f/amp;

  17. Laguardia Airport Mean Temperature “Gaussian” “exponential” Blue: daily mean temperature dataRed: 14 day Gaussian running average

  18. first derivative filter f = Dt [1, -1]T But note delayed by ½Dt M=2; f = dt*[1,-1]'; delay = 0.5*dt; second derivative filter f = (Dt)2 [1, -2, 1]T But note delayed by Dt

  19. First-derivative note more-variable in winter

  20. second-derivative note more-variable in winter

  21. prediction error filter x = [x1, x2, x3, x4, … xN-1]T f = [-1, f1, f2, f3, f4, … fN-1]T Choose f such that f*x  0 f5, f4, f3, f2, f1, -1 … xM-3, xM-2, xM-1, xM, xM+1, xM+2, xM+3, … xM = f1xM-1 + f2xM-2 + f3xM-3 … xM predicted from past values

  22. MatLab Code M=10; % filter of length M, data of length N G = zeros(N+1,M); % solve by least-squares d = zeros(N+1,1); % implement condition f0=1 % as if its prior information for p = [1:M] % usual G matrix for filter G(p:N,p) = T(1:N-p+1); d(p)=0; % d vector is all zero end G(N+1,1)=1e6; % prior info, with epsilon=1e6 d(N+1)=-1e6; f = inv(G'*G)*G'*d; % least-squares solution y = conv(f,T); % try out fileter, y is prediction error

  23. filter length M = 10 days filter, f

  24. filter length M = 10 days x f*x error = 6.4105

  25. filter length M = 100 days filter, f

  26. filter length M = 10 days x f*x error = 6.2105

  27. f*x is the unpredictable part of x

  28. Let’s try it with the Neuse River Hydrograph Dataset Filter length M=100 What’s that? x f*x

  29. Close up of first year of data Note that the prediction error, f*x, is spikier than the hydrograph data, x. I think that this means that some of the dynamics of the river flow is being captured by the filter, f, and that the unpredictable part is mostly the forcing, that is, precipitation x f*x

More Related