[R] convolve bug?

Bill Simpson wsi at gcal.ac.uk
Thu Nov 18 14:41:53 CET 1999


I have been experimenting with convolve().

What I know about convolution I learned from engineering (they call this
stuff linear systems theory), not statistics, so maybe this is all just a
matter of different conventions. BUT I notice very weird things with
convolve().

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"

BTW, the help for convolve says:

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.

There seems to be a typo: shouldn't it be
r <- convolve(x,y, conj=TRUE, type="open") or "filter" or whatever

2.
x<-seq(1,100)
y<-ifelse(x<=50, 0, 1)
#y is a discrete unit step or Heaviside function

h<-dnorm(x, mean=50, sd=10)
# the filter is a Gaussian

plot(convolve(y,h, type="open"))
#weird
points(pnorm(x,mean=50,sd=10))
#what I expected, since convolution with a step is integration


The definition of convolution used by Bracewell (p. 32) is
out[i-1] = Sum f[j] g[i-j] 
            j
where out[] is the convolution (he calls it serial product here).
This definition seems essentially the same as the one in the R help.

Is there something wrong with convolve(), or is it just me?

Thanks very much for any help.

Bill

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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