I have the following code...Note the two lines under # generate sine curve. One uses a higher precision value for 2pi than the other, they should still give near identical results though.
import numpy as np
import matplotlib.pyplot as plt
t1 = np.arange(0., 1., .01)
# generate sine curve
y1 = np.sin(6.28318*5.*t1)
#y1 = np.sin(6.283185307179586*5.*t1) # equivalent to np.sin(2*np.pi*t1)
# calculate the fft (no averaging!) of the time series
ffty = np.fft.fft(y1)
fig, ax_list = plt.subplots(3,1)
ax_list[0].plot(t1,y1, '.-')
ax_list[1].plot(ffty.real, '.-', label='Real Part')
ax_list[1].legend()
ax_list[2].plot(ffty.imag, '.-', label='Imag Part')
ax_list[2].legend()
plt.show()
If you run the code with the lower precision 6.28318 you get the expected result for the fft...
However, if you run the code with the higher precision 6.283185307179586 which is equal to 2.*numpy.pi, you get the unexpected result below... the real part is drastically wrong...The amplitudes are way off, it's not symmetric, it doesn't make any sense.
I'm at a loss as to what is causing this. Anyone have any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…