In most audio processing tasks, one of the most used transformations is MFCC (Mel-frequency cepstral coefficients).

I mostly know the math that's behind the MFCC: I understand both the filterbank step and the Mel frequency scaling.

What I don't get is the DCT (Discrete Cosine Transform) step: What kind of information do I get in this step? What is a good visual representation of this step?


You can think of the DCT as a compression step. Typically with MFCCs, you will take the DCT and then keep only the first few coefficients. This is basically the same reason that the DCT is used in JPEG compression. DCTs are chosen because their boundary conditions work better on these types of signals.

Let's contrast the DCT with the Fourier transform. The Fourier transform is made up of sinusoids that have an integer number of cycles. This means, all of the Fourier basis functions start and end at the same value -- they do not do a good job of representing signals that start and end at different values. Remember that the Fourier transform assumes a periodic extension: If you imagine your signal on a sheet of paper, the Fourier transform wants to roll that sheet into a cylinder so that the left and right sides meet.

Think of a spectrum that is shaped roughly like a line with negative slope (which is pretty typical). The Fourier transform will have to use a lot of different coefficients to fit this shape. On the other hand, the DCT has cosines with half-integer numbers of cycles. There is, for example, a DCT basis function that looks vaguely like that line with negative slope. It does not assume a period extension (instead, an even extension), so it will do a better job of fitting that shape.

So, let's put this together. Once you've computed the Mel-frequency spectrum, you have a representation of the spectrum that is sensitive in a way similar to how human hearing works. Some aspects of this shape are more relevant than others. Usually, the larger more overarching spectral shape is more important than the noisy fine details in the spectrum. You can imagine drawing a smooth line to follow the spectral shape, and that the smooth line you draw might tell you just about as much about the signal.

When you take the DCT and discard the higher coefficients, you are taking this spectral shape, and only keeping the parts that are more important for representing this smooth shape. If you used the Fourier transform, it wouldn't do such a good job of keeping the important information in the low coefficients.

If you think about feeding the MFCCs as features to a machine learning algorithm, these lower-order coefficients will make good features, since they represent some simple aspects of the spectral shape, while the higher-order coefficients that you discard are more noise-like and are not important to train on. Additionally, training on the Mel spectrum magnitudes themselves would probably not be as good because the particular amplitude at different frequencies are less important than the general shape of the spectrum.


The key to understanding MFCC is in the start of the sentence in the linked-to article:

They are derived from a type of cepstral representation of the audio clip...

MFCCs are like a spectrum-of-a-log-spectrum, the cepstrum.

The cepstrum of a signal $x(t)$is just:

$$C(z) = {\cal F}^{-1}(\log(|{\cal F}(x(t))|^2) $$

where ${\cal F}$ is the Fourier transform and ${\cal F}^{-1}$ its inverse.

The reason the cepstrum is neat is that the interposed logarithm operation means that convolutions of the original signal show up as simple additions in the cepstrum.

That advantage carries over to the MFCCs, although liftering is not as direct as with the standard cepstrum.

Where the MFCC differs is in the use of the discrete cosine transform (DCT) as the final transform instead of the inverse Fourier transform.

The advantage the DCT has over the Fourier transform is that the resulting coefficients are real-valued, which makes subsequent processing and storage easier.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.