[R] low pass filter analysis in R
bretschr at xs4all.nl
Thu Feb 7 12:04:50 CET 2013
Dear Janesh Devkota,
> Hello R users,
> I am trying to use R to do the low pass filter analysis for the tidal data.
> I am a novice in R and so far been doing only simple stuffs on R. I found a
> package called signal but couldn't find the proper tutorial for the low
> pass filter.
> Could anyone point me to the proper tutorial or starting point on how to do
> low pass filter analysis in R ?
> Thank you so much.
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')
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.
3584 CH Utrecht
More information about the R-help