To my understanding, multiplying a signal in the frequency-domain is equal to a convolution in the time-domain.
I wrote a small python program, but i always end up with a shift in the time domain. where does this come from? An hints how to get the correct convolution, where the convolved output signal is in place corresponding to the input signals?
import numpy as np
from matplotlib import pyplot as plt
# make simple rectangular signals
r1 = np.zeros(100, dtype=float)
r2 = np.zeros(100, dtype=float)
r1[1:20] = 1.
r2[20:40] = 1.
# fftransform the signals
fft_r1 = np.fft.rfft(r1)
fft_r2 = np.fft.rfft(r2)
# multiply the frequence-spectra of the signals
fft_p = np.multiply(fft_r1, fft_r2)
# ifftransform back to time-domain
conv = np.fft.irfft(fft_p)
f, axarr = plt.subplots(3, 3)
f.tight_layout()
axarr[0, 0].plot(r1)
axarr[0, 0].set_title("r1")
axarr[0, 1].plot(np.abs(fft_r1), '.')
axarr[0, 1].set_title("fft_r1")
axarr[1, 0].plot(r2)
axarr[1, 0].set_title("r2")
axarr[1, 1].plot(np.abs(fft_r2), '.')
axarr[1, 1].set_title("fft_r2")
axarr[2, 0].plot(np.abs(fft_p), '.')
axarr[2, 0].set_title("fft product")
axarr[2, 1].plot(conv)
axarr[2, 1].set_title("conv (ifft of fft_product)")
axarr[2, 2].plot(np.convolve(r1, r2, 'same'))
axarr[2, 2].set_title("conv, np")
Here is an image of the plots that the above code generates: