Skip to content
Prev 317017 / 398506 Next

low pass filter analysis in R

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