# Inverse Fourier transform in Python not yielding the original signal

I am trying to do a Fourier Transform and Inverse Fourier Transform. The problem is that I am not getting the original signal after inverse transform. # set signal and transform constants
samples = 10000
t = np.arange(samples)
cf = 1000 # carrier frequency Hz
mf = 60 # modulation frequency Hz
# signal is a classic AM waveform
signal = lambda t: np.sin(2 * np.pi * cf * t / samples) \
* (1+(np.sin(2 * np.pi * mf * t / samples)))

fi = np.arange(5000)
fs = np.fft.fft(signal(t))[:5000]
sp2.plot(fi ,abs(fs) * 2 / samples, color = "#fb8072")

samples = 10000
t = np.arange(samples)
# declare an all-zeros frequency spectrum
s = np.zeros((samples,), dtype=complex)
# set the spectral lines
s = 0.5
s = 1.0
s = 0.5

fs = np.fft.ifft(s)[:512]
sp2.plot(fi, fs * samples ,color='#fdb462')
plt.grid(color='grey', linestyle='-.', linewidth=0.5)
plt.show() Why is the yellow time-domain signal not as the same as the original blue signal?

• Hi Reza! Welcome to DSP.SE. Your question isn't really clear; can you add further details as to why you aren't doing ts = np.fft.ifft(fs) given fs is the fourier transform? If you want to include your code, please narrow it down to the bare minimum to focus on your question and add more details as to what you are stuck on exactly. Including plots can also help. Feb 14 at 0:10
• Hi Dan! Thank you for suggestions. Feb 14 at 0:36

samples = 10000
t = np.arange(samples)
# declare an all-zeros frequency spectrum
s = np.zeros((samples,), dtype=complex)
# set the spectral lines
s = 0.5
s = 1.0
s = 0.5

fs = np.fft.ifft(s)[:512]
sp2.plot(fi, fs * samples ,color='#fdb462')
plt.grid(color='grey', linestyle='-.', linewidth=0.5)
plt.show()


seems to be making the one-sided spectrum that your first signal creates.

For the inverse to work, your Fourier domain signal needs to have both positive and negative frequency peaks.

You also haven't clarified Dan's question: why are you doing that, rather than just

s = np.fft.ifft(fs)


given the fs is the frequency domain representation of your original signal.

That part doesn't make sense to me.

• and I think it was missed that the values are complex, where in the OP only the magnitudes were used in the recreation of the FFT bins. Feb 14 at 3:12
• I am aware of the ifft function but I will have to demonstrate this to some people and delineate it. I was able to get the signal back by including the imaginary part. Feb 14 at 3:46