Main Content


Convert from hertz to mel scale

Since R2019a



mel = hz2mel(hz) converts values in hertz to values on the mel frequency scale.

mel = hz2mel(hz,MelStyle=style) specifies whether to use the Slaney-style or O'Shaughnessy-style mel scale.


collapse all

Set two bounding frequencies in Hz and then convert them to the mel scale.

b = hz2mel([20,8000]);

Generate a row vector of 32 values uniformly spaced on the mel scale.

melVect = linspace(b(1),b(2),32);

Convert the row vector of values into equivalent frequencies in Hz.

hzVect = mel2hz(melVect);

Plot the two vectors for comparison. As mel values increase linearly, Hz values increase exponentially.

title('Mel vs Hz')
grid on

Figure contains an axes object. The axes object with title Mel vs Hz, xlabel Mel, ylabel Hz contains a line object which displays its values using only markers.

Create a vector containing frequencies from 0 Hz to 8000 Hz.

hz = 0:8e3;

Convert the frequencies to the mel scale. By default, hz2mel uses the O'Shaughnessy-style mel scale.

mel_oshaughnessy = hz2mel(hz);

Convert the frequencies using the Slaney-style mel scale by calling hz2mel with MelStyle set to "slaney".

mel_slaney = hz2mel(hz,MelStyle="slaney");

Plot both the O'Shaughnessy-style and Slaney-style mel frequencies against the frequency in Hz.

ylabel("Mel (O'Shaughnessy)")
yyaxis right
ylabel("Mel (Slaney)")

Figure contains an axes object. The axes object with xlabel Hertz, ylabel Mel (Slaney) contains 2 objects of type line.

Input Arguments

collapse all

Input frequency in Hz, specified as a scalar, vector, matrix, or multidimensional array.

Data Types: single | double

Mel style, specified as "oshaughnessy" or "slaney".

Data Types: char | string

Output Arguments

collapse all

Output frequency on the mel scale, returned as a scalar, vector, matrix, or multidimensional array the same size as hz.

Data Types: single | double


The frequency conversion from Hz to the O'Shaughnessy-style mel scale uses the following formula [1]:


The Slaney-style mel scale follows [2]. The scale is linear with respect to Hz below 1000 Hz, and it is logarithmic above 1000 Hz.


[1] O'Shaughnessy, Douglas. Speech Communication: Human and Machine. Reading, MA: Addison-Wesley Publishing Company, 1987.

[2] Slaney, Malcolm. "Auditory Toolbox: A MATLAB Toolbox for Auditory Modeling Work." Technical Report, Version 2, Interval Research Corporation, 1998.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2019a

expand all