You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the example for mel_to_stft we have the following code:
y, sr = librosa.load(librosa.ex('trumpet'))
S = np.abs(librosa.stft(y))
mel_spec = librosa.feature.melspectrogram(S=S, sr=sr)
S_inv = librosa.feature.inverse.mel_to_stft(mel_spec, sr=sr)
S is the magnitude, mel_spec is therefore a mel magnitude spectrogram (not mel power spectrogram). However, the code for librosa.feature.inverse.mel_to_stft does the following:
M : np.ndarray [shape=(..., n_mels, n), non-negative]
The spectrogram as produced by `feature.melspectrogram`
inverse = nnls(mel_basis, M)
return np.power(inverse, 1.0 / power, out=inverse)
The power variable is not passed in the example and is therefore the default value power = 2.0. This would be correct when assuming a power spectrogram as input, which is not the case here.
My understanding is, that S_inv is now the approximate square root of S? However, in the example we proceed to compare the two assuming they should be equal, apart from the approximation error.
IMO we either need to convert magnitude into power with S = np.abs(librosa.stft(y))**2 or pass the power parameter in S_inv = librosa.feature.inverse.mel_to_stft(mel_spec, sr=sr, power=1).
The text was updated successfully, but these errors were encountered:
Ah, excellent catch! You are correct that there is a power mismatch between the forward and inverse calls here. Fixing this does dramatically reduce the residual error. I'll PR a fix before the monday release.
In the example for mel_to_stft we have the following code:
S is the magnitude, mel_spec is therefore a mel magnitude spectrogram (not mel power spectrogram). However, the code for
librosa.feature.inverse.mel_to_stft
does the following:The
power
variable is not passed in the example and is therefore the default valuepower = 2.0
. This would be correct when assuming a power spectrogram as input, which is not the case here.My understanding is, that
S_inv
is now the approximate square root ofS
? However, in the example we proceed to compare the two assuming they should be equal, apart from the approximation error.IMO we either need to convert magnitude into power with
S = np.abs(librosa.stft(y))**2
or pass thepower
parameter inS_inv = librosa.feature.inverse.mel_to_stft(mel_spec, sr=sr, power=1)
.The text was updated successfully, but these errors were encountered: