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 or matrix of numeric vectors giving the indices to convolve. If index is a list, then it must have the same length as x and element lengths that match weights. If x is a matrix, then its rows must correspond to x and its columns must correspond to 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 July 16, 2024, 1:28 p.m.