convolution bug (PR#408)
wsimpson@gcal.ac.uk
wsimpson@gcal.ac.uk
Fri, 28 Jan 2000 11:17:37 +0100 (MET)
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._