| cconv {gsignal} | R Documentation |
Circular convolution
Description
Compute the modulo-n circular convolution.
Usage
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:
|
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.
Value
Circular convolution of input vectors, returned as a vector.
Author(s)
Leonardo Araujo.
Conversion to R by Geert van Boxtel,
G.J.M.vanBoxtel@gmail.com.
See Also
Examples
a <- c(1, 2, -1, 1)
b <- c(1, 1, 2, 1, 2, 2, 1, 1)
c <- cconv(a, b) # Circular convolution
cref = conv(a, b) # Linear convolution
all.equal(max(c - cref), 0)
cconv(a, b, 6)