Bug 408 - convolution bug
Summary: convolution bug
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: old
Hardware: All Linux
: P5 normal
Assignee: Jitterbug compatibility account
URL:
Depends on:
Blocks:
 
Reported: 2000-01-28 16:17 UTC by Jitterbug compatibility account
Modified: 2012-03-24 16:22 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jitterbug compatibility account 2000-01-28 16:17:36 UTC
From: wsimpson@gcal.ac.uk
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().
Comment 1 Jitterbug compatibility account 2004-08-12 04:40:00 UTC
NOTES:
 Is this a bug?
Comment 2 Jitterbug compatibility account 2004-08-12 06:36:19 UTC
Audit (from Jitterbug):
Wed Feb 16 19:28:42 2000	ripley	moved from incoming to Language
Thu Aug 12 01:36:19 2004	thomas	changed notes