# Implementing a bandpass filter in R - this code's logic confuses me

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?

• OMG there is a signal processing SE now? – Sean Owen Apr 9 '15 at 1:00