I'm using the librosa
library to get and filter spectrograms from audio data.
I mostly understand the math behind generating a spectrogram:
- Get signal
- window signal
- for each window compute Fourier transform
- Create matrix whose columns are the transforms
- Plot heat map of this matrix
So that's really easy with librosa
:
spec = np.abs(librosa.stft(signal, n_fft=len(window), window=window)
Yay! I've got my matrix of FFTs. Now I see this function librosa.amplitude_to_db
and I think this is where my ignorance of signal processing starts to show. Here is a snippet I found on Medium:
spec = np.abs(librosa.stft(y, hop_length=512))
spec = librosa.amplitude_to_db(spec, ref=np.max)
Why does the author use this amplitude_to_db
function? Why not just plot the output of the STFT directly?