0

I have computed the mel spectrogram with librosa like that:

self.Spectrogram = librosa.feature.melspectrogram(y=self.RawSignal, sr=self.sampling_frequency,
                                                      n_mels=128, fmax=8000)

I need to obtain the corresponding value of a given frequency (say 4400 Hz) in the normalized scale [0,127], since n_mels=128. I have seen that 103 is the corresponding value to 4400 Hz, but I would like a generic formula. PS. it is not the conversion formula from Hz to mels what I am searching for.

Thanks in advance

LiukPet
  • 93
  • 10

1 Answers1

0

Use the librosa.core.mel_frequencies function to calculate the centerpoint of your mel filters. Make sure to pass the same parameters as to melspectrogram. Once you have the centerpoints, you can find which bin a particular frequency belongs to by looking up the closest value.

import numpy
import librosa

find = 4400 
freqs = librosa.core.mel_frequencies(fmin=0.0, fmax=8000, n_mels=128)
bin = numpy.argmin(abs(freqs - find))

print(bin)

103

Jon Nordby
  • 5,494
  • 1
  • 21
  • 50