# Why convolution in time and frequency domain are not equal?

I was writing this Jupyter Notebook. Then, I unexpectedly faced two visually similar output, but their numerical results were very different.

This is the code I used for convolution in the time domain:

filtered_k1 = sp.signal.convolve2d(img, k1, mode='same')
filtered_k2 = sp.signal.convolve2d(img, k2, mode='same')

def FT(x):
return np.fft.fft2(x)

def iFT(x):
return np.fft.ifft2(x)

x_h, x_w = x.shape
k_h, k_w = k.shape
padding = [[0, x_h - k_h], [0, x_w - k_w]]

K1_BIG = FT(k1_big)
K2_BIG = FT(k2_big)

filtered_K1 = np.real(iFT(IMG * K1_BIG))
filtered_K2 = np.real(iFT(IMG * K2_BIG))

diff1 = filtered_K1 - filtered_k1
diff2 = filtered_K2 - filtered_k2


The RSS on diff1 and diff2 was not residual numerical error, as I expected.

• The convolution using the fft results in a circular convolution; is that what is causing your difference in the results? – Dan Boschen Jan 4 '19 at 14:14
• I am not sure. If this is the case, I would like to know how to set up sp.signal.convolve2d to yield the same output – Eduardo Reis Jan 4 '19 at 18:13