windowSmooth: Fast Computation of Moving Window Average

Description Usage Arguments Details Value Examples

View source: R/windowSmooth.R

Description

Compute moving window average of a time-series x.

Usage

1
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## 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")

oslerinhealth/adept documentation built on Oct. 10, 2019, 4:57 a.m.