# Why idft(dft(a) * dft(b)) not equal to convolve(a, b)?

I'm a little confused... I always thought the DFT of a convolution was equal to a product of DFTs, but when I tried this in Python:

from scipy import *

a = [1+0j, 2+0j]
b = [4+0j, 5+0j]

print list(ifft(fft(a) * fft(b)))
print list(convolve(a, b))


I got back:

[(14+0j), (13+0j)]
[(4+0j), (13+0j), (10+0j)]


Why are they not the same thing?

• You could just use fftconvolve Sep 24, 2012 at 16:35
• @endolith: That returns the same thing as convolve. Sep 24, 2012 at 17:26
• Isn't that what you want? You're trying to use FFTs to calculate the same output as convolve, which is exactly what fftconvolve does. Sep 24, 2012 at 17:28
• possible duplicate of Efficiently calculating autocorrelation using FFTs Sep 24, 2012 at 17:29
• @endolith: I'm not asking how to calculate anything; did you read the question? Sep 25, 2012 at 8:14

ifft(fft(a) * fft(b)) performs a cyclic convolution, convolve apparently zero-pads the inputs. If you pad both arrays with zeros, the result should be the same:
a = [0,0,0,1+0j, 2+0j,0,0,0]