[R] fft inverse display help

rkevinburton at charter.net rkevinburton at charter.net
Wed Oct 1 16:56:17 CEST 2008

Generate the 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))

Take the fft of the series generated:

series <- genseq()
series <- ts(c(series, rep(0, nextn(length(series)) - length(series))), frequency = 365)
fs <- fft(series)

Filter the response. Pick any two frequencies:

ff <- complex(length(fs))
ff[9] <- fs[9]
ff[5] <- fs[5]

Include the DC component:

ff[1] <- fs[1]

Take the inverse

fi <- fft(ff, inverse=TRUE) / length(ff)



Notice that the plot is the Re vs. Im on the x and y axis' respectively.

Now notice the difference if I plot the inverse fft

plot(fft(fs/length(fs), inverse=TRUE))

My question was simply the "automatic" mode that 'plot' seems to be taking. In the first instance Re vs. Im and the second series vs. Time.


---- Dieter Menne <dieter.menne at menne-biomed.de> wrote: 
>  <rkevinburton <at> charter.net> writes:
> > 
> > So iis what you are saying n plotting the list of compliex numbers 'R'
> recognizes the non-symmery and plots
> > it differently (Re vs. Im) rather than versus Time?
> Mmm... don't fully understand what you mean, mainly because your program example
> did not run and I had do some guessing what your problem was.
> Dieter
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list