From wsimpson@gcal.ac.uk  Fri Jan 28 10:17:37 2000
From: wsimpson@gcal.ac.uk (wsimpson@gcal.ac.uk)
Date: Fri, 28 Jan 2000 11:17:37 +0100 (MET)
Subject: convolution bug (PR#408)
Message-ID: <200001281017.LAA11335@pubhealth.ku.dk>

Full_Name: Bill Simpson
Version: 65.1 , 0.90.1
OS: Linux
Submission from: (NULL) (193.62.250.209)


I reported this on r-help, but here is official bug report.

The present convolve() does not do convolution by default. Its default behaviour
is
correlation. This is a bug.

The default argument conj should be set to FALSE.

The zero-padding should be on the right for linear convolution (don't ask me
why you call this type="open"; I suggest type="linear").

Here is what I expect linear convolution to do:
myconvolve<-function (x,h) 
{
    nx <- length(x)
    nh <- length(h)
    #zero pad
    if(nx>nh)
       {
       x <- c(x,rep(0, nh-1))
       h<-c(h,rep(0,nx-1))
       }
    else
       {
       h <- c(h,rep(0, nx-1))
       x<-c(x,rep(0,nh-1))
       }
    x <- fft(fft(x) * fft(h), inv = TRUE)
    Re(x)/length(x)
#I am not sure about this, the R IFFT is weird
}

What "circular" convolution should do is just
eliminate the zero-padding:

myconvolve2<-function (x,h)
{
#no padding, circular convolution
    nx <- length(x)
    nh <- length(h)
    x <- fft(fft(x) * fft(h), inv = TRUE)
    Re(x)/(nx)
}


I suggest that you create two functions, convolve() and correlate(), and get
rid
of the conj argument in convolve().

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


convolution bug (PR#408)
wsimpson@gcal.ac.uk