How do I run a high pass or low pass filter on data points in R?
Per request of OP:
The signal package contains all kinds of filters for signal processing. Most of it is comparable to / compatible with the signal processing functions in Matlab/Octave.
Using lanczos low pass filter in R program
Using the web I find this MATLAB implementation.
If you skipped the first part(arguments check), it looks simple to write its R equivalent.
# Cf - Cut-off frequency (default: half Nyquist)
# M - Number of coefficients (default: 100)
lanczos_filter_coef <- function(Cf,M=100){
lowpass_cosine_filter_coef <- function(Cf,M)
coef <- Cf*c(1,sin(pi*seq(M)*Cf)/(pi*seq(M)*Cf))
hkcs <- lowpass_cosine_filter_coef(Cf,M)
sigma <- c(1,sin(pi*seq(M)/M)/(pi*seq(M)/M))
hkB <- hkcs*sigma
hkA <- -hkB
hkA[1] <- hkA[1]+1
coef <- cbind(hkB, hkA)
coef
}
To test it for example:
dT <- 1
Nf <- 1/(2*dT)
Cf <- Nf/2
Cf <- Cf/Nf
lanczos_filter_coef(Cf,5)
hkB hkA
[1,] 5.000000e-01 5.000000e-01
[2,] 2.977755e-01 -2.977755e-01
[3,] 1.475072e-17 -1.475072e-17
[4,] -5.353454e-02 5.353454e-02
[5,] -4.558222e-18 4.558222e-18
[6,] 2.481571e-18 -2.481571e-18
PS I don't know very well MATLAB(used it many years ago), so I I used this link For the R/MATLAB analogy. I hope that someone with more R/MATLAB/Scilab knowledge can test my code.
Related Topics
How to Keep My Subtitles When I Use Ggplotly()
Control Alpha Blending/Opacity of N Overlapping Areas
How to 'Compress' an Lm() Object for Later Prediction
How to Remove Columns from a Data.Frame by Data Type
Histogram Conditional Fill Color
Parsing Iso8601 Date and Time Format in R
How to Minimize Size of Object of Class "Lm" Without Compromising It Being Passed to Predict()
Update Plot Within Observer Loop in Shiny Application
Knitr: Opts_Chunk$Set() Not Working in Rscript Command
What Are the Ways to Create an Executable from R Program
Replacing Negative Values in a Model (System of Odes) with Zero
Create Columns from Column of List in Data.Table
How to Pass Column Name as Argument to Function for Dplyr Verbs
How to Clear an Na Flag for a Posix Value