def SpecCentWind(x, sr=1, nwind=1024, nhop=512, windfunc=np.blackman):
'''
Calculates the SpectralCentroid of x, in frames of
length nwind, and in steps of nhop. windfunc is used as
windowing function
nwind should be at least 3 periods if the signal is periodic.
'''
ff = np.arange(nwind/2)/float(nwind)*sr
def SCvec(xw):
xf = np.fft.fft(xw)
xf2 = xf[:nwind/2]
return sum(np.abs(xf2)*ff)/sum(np.abs(xf2))
amp, t = FuncWind(SCvec, x, power=0, sr=sr,
nwind=nwind, nhop=nhop)
return np.array(amp), np.array(t)
评论列表
文章目录