[R] fft inverse display help

rkevinburton at charter.net rkevinburton at charter.net
Tue Sep 30 21:17:05 CEST 2008


I have a a simple function that generates a time series square wave:

genseq <- function()
{
  x <- numeric(4*365)
  s <- seq(as.Date("2005-01-01"), as.Date("2008-12-31"), by="month")
  ob <- as.vector(s[c(10,22,34,46)] - as.Date("2005-01-01"))
  oe <- as.vector(s[c(11,23,35,47)] - as.Date("2005-01-01"))
  for(.index in 1:length(ob))
  {
    x[ob[.index]:(oe[.index] - 1)] <- 1 
  }
  return(ts(x, frequency=365))
}

Then I take the invenrse:

fs <- fft(series)
fi <- fft(fs, inverse=TRUE) / length(fs)
plot(fi)

This as expected gives me back exactly what I put in. The x axis is label in Time and the y axis is labeled as 'fi'. Now if I try some filtering and select a few frequencies:

ff <- complex(length(fs))
sei <- order(e)
ff[sei[1:40]] <- fs[sei[1:40]]
fi <- fft(ff, inverse=TRUE) / length(ff)
plot(fi, main = "After filter")

Now I ge the x-asis as the real component and y-axis as imaginary component. When does the display switch? How many frequencies do I select before I get the 'Time' axis back? From the above I am selecting 40 (out of 1500).

Thank you.

Kevin



More information about the R-help mailing list