Learn R Programming

signal (version 1.8-0)

filter: Filter a signal

Description

Generic filtering function. The default is to filter with an ARMA filter of given coefficients. The default filtering operation follows Matlab/Octave conventions.

Usage

# S3 method for default
filter(filt, a, x, init, init.x, init.y, ...)

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

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

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

Value

The filtered signal, normally of the same length of the input signal 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.

a

the autoregressive (recursive) coefficients of an ARMA filter.

x

the input signal to be filtered.

init, init.x, init.y

init, init.x, init.y

allows to supply initial data for the filter - this allows to filter very large timeseries in pieces.

...

additional arguments (ignored).

Author

Tom Short, EPRI Solutions, Inc., (tshort@eprisolutions.com)

Details

The default filter is an ARMA filter defined as:

$$a_1y_n + a_2y_{n-1} + \dots + a_ny_1 = b_1x_n + b_2x_{m-1} + \dots + b_mx_1$$

The default filter calls stats:::filter, so it returns a time-series object.

Since filter is generic, it can be extended to call other filter types.

References

https://en.wikipedia.org/wiki/Digital_filter

Octave Forge https://octave.sourceforge.io/

See Also

filter in the stats package, Arma, fftfilt, filtfilt, and runmed.

Examples

Run this code
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")

Run the code above in your browser using DataLab