我有以下代码...请注意# generate sine curve下的两行代码。其中一行使用比另一行更高精度的2pi值,尽管它们应该仍然给出接近相同的结果。
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()
如果您使用较低的精度6.28318运行代码,则可以获得fft的预期结果... 然而,如果您使用更高的精度6.283185307179586(等于2.*numpy.pi)运行代码,则会得到以下意外结果...实部明显错误...幅值偏差很大,不对称,没有任何意义。 我不知道是什么原因导致了这种情况。有人有什么想法吗?