convolve_at: Convolution at Arbitrary Indices

View source: R/signal.R

convolve_atR Documentation

Convolution at Arbitrary Indices

Description

Convolve a signal with weights at arbitrary indices.

Usage

convolve_at(x, index, weights, ...)

Arguments

x

A numeric vector.

index

A list of numeric vectors giving the indices to convolve. Must be as long as x. Lengths must match weights.

weights

A list giving the weights of the kernels to convolve for each element of x. Lengths must match index.

...

Additional arguments passed to sum(). (E.g, na.rm.)

Details

This is essentially just a weighted sum defined by x[i] = sum(weights[[i]] * x[index[[i]]]).

Value

A numeric vector the same length as x with the smoothed result.

Author(s)

Kylie A. Bemis

Examples

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")

kuwisdelu/matter documentation built on May 1, 2024, 5:17 a.m.