cconv function

Circular convolution

Circular convolution

Compute the modulo-n circular convolution.

cconv(a, b, n = length(a) + length(b) - 1)

Arguments

  • a, b: Input, coerced to vectors, can be different lengths or data types.
  • n: Convolution length, specified as a positive integer. Default: length(a) + length(b) - 1.

Returns

Circular convolution of input vectors, returned as a vector.

Details

Linear and circular convolution are fundamentally different operations. Linear convolution of an n-point vector x, and an l-point vector y, has length n + l - 1, and can be computed by the function conv, which uses filter. The circular convolution, by contrast, is equal to the inverse discrete Fourier transform (DFT) of the product of the vectors' DFTs.

For the circular convolution of x and y to be equivalent to their linear convolution, the vectors must be padded with zeros to length at least n + l - 1 before taking the DFT. After inverting the product of the DFTs, only the first n + l - 1 elements should be retained.

For long sequences circular convolution may be more efficient than linear convolution. You can also use cconv to compute the circular cross-correlation of two sequences.

Examples

a <- c(1, 2, -1, 1) b <- c(1, 1, 2, 1, 2, 2, 1, 1) c <- cconv(a, b) cref = conv(a, b) # Linear convolution all.equal(max(c - cref), 0) cconv(a, b, 6)

See Also

conv, convolve

Author(s)

Leonardo Araujo.

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

  • Maintainer: Geert van Boxtel
  • License: GPL-3
  • Last published: 2024-09-11