

_F_a_s_t _C_o_n_v_o_l_u_t_i_o_n

     convolve(x, y, conj = TRUE, type = c("circular", "open", "filter"))

_A_r_g_u_m_e_n_t_s:

     x,y: numeric sequences of the same length to be con-
          volved.

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

    type: character; one of `"circular"', `"open"',
          `"filter"' (beginning of word is ok).  For `circu-
          lar', the two sequences are treated as circular,
          i.e., periodic.

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

_D_e_s_c_r_i_p_t_i_o_n:

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

_D_e_t_a_i_l_s:

     The Fast Fourier Transform, `fft', is used for effi-
     ciency.

     The input sequences `x' and  `y' must have the same
     length if `circular = TRUE').

_V_a_l_u_e:

     If `r <- convolve(x,y, conj=TRUE, type)' and `n <-
     length(x)', then

              r[k] = sum(i=1,..,n;  x[i] * y[k-i])

     for k = 1,...,n.

     If `type == "circular"', then y[j] == y[n+j] for j < 0.

_R_e_f_e_r_e_n_c_e_s:

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

_S_e_e _A_l_s_o:

     `fft', `nextn'.

_E_x_a_m_p_l_e_s:

     x <- c(0,0,0,100,0,0,0)
     y <- c(0,0,1, 2 ,1,0,0)/4
     zapsmall(convolve(x,y))         #  *NOT* what you first thought..
     zapsmall(convolve(x, y[3:5], type="f")) # rather
     x <- rnorm(50);y <- rnorm(50)
     all(convolve(x,y), convolve(y,x))
     all(convolve(x,y, conj = FALSE), rev(convolve(y,x)))

     n <- length(x <- -20:24)
     y <- (x-10)^2/1000 + rnorm(x)/8

     Han <- function(y) # Hanning
            convolve(y, c(1,2,1)/4, type = "filter")

     plot(x,y, main="Using  convolve(.) for Hanning filters")
     lines(x[-c(1  , n)      ], Han(y), col="red")
     lines(x[-c(1:2, (n-1):n)], Han(Han(y)), lwd=2, col="dark blue")

