convolve_at | R Documentation |
Convolve a signal with weights at arbitrary indices.
convolve_at(x, index, weights, margin = NULL, na.rm = FALSE)
x |
A numeric vector or matrix. |
index |
A list or matrix of numeric vectors giving the indices to convolve. If |
weights |
A list giving the weights of the kernels to convolve for each element of |
margin |
If |
na.rm |
Should missing values (including |
This is essentially just a weighted sum defined by x[i] = sum(weights[[i]] * x[index[[i]]])
.
A numeric vector the same length as x
with the smoothed result.
Kylie A. Bemis
set.seed(1)
t <- seq(from=0, to=6 * pi, length.out=5000)
y <- sin(t) + 0.6 * sin(2.6 * t)
x <- y + runif(length(y))
i <- roll(seq_along(x), width=15)
wt <- dnorm((-7):7, sd=7/2)
wt <- wt / sum(wt)
xs <- convolve_at(x, i, wt)
plot(x, type="l")
lines(xs, col="red")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.