【发布时间】:2020-03-03 14:06:53
【问题描述】:
我找到了以下两种计算光谱质心的方法,但它们返回的值不同。
哪个是正确的版本,两者有何不同?
1.
def spectral_centroid(x, samplerate=44100):
magnitudes = np.abs(np.fft.rfft(x)) # magnitudes of positive frequencies
length = len(x)
freqs = np.abs(np.fft.fftfreq(length, 1.0/samplerate)[:length//2+1]) # positive frequencies
return np.sum(magnitudes*freqs) / np.sum(magnitudes)
2.
cent = librosa.feature.spectral_centroid(y=y, sr=sr)
print(np.mean(cent.T, axis=0))
【问题讨论】:
标签: python signal-processing librosa