[R] bandpass filters in R

Bill Simpson wsi at gcal.ac.uk
Wed Feb 14 11:33:46 CET 2001

> does anybody have any ideas regarding the easiest and most efficient way
> of implementing a bandpass filter in R ?
> any help would be truly appreciated.

Here is an example using lowpass filter.
 h<-dnorm(c(1:100), mean=50, sd=10)  #this is your lowpass filter 
 y<-ifelse(x<=250, 0, 1)
 plot(convolve(y,h, type="open")[101:500],type='l')   #100= filter length
abline(v=250-50)   # location of original step in the output

NOTE: if your filter is not symmetrical you need:
 plot(convolve(y,rev(h), type="open")[101:500],type='l')

You can consult some books to find a good bandpass filter. One simple idea
is to use a Gabor function, which is a Gaussian multiplied by a sinewave.
By varying the sd of the Gaussian you vary the bandwidth. The filter is
centred on whatever freq you use in your sinewave.
h<-dnorm((1:100), mean=50, sd=10)*cos(2*pi*5*(1:100)/100)
(In freq domain this filter is a Gaussian centred on freq)


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list