# [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.
x<-seq(1,500)
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
points(pnorm(c(1:400),mean=250-50,sd=10))

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)
^
freq
(In freq domain this filter is a Gaussian centred on freq)

Bill

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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