The R Project SVN R

Rev

Rev 69587 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 69587 Rev 69588
Line 12... Line 12...
12
}
12
}
13
\usage{
13
\usage{
14
convolve(x, y, conj = TRUE, type = c("circular", "open", "filter"))
14
convolve(x, y, conj = TRUE, type = c("circular", "open", "filter"))
15
}
15
}
16
\arguments{
16
\arguments{
17
  \item{x, y}{numeric sequences to be convolved, \emph{of the same
17
  \item{x, y}{numeric sequences \emph{of the same length} to be
18
      length} for \code{type = "circular"}, the default.  For \code{type
-
 
19
      = "filter"}, \code{y} must not be longer than \code{y} (and
-
 
20
    typically is much shorter).}
18
    convolved.}
21
  \item{conj}{logical; if \code{TRUE}, take the complex \emph{conjugate}
19
  \item{conj}{logical; if \code{TRUE}, take the complex \emph{conjugate}
22
    before back-transforming (default, and used for usual convolution).}
20
    before back-transforming (default, and used for usual convolution).}
23
  \item{type}{character; partially matched to \code{"circular"}, \code{"open"},
21
  \item{type}{character; partially matched to \code{"circular"}, \code{"open"},
24
    \code{"filter"}.  For \code{"circular"}, the
22
    \code{"filter"}.  For \code{"circular"}, the
25
    two sequences are treated as \emph{circular}, i.e., periodic.
23
    two sequences are treated as \emph{circular}, i.e., periodic.
Line 68... Line 66...
68
x <- rnorm(50)
66
x <- rnorm(50)
69
y <- rnorm(50)
67
y <- rnorm(50)
70
# Circular convolution *has* this symmetry:
68
# Circular convolution *has* this symmetry:
71
all.equal(convolve(x, y, conj = FALSE), rev(convolve(rev(y),x)))
69
all.equal(convolve(x, y, conj = FALSE), rev(convolve(rev(y),x)))
72
 
70
 
73
 
-
 
74
(ctypes <- eval(formals(convolve)$type)[-1]) # all but "circular"
-
 
75
for(n in 1:500) {%% <- FIXME ?  \dontshow{..} ??
-
 
76
 x <- rnorm(1+ rpois(1, 20))
-
 
77
 y <- rnorm(1+ rpois(1, sample(c(4,40), 1)))
-
 
78
 Lxy <- sapply(ctypes, function(T) convolve(x,y, type=T), simplify=FALSE)
-
 
79
 stopifnot(all.equal(Lxy$open,   Lxy$`1+open`,   tol=1e-14))
-
 
80
 stopifnot(all.equal(Lxy$filter, Lxy$`1+filter`, tol=1e-14))
-
 
81
}
-
 
82
 
-
 
83
n <- length(x <- -20:24)
71
n <- length(x <- -20:24)
84
y <- (x-10)^2/1000 + rnorm(x)/8
72
y <- (x-10)^2/1000 + rnorm(x)/8
85
 
73
 
86
Han <- function(y) # Hanning
74
Han <- function(y) # Hanning
87
       convolve(y, c(1,2,1)/4, type = "filter")
75
       convolve(y, c(1,2,1)/4, type = "filter")