windowSmooth {adept}R Documentation

Fast Computation of Moving Window Average

Description

Compute moving window average of a time-series x.

Usage

windowSmooth(x, W, x.fs = 1)

Arguments

x

A numeric vector. A time-series for which a moving window average is computed.

W

A numeric scalar. A length of a moving window, expressed in time (seconds).

x.fs

Frequency of a time-series x, expressed in a number of observations per second. Defaults to 1.

Details

Time-series frequency x.fs and a length of a moving window (expressed in time) W together determine W.vl = round(W * x.fs), a length of a moving window expressed in a length of x vector object. Note: W.vl must be equal or greater than 3.

Value

A numeric vector. Moving window average of a time-series x. Note: head and tail of the output vector where the moving window is undefined are filled with NA.

Examples

## Time-series defined as a function f(x) = x
N <- 100
W  <- 20
x <- 1:N
x.smoothed <- windowSmooth(x, W)
plot(x, type = "l")
points(x.smoothed, col = "red")

## Time-series defined as a function f(x) = sin(x) + noise
N <-  1000
W  <- 100
x <- sin(seq(0, 4 * pi, length.out = N)) + rnorm(N, sd = 0.1)
x.smoothed <- windowSmooth(x, W)
plot(x, type = "l")
points(x.smoothed, col = "red")


[Package adept version 1.2 Index]