Re: [R] low pass filter analysis in R
Dear Janesh, Re: Dear Franklin Bretschneider, Thank you so much for your reply and explanation about the filter using the stats and signal package. I decided to opt the filter method in signal package. I have a simple question about the cut off frequency here. I have 30 minute collected tidal data and I want to use the 48 hour low pass filter to my data to remove the fluctuations and then get only the residuals. What should be the cutoff frequency in my case ? I have tried to figure out cut off frequency with the following rationale : . The parameters for butter filter are n, Wn and type. In the help, Wis defined as critical frequencies of the filter. W must be a scalar for low-pass and high-pass filters, and W must be a two-element vector c(low, high) specifying the lower and upper bands. For digital filters, W must be between 0 and 1 where 1 is the Nyquist frequency. A value of 1 corresponds to half the sampling frequency. In my case the sampling frequency is 2 hr^-1. Hence a value of 0.01 corresponds to a frequency cutoff of .01*1 = .01 hr^-1 or 100 hrs time. Using unitary method, if 100 hours cut off frequency is 0.01 then 48 hours cut off frequency is 0.01/100*48 = 0.0048 hr^-1 . Is that correct ? Thank you so much Janesh With digital filters (called z-plane in the signal package), the cut-off frequency must indeed be given as a fraction of the Nyquist freqency. With your tidal data, taken at 2 samples per hour, the nyquist is 1 per hour. So, a cutoff interval of 48 h means a cutoff frequncy of 1/48 f(nyq) , or 0.020833. This must be fed into the butterworth function. Note btw that at the cut-off frequency, the amplitude is still rather high (about 0.707), so the tidal signal (period about 12.5 h) will not be attenuated much. I hope this helps. It's always best to check with a simple example, such as an f= 1/48 sine, which after your filter should be reduced to an amplitude of 0.707). Then check with a simulated tidal signal (say, a sine of about 12:25 h period). With such simple tests, I often find my own programming errors. Best wishes, Franklin -- Franklin Bretschneider -- Dept Biology Kruyt Building W711 Padualaan 8 3584 CH Utrecht The Netherlands [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] low pass filter analysis in R
Dear Janesh Devkota, Re: 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. Janesh 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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] low pass filter analysis in R
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 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] low pass filter analysis in R
Janesh, This might help get you started: http://biostatmatt.com/archives/78 (apologies for linking to my own blog) Regards, Matt -- Message: 51 Date: Wed, 6 Feb 2013 18:50:43 -0600 From: Janesh Devkota janesh.devk...@gmail.com To: r-help@r-project.org Subject: [R] low pass filter analysis in R Message-ID: CAPTbr1rrSmUgmjjKL54u2KZzzEAFLUXALCuH=wofrbttaky...@mail.gmail.com Content-Type: text/plain 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. Janesh [[alternative HTML version deleted]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] low pass filter analysis in R
Dear Franklin Bretschneider, Thank you so much for your reply and explanation about the filter using the stats and signal package. I decided to opt the filter method in signal package. I have a simple question about the cut off frequency here. I have 30 minute collected tidal data and I want to use the 48 hour low pass filter to my data to remove the fluctuations and then get only the residuals. What should be the cutoff frequency in my case ? I have tried to figure out cut off frequency with the following rationale : . The parameters for butter filter are n, Wn and type. In the help, W is defined as critical frequencies of the filter. W must be a scalar for low-pass and high-pass filters, and W must be a two-element vector c(low, high) specifying the lower and upper bands. For digital filters, W must be between 0 and 1 where 1 is the Nyquist frequency. A value of 1 corresponds to half the sampling frequency. In my case the sampling frequency is 2 hr^-1. Hence a value of 0.01 corresponds to a frequency cutoff of .01*1 = .01 hr^-1 or 100 hrs time. Using unitary method, if 100 hours cut off frequency is 0.01 then 48 hours cut off frequency is 0.01/100*48 = 0.0048 hr^-1 . Is that correct ? Thank you so much Janesh On Thu, Feb 7, 2013 at 6:07 AM, Bretschneider SIG-R brets...@xs4all.nlwrote: 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 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] low pass filter analysis in R
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. Janesh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] low pass filter analysis in R
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 : 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. Janesh [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.