通过以下简单的 Python fft 实现,我得到了错误的输出。有人可以解释我需要解决的问题吗?
import numpy as np
import matplotlib.pyplot as plt
def tone(fs, frequency, dur=1, amp=50):
'''
test tone
'''
nsamples = dur * fs
t = np.linspace(0, dur, nsamples, endpoint=False)
tone = amp*np.sin(frequency*2*np.pi*t)
return tone
fs = 16000
dur = 0.5
freq = 1500
stim = tone(fs, freq, dur=dur)
time = np.linspace(0, dur, num=fs*dur)
t = np.linspace(0, fs, num=fs*dur)
fdata = np.fft.fft(stim)
hwp = int(np.shape(fdata)[0]/2)
tplt = t[:hwp]
fplt = fdata[:hwp]
plt.figure(num=1)
plt.plot(time, stim, 'b-')
plt.show()
plt.figure(num=2)
plt.plot(tplt, np.abs(fplt.real), 'b-')
plt.xscale('log')
plt.show()
移除
, 端点 = 假
虽然我不明白为什么会修复实现。
也许有人可以解释(?)

