Skip to content

low pass filter analysis in R

6 messages · Janesh Devkota, Pascal Oettli, Franklin Bretschneider

#
Hello,

If you know what a lowpass filter is, you should be able to use "filter" 
from "stats" package.

And you can have a look at:

?triang

HTH,
Pascal


Le 07/02/2013 09:50, Janesh Devkota a ?crit :
#
Dear Janesh Devkota,


Re:
Indeed, filters are in both the "stats" and the "signal" packages.
The simplest is to define a "running average" smoothing, e.g.

if your data is called "y":

yfiltered = stats:::filter(y, c(1,1,1,1,1,1,1)/7)

So, smooth the data by the filter c(1,1,1,1,1,1,1)/7
Note that the first 3 and last 3 data points are lost.
The longer the filter, the more data at the start and the end of your data will be lost.


The "signal" package allows more sphisticated forms of filter.
In addition, it contains functions to compute filter types well-known in signal analysis, such as butterworth and chebysheff filters.

A second-order butterworth filter with a cutoff at 0.1 x the sampling frequency:

myfilter = butter(2, 0.1, type = 'low', plane='z')  

Apply this:

yfiltered = signal:::filter(y, x) # apply filter

Note that loading the "signal" package may mask the filter from "stats".
Hence the call with the ::: in it.

Succes.

Best wishes,



Franklin Bretschneider
--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands
#
Dear Janesh Devkota,



Sorry, I forgot an edit.
The last command should read:

yfiltered = signal:::filter(myfilter, y) # apply filter

Best wishes,



Franklin Bretschneider


--
Dept Biologie
Kruytgebouw W711
Padualaan 8
3584 CH Utrecht
The Netherlands