Learn R Programming

gsignal (version 0.3-1)

filtfilt: Zero-phase digital filtering

Description

Forward and reverse filter the signal.

Usage

filtfilt(filt, ...)

# S3 method for default filtfilt(filt, a, x, ...)

# S3 method for Arma filtfilt(filt, x, ...)

# S3 method for Ma filtfilt(filt, x, ...)

# S3 method for Sos filtfilt(filt, x, ...)

# S3 method for Zpg filtfilt(filt, x, ...)

Arguments

filt

For the default case, the moving-average coefficients of an ARMA filter (normally called <U+2018>b<U+2019>). 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.

Value

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<U+2019>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. Gustafsson's [1] method is then used to specify the initial conditions used to further handle the edges of the signal.

References

[1] Gustafsson, F. (1996). Determining the initial states in forward-backward filtering. IEEE Transactions on Signal Processing, 44(4), 988 - 992.

See Also

filter, filter_zi, Arma, Sos, Zpg

Examples

Run this code
# NOT RUN {
bf <- butter(3, 0.1)                                 # 10 Hz low-pass filter
t <- seq(0, 1, len = 100)                            # 1 second sample
x <- sin(2* pi * t * 2.3) + 0.25 * rnorm(length(t))  # 2.3 Hz sinusoid+noise
z <- filter(bf, x)                                   # apply filter
plot(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"))

# }

Run the code above in your browser using DataLab