filtfilt: Zero-phase digital filtering

View source: R/filtfilt.R

filtfiltR Documentation

Zero-phase digital filtering

Description

Forward and reverse filter the signal.

Usage

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.

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.

Value

The filtered signal, normally of the same length of the input signal x, returned as a vector or matrix.

Author(s)

Paul Kienzle, pkienzle@users.sf.net,
Francesco Potortì, pot@gnu.org,
Luca Citi, lciti@essex.ac.uk.
Conversion to R and adapted by Geert van Boxtel G.J.M.vanBoxtel@gmail.com.

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

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"))


gsignal documentation built on Sept. 12, 2024, 6:27 a.m.