我正在分析波动中存在的谐波作为弹拨发生位置的函数。我希望获得像本页所示的情节:https ://softwaredevelopmentperestroika.wordpress.com/2013/12/10/fast-fourier-transforms-with-python-the-noise-and-the-signal/ 。为此,我编写了对非对称三角形进行建模的代码并实现了 numpy 的 fft。然而,输出的数据不是我所期望的,它的峰值约为 0 Hz。这是我的代码及其输出:
from numpy.fft import fft as npfft, fftfreq as npfftfreq
#triangular pulse
def triangular_pulse(x, xmean, sigma):
for i in x:
if x[i]<=xmean:
y[i] = x[i]*(sigma/xmean)
else :
y[i] = sigma-(x[i]-xmean)*(sigma/(200-xmean))
return y
N_masses = 200
T = 0.0669264714
mu = .03937
cSq = T/mu
c = np.sqrt(cSq)
dx = 1.0
dt = dx/c
print dt
#Initialize some arrays
x0 = np.arange(N_masses)*dx
y = np.zeros(N_masses)
vy = np.zeros(N_masses)
ay = np.zeros(N_masses)
#Set Initial conditions (pluck)
# # half-pluck
# y = 30*gaussian_pulse(x0,x0[N_masses/2],2)
# quarter-pluck
y = triangular_pulse(x0,x0[N_masses/4],1)
rhat=npfft(y)
freaq=npfftfreq(len(y),dt)
plt.plot(freaq,np.abs(rhat)/len(rhat))
plt.show()
如果您发现我的问题的根源,请告诉我。谢谢!
更新
添加了 y = triangular_pulse(x0,x0[N_masses/40],1) y-=np.mean(y) ,结果是更宽的非零带;然而,峰值仍然以“0”为中心。