Learn R Programming

gsignal (version 0.3-1)

movingrms: Moving Root Mean Square

Description

Compute the moving root mean square (RMS) of the input signal.

Usage

movingrms(x, width = 0.1, rc = 0.001, fs = 1)

Arguments

x

Input signal, specified as a numeric vector or matrix. In case of a matrix, the function operates along the columns

width

width of the sigmoid window, in units relative to fs. Default: 0.1

rc

Rise time (time constant) of the sigmoid window, in units relative to fs. Default: 1e-3

fs

Sampling frequency. Default: 1

Value

A list containing 2 variables:

rmsx

Output signal with the same dimensions as x

w

Window, returned as a vector

Details

The signal is convoluted against a sigmoid window of width w and risetime rc. The units of these parameters are relative to the value of the sampling frequency given in fs.

See Also

sigmoid_train

Examples

Run this code
# NOT RUN {
N <- 128
t <- seq(0, 1, length.out = N)
x <- sigmoid_train(t, c(0.4, Inf), 1e-2)$y * (2 * runif(length(t)) - 1)
fs <- 1 / diff(t[1:2])
width <- 0.05
rc <- 5e-3
ret <- movingrms(as.numeric(scale(x)), width, rc, fs)
plot(t, x, type = "l", col = "red", xlab = "", ylab = "")
lines(t, ret$rmsx, lwd = 4, col = "black")
polygon(c(0, t, length(t)), c(0, ret$rmsx, 0), col = "blue")
lines (t, ret$w, lwd = 2, col = "green")
legend("topleft", c("data", "window", "movingrms"), lty = 1,
       col = c("red", "green", "blue"))

# }

Run the code above in your browser using DataLab