filtfilt(filt,...)## Default S3 method:filtfilt(filt, a, x,...)## S3 method for class 'Arma'filtfilt(filt, x,...)## S3 method for class 'Ma'filtfilt(filt, x,...)## S3 method for class 'Sos'filtfilt(filt, x,...)## S3 method for class 'Zpg'filtfilt(filt, x,...)
Arguments
filt: For the default case, the moving-average coefficients of an ARMA filter (normally called b). Generically, filt specifies an arbitrary filter operation.
...: additional arguments (ignored).
a: the autoregressive (recursive) coefficients of an ARMA filter, specified as a vector. If a[1] is not equal to 1, then filter normalizes the filter coefficients by a[1]. Therefore, a[1]
must be nonzero.
x: the input signal to be filtered. If x is a matrix, all colums are filtered.
Returns
The filtered signal, normally of the same length of the input signal x, returned as a vector or matrix.
Details
Forward and reverse filtering the signal corrects for phase distortion introduced by a one-pass filter, though it does square the magnitude response in the process. That’s the theory at least. In practice the phase correction is not perfect, and magnitude response is distorted, particularly in the stop band.
Before filtering the input signal is extended with a reflected part of both ends of the signal. The length of this extension is 3 times the filter order. The Gustafsson [1] method is then used to specify the initial conditions used to further handle the edges of the signal.
Examples
bf <- butter(3,0.1)# 10 Hz low-pass filtert <- seq(0,1, len =100)# 1 second samplex <- sin(2* pi * t *2.3)+0.25* rnorm(length(t))# 2.3 Hz sinusoid+noisez <- filter(bf, x)# apply filterplot(t, x, type ="l")lines(t, z, col ="red")zz <- filtfilt(bf, x)lines(t, zz, col="blue")legend("bottomleft", legend = c("original","filter","filtfilt"), lty =1, col = c("black","red","blue"))
References
[1] Gustafsson, F. (1996). Determining the initial states in forward-backward filtering. IEEE Transactions on Signal Processing, 44(4), 988 - 992.