lp: First-order low-pass filtering

View source: R/lp.R

lpR Documentation

First-order low-pass filtering

Description

First-order low-pass filtering of time series.

Usage

lp(X, a1, usestate = TRUE)

Arguments

X

Dataframe or matrix (or list of them) of forecasts in columns to be low-pass filtered.

a1

The low-pass filter coefficient.

usestate

logical: Use the state kept in the model$input? if lp() is used outside model$transform_data(), then it must be set to FALSE, otherwise the input$state (which is not there) will be read leading to an error.

Details

This function applies a first order unity gain low-pass filter to the columns of X. The low-pass filter is applied to each column seperately. The stationary gain of the filter i one.

If a list of dataframes (or matrices) is given, then the low-pass filtering is recursively applied on each.

Value

The low-pass filtered dataframe (as a matrix)

Examples

# Make a dataframe for the examples
X <- data.frame(k1=rep(c(0,1),each=5))
X$k2 <- X$k1
Xf <- lp(X, 0.5, usestate=FALSE)
Xf

# See the input and the low-pass filtered result
plot(X$k1)
lines(Xf[ ,"k1"])
# Slower response with higher a1 value
lines(lp(X, 0.8, usestate=FALSE)[ ,"k1"])

# If a list of dataframes is given, then lp() is recursively applied on each
lp(list(X,X), 0.5, usestate=FALSE)



onlineforecast documentation built on Oct. 12, 2023, 5:15 p.m.