saei
saei

Reputation: 109

Why doesn't this R code produce the same result? (Convolution vs FFT)

Why doesn't this produce the same result?

x <- runif(10, 0, 1)
y <- runif(10, 0, 1)
convolve(x,y)

f <- fft(fft(x)*fft(y), inverse = TRUE)
f/length(f)  ##not the same as convolve(x,y)....

If this is not what the function convolve is doing, then what else?

Upvotes: 2

Views: 149

Answers (1)

dave-edison
dave-edison

Reputation: 3726

They're not equivalent because convolve has default argument conj = TRUE, and fft returns a vector of type complex. If we change these the results are indeed the same:

all.equal(Re(f) / length(f), convolve(x, y, conj = FALSE))
# TRUE

Upvotes: 3

Related Questions