wconv: 1-D or 2-D convolution

View source: R/wconv.R

wconvR Documentation

1-D or 2-D convolution

Description

Compute the one- or two-dimensional convolution of two vectors or matrices.

Usage

wconv(
  type = c("1d", "2d", "row", "column"),
  a,
  b,
  shape = c("full", "same", "valid")
)

Arguments

type

Numeric or character, specifies the type of convolution to perform:

"1d"

For a and b as (coerced to) vectors, perform 1-D convolution of a and b;

"2d

For a and b as (coerced to) matrices, perform 2-D convolution of a and b;

"row"

For a as (coerced to) a matrix, and b (coerced to) a vector, perform the 1-D convolution of the rows of a and b;

"column"

For a as (coerced to) a matrix, and b (coerced to) a vector, perform the 1-D convolution of the colums of a and b;

a, b

Input vectors or matrices, coerced to numeric.

shape

Subsection of convolution, partially matched to:

"full"

Return the full convolution (default)

"same"

Return the central part of the convolution with the same size as A. The central part of the convolution begins at the indices floor(c(nrow(b), ncol(b)) / 2 + 1)

"valid"

Return only the parts which do not include zero-padded edges. The size of the result is max(c(nrow(a), ncol(b)) - c(nrow(b), ncol(b)) + 1, 0)

Value

Convolution of input matrices, returned as a matrix or a vector.

Author(s)

Lukas Reichlin, lukas.reichlin@gmail.com.
Conversion to R by Geert van Boxtel, G.J.M.vanBoxtel@gmail.com.

See Also

conv

Examples

a <- matrix(1:16, 4, 4)
b <- matrix(1:9, 3,3)
w <- wconv('2', a, b)
w <- wconv('1', a, b, 'same')
w <- wconv('r', a, b)
w <- wconv('r', a, c(0,1), 'same')
w <- wconv('c', a, c(0,1), 'valid')


gsignal documentation built on Sept. 12, 2024, 6:27 a.m.