Skip to content
Prev 171829 / 398506 Next

Moving Average

I wrote a little code using Fourier filtering if you would like to
take a look at this:

library(StreamMetabolism)
library(mFilter)
x <- read.production(file.choose())
#contiguous.zoo(data.frame(x[,"RM202DO.Conc"], coredata(x[,"RM202DO.Conc"])))
#contiguous.zoo(data.frame(x[,"RM61DO.Conc"], coredata(x[,"RM61DO.Conc"])))
short <- x[42685:48535,"RM202DO.Conc"]
#short <- x[53909:59957,"RM61DO.Conc"]
short.ts <- ts(coredata(short), frequency=96)
#fourier filtering
short.fft <- fft(short.ts)
plot(Re(short.fft), xlim=c(0,10), ylim=c(-1000, 1000))
short.fft[789:5563] = 0+0i
short.ifft = fft(short.fft, inverse = TRUE)/length(short.fft)
#zoo series
filt <- zoo(coredata(Re(short.ifft)) , index(short))



par(mfrow=c(2,1))
plot(short)
plot(filt)

window.plot <- function(x, y, a, b, s, d){
	par(mfrow=c(2,1))
	plot(window.chron(x, a, b, s, d))
	plot(window.chron(y, a, b, s, d))
	}
window.plot(short, filt, "04/17/2007", "00:01:00", "04/17/2007", "23:46:00")


plot.e <- function(b, w, x, y, z){
a <- window.chron(b, w, x, y, z)
plot(a, ylim=range(a)+0.06*c(-1, 1))
lines(a*0.98, col="blue")
lines(a*1.02, col="red")
}

it may not be exactly what you want, but you will have a handle on
what spectral properties that you have removed.

On Thu, Feb 26, 2009 at 9:54 AM, Ted Harding
<Ted.Harding at manchester.ac.uk> wrote: