Skip to contents

Applies linear filtering to a univariate "timeSeries".

Usage

# S4 method for timeSeries
filter(x, filter, method = c("convolution", "recursive"), sides = 2, 
       circular = FALSE, init = NULL)

Arguments

x

an object from class "timeSeries".

filter

coefficients of the filter.

method

"convolution" or "recursive".

sides,circular

for convolution filters only. Onesided if sides = 1, centred around lag 0 if sides = 2. Circular if circular = TRUE.

init

for recursive filters only. Values before the start of the time series.

Details

filter is a generic function with default method stats::filter. The method for "timeSeries" is a wrapper for the latter.

See ?stats::filter for details about the arguments.

Value

a "timeSeries" object

See also

base R function filter

Examples

## Creata a dummy signal 'timeSeries' - 
   data <- matrix(rnorm(100), ncol = 2)
   s <- timeSeries(data, units=c("A", "B"))
   head(s)
#>  
#>               A           B
#> [1,]  0.9851607 -1.55567959
#> [2,]  0.5336291 -1.55848871
#> [3,] -1.3122055  0.34779055
#> [4,]  1.0059125  0.07760222
#> [5,] -0.4908190 -0.56542618
#> [6,]  0.1710881 -0.46686573
   
## Filter the series - 
   f <- filter(s, rep(1, 3))
   head(f)
#>  
#>                A          B
#> [1,]          NA         NA
#> [2,]  0.20658444 -2.7663777
#> [3,]  0.22733616 -1.1330959
#> [4,] -0.79711200 -0.1400334
#> [5,]  0.68618160 -0.9546897
#> [6,]  0.01657283 -0.5366053
   
## Plot and compare the first series - 
   plot(cbind(s[, 1], f[, 1]), plot.type="s")