Lag-free filter methods for time series I'm currently working with accelerometer based raw data (100 hz). Now I want to low pass filter this timeseries of accelerations for further analyses.
I tried different filters like the simple moving average (SMA) or the exponential moving average (EMA) filter. But both methods produce lag, which I want to avoid. Are there any lag-free filter methods available for my kind of data? I'm doing my analysis in R, so appropriate R packages are prefered.
 A: Filters like the Savitzky-Golay filter might just be what you are searching for. The core difference to classic runmean or runmed filters is that they fit itself to the signal in the running window, so don't produce the same lag as runmean or runmed would do (in case of this filter this is done using polynoms with convolution - so besides the window width, you have an additional filter order parameter to tune here). Here's a short example using a Savitzky-Golay filter in R with the signal package:
library(signal)
matplot(data.frame( beaver1[,3], 
                runmed(beaver1[,3], k = 11),
                filter(filt = sgolay(p = 5, n = 11), x = beaver1[,3])
                ), type='l', lwd=2, lty=1, ylab='')
legend('topleft', legend=c('original', 'runmed', 'Savitzky–Golay'), col=1:3, lty=1:3, lwd=2)

A: Another option is to run the filter once in the forward direction, then again in the reverse direction, which cancels the lag. The functions in Python and Matlab are both called filtfilt(). I'm not an R user, but there seems to be an R implementation here (also called filtfilt()). This could be useful if you want to design a filter with specific frequency response characteristics. Otherwise, smoothing methods (e.g. Savitzky Golay as geekoverdose mentioned, or LOESS, etc.) could be simpler.
