convolve

0th

Percentile

Convolution of Sequences via FFT

Use the Fast Fourier Transform to compute the several kinds of convolutions of two sequences.

Keywords
math, dplot
Usage
convolve(x, y, conj = TRUE, type = c("circular", "open", "filter"))
Arguments
x, y

numeric sequences of the same length to be convolved.

conj

logical; if TRUE, take the complex conjugate before back-transforming (default, and used for usual convolution).

type

character; partially matched to "circular", "open", "filter". For "circular", the two sequences are treated as circular, i.e., periodic.

For "open" and "filter", the sequences are padded with 0s (from left and right) first; "filter" returns the middle sub-vector of "open", namely, the result of running a weighted mean of x with weights y.

Details

The Fast Fourier Transform, fft, is used for efficiency.

The input sequences x and y must have the same length if circular is true.

Note that the usual definition of convolution of two sequences x and y is given by convolve(x, rev(y), type = "o").

Value

If r <- convolve(x, y, type = "open") and n <- length(x), m <- length(y), then $$r_k = \sum_{i} x_{k-m+i} y_{i}$$ where the sum is over all valid indices $i$, for $k = 1, \dots, n+m-1$.

If type == "circular", $n = m$ is required, and the above is true for $i , k = 1,\dots,n$ when $x_{j} := x_{n+j}$ for $j < 1$.

References

Brillinger, D. R. (1981) Time Series: Data Analysis and Theory, Second Edition. San Francisco: Holden-Day.