[R] convolve bug?
yudi@ucd.ie
yudi at ucd.ie
Thu Nov 18 16:57:11 CET 1999
> Date: Thu, 18 Nov 1999 13:41:53 +0000 (GMT)
> From: Bill Simpson <wsi at gcal.ac.uk>
> 1. First example, from the classic Bracewell The Fourier transform and its
> applications, chap 3 (p.32 in 2nd edition):
> {2 2 3 3 4} * {1 1 2} = {2 4 9 10 13 10 8}
> where * denotes convolution (discrete in this case). See bottom of this
> email for his definition of convolution.
> In R I get:
> x<-c(2,2,3,3,4)
> h<-c(1,1,2)
> convolve(x,h,type="o")
> [1] 4 6 10 11 14 7 4
> I think "open" is the right type. I want to get length(x)+length(h)-1
> terms in the convolution output, which is what "open" gives. I definitely
> don't want "circular"
Note this one:
x<-c(2,2,3,3,4)
h<-c(2,1,1) # reverse the filter
convolve(x,h,type="o")
[1] 2 4 9 10 13 10 8 # matches Bracewell
> Is there something wrong with convolve(), or is it just me?
The filter in R is not reversed, which is fine as long as it is
understood so, but the help is not consistent:
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'.
This implies y is not reversed, but the definition
r[k] = sum(i=1,..,n; x[i] * y[k-i])
reverses y, which is not the way it is implemented.
-Yudi-
------------------------------
Yudi Pawitan: yudi at stat.ucc.ie
Department of Statistics, UCC
Cork, Ireland
Ph : 353-21-902 906
Fax: 353-21-271 040
------------------------------
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list