0
$\begingroup$

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.

enter image description here

# 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[940] = 0.5
s[1000] = 1.0
s[1060] = 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()

enter image description here

Why is the yellow time-domain signal not as the same as the original blue signal?

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Feb 14 at 0:10
  • $\begingroup$ Hi Dan! Thank you for suggestions. $\endgroup$
    – Reza Afra
    Feb 14 at 0:36

1 Answer 1

3
$\begingroup$

Your code:

samples = 10000
t = np.arange(samples)
# declare an all-zeros frequency spectrum
s = np.zeros((samples,), dtype=complex)
# set the spectral lines
s[940] = 0.5
s[1000] = 1.0
s[1060] = 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.

$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Feb 14 at 3:12
  • $\begingroup$ 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. $\endgroup$
    – Reza Afra
    Feb 14 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.