I am reading this "how to" in R: http://www.inside-r.org/howto/time-series-analysis-and-order-prediction-r

I am confused about the tutorial's implemented band pass filter. In particular, here's the code I'm wondering about. The goal is to extrapolate a time series based only on certain ranges of frequencies determined by peakind.

subsignals <- lapply(c(peakind$freqindex, midindex+1), function(x){
    upperind <- x
    fsub <- f
    notnullind <- ((fsub$freqindex >= lowerind
                    & fsub$freqindex < upperind)
                    (fsub$freqindex >  (lindex - upperind + 2)
                     & fsub$freqindex <= (lindex - lowerind + 2)))
    fsub[!notnullind,"coef"] <- 0
    lowerind <<- upperind
    Re(fft(fsub$coef, inverse=TRUE)/length(fsub$coef))

My question is, why this condition:

 (fsub$freqindex >  (lindex - upperind + 2)
                         & fsub$freqindex <= (lindex - lowerind + 2))

This is basically saying to include (for computation of inverse FFT) those frequencies that are within the narrow range of the top frequency minus upper band frequency +2 and top frequency minus lower band frequency + 2. So basically just some tale at the top of the frequency. This doesn't make any sense to me. Can someone tell me where I should read up on this or what an intuitive hand-wavey sort of justification is?

  • $\begingroup$ OMG there is a signal processing SE now? $\endgroup$
    – Sean Owen
    Apr 9, 2015 at 1:00

1 Answer 1


Without knowing what values are being passed in, I will assume the +2 is an adjustment for R using 1 based indices. The band in the upper half of the frequency data represent complex frequencies symmetric about the fft length/2. The motivation is using a property of the DFT that will result in a real value output from the ifft: http://en.wikipedia.org/wiki/Discrete_Fourier_transform#The_real-input_DFT


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.