たれぱんのびぼーろく

わたしの備忘録、生物学とプログラミングが多いかも

librosaの`amplitude_to_db`は扱い注意

librosa.amplitude_to_db は linear-amplitude spec を log-power spec へ変換する関数1.
linear-ampをlog-ampにするのではない, 注意.

この用途で楽をしたい場合、librosa.power_to_db へ linear-ampを突っ込めばいい.

# 300/3 = 100 = 10^2 = 2B = 20dB
S = np.array([[300., 3.]])
S_db = librosa.power_to_db(S, ref=3.0, top_db=None)
print(S, S_db) # [[300.   3.]] [[20.  0.]]

  1. “Convert an amplitude spectrogram to dB-scaled spectrogram. … This is equivalent to power_to_db(S2, ref=ref2, amin=amin**2, top_db=top_db)” from librosa 0.9.1