[][src]Function mel_filter::mel_frequencies

pub fn mel_frequencies<T: Float + NumOps>(
    n_mels: Option<usize>,
    fmin: Option<T>,
    fmax: Option<T>,
    htk: bool
) -> Vec<T>

Implementation of librosa.mel_frequencies

Compute an array of acoustic frequencies tuned to the mel scale.

The mel scale is a quasi-logarithmic function of acoustic frequency designed such that perceptually similar pitch intervals (e.g. octaves) appear equal in width over the full hearing range.

Because the definition of the mel scale is conditioned by a finite number of subjective psychoaoustical experiments, several implementations coexist in the audio signal processing literature [#]. By default, librosa replicates the behavior of the well-established MATLAB Auditory Toolbox of Slaney [#]. According to this default implementation, the conversion from Hertz to mel is linear below 1 kHz and logarithmic above 1 kHz. Another available implementation replicates the Hidden Markov Toolkit [#]_ (HTK) according to the following formula::

mel = 2595.0 * (1.0 + f / 700.0).log10().

The choice of implementation is determined by the htk keyword argument: setting htk=false leads to the Auditory toolbox implementation, whereas setting it htk=true leads to the HTK implementation.

  • [#] Umesh, S., Cohen, L., & Nelson, D. Fitting the mel scale. In Proc. International Conference on Acoustics, Speech, and Signal Processing (ICASSP), vol. 1, pp. 217-220, 1998.

  • [#] Slaney, M. Auditory Toolbox: A MATLAB Toolbox for Auditory Modeling Work. Technical Report, version 2, Interval Research Corporation, 1998.

  • [#] Young, S., Evermann, G., Gales, M., Hain, T., Kershaw, D., Liu, X., Moore, G., Odell, J., Ollason, D., Povey, D., Valtchev, V., & Woodland, P. The HTK book, version 3.4. Cambridge University, March 2009.

See Also

hz_to_mel

mel_to_hz

librosa.feature.melspectrogram

librosa.feature.mfcc

Parameters

n_mels : Number of mel bins.

fmin : float >= 0, Minimum frequency (Hz).

fmax : float >= 0, Maximum frequency (Hz).

htk : bool If True, use HTK formula to convert Hz to mel. Otherwise (False), use Slaney's Auditory Toolbox.

Returns

bin_frequencies : Vec[shape=(n_mels,)] Vector of n_mels frequencies in Hz which are uniformly spaced on the Mel axis.

Examples

use mel_filter::mel_frequencies;
let freqs = mel_frequencies::<f64>(Some(40), None, None, false); // n_mels=40
println!("{:?}", freqs);
let expected = vec![  0.0             ,   85.31725552163941,  170.63451104327882,
                    255.95176656491824,  341.26902208655764,  426.586277608197  ,
                    511.9035331298365 ,  597.2207886514759 ,  682.5380441731153 ,
                    767.8552996947546 ,  853.172555216394  ,  938.4898107380334 ,
                   1024.8555458780081 , 1119.1140732107583 , 1222.0417930074345 ,
                   1334.436032577335  , 1457.1674514162094 , 1591.1867857508237 ,
                   1737.532213396153  , 1897.3373959769085 , 2071.840260812287  ,
                   2262.3925904926227 , 2470.4704944333835 , 2697.6858435241707 ,
                   2945.7987564509885 , 3216.731234416783  , 3512.5820498813423 ,
                   3835.64300465582   , 4188.416683294875  , 4573.635839312682  ,
                   4994.284564397706  , 5453.621404613084  , 5955.204602651788  ,
                   6502.919661685081  , 7101.009444327076  , 7754.107039876304  ,
                   8467.271654439703  , 9246.027801961029  , 10096.408099746186 ,
                   11025.0];
assert_eq!(freqs, expected);