matplotlibmfcclibrosa

Librosa mel filter bank decreasing triangles


I'm a bit stuck understanding MFCCs.

From what I have read the mel filter banks should be a series of triangles that get wider and their peaks are at the same place. Like this...

enter image description here

However when I compute the mel filter banks using librosa I get...

enter image description here

Code:

import librosa
import matplotlib.pyplot as plt

sr = 16000
mel_basis = librosa.filters.mel(sr=sr, n_fft=512, n_mels=10,fmin=0, fmax=sr / 2)
plt.plot(mel_basis)

Solution

  • I'm a bit more informed now and I feel like the answer given is not completely correct, so I think I should answer my own question.

    librosa.filters.mel returns a matrix with the shape (n_mels, n_fft/2 +1). This means each row in the matrix is a mel. The columns are the weight for each frequency for the mel filter bank. The frequency is in terms of cycles up to number of n_fft, we throw away half of them due to aliasing (nyquist theorem).

    This means in order to plot the mels correctly the matrix needs to be transposed. As we effectively want N different plots where N is the number of mels.

    plt.plot(mel.T)

    This gives the following image: enter image description here

    Note that this set of mel filter banks is still not what is expected. This is because the Librosa uses a normalised version of mel-filter banks, this means that each of the mels have an area of 1 instead of the traditional equal height of 1. The matrix returned from librosa can be transformed into the equal height mel-filter bank by:

    mels /= np.max(mels, axis=-1)[:, None]

    And then the plot looks like this:enter image description here