# Using DTW on the MFCC's to match a spoken word to a template

I am trying to code a simple algorithm in MATLAB that would be used to detect a single word. The goal would be to have a user record the word one time to act as a template, then make the user repeat the same word to try and detect it. Searching on this website has answered many of my questions, but I still have some interrogations.

So far my algorithm calculates the MFCC's in the following way:

• Extract the data from a .wav file (recorded at $8000\textrm{ Hz}$)
• Build frames of $64\textrm{ ms}$ with a $50\%$ overlap, applying a Hann window
• Calculate the FFT of all these frames
• Calculate the Power Spectrum using the FFT results ($P(k) = \lvert X(k)\rvert^2$)
• For each frame, extract 26 coefficients by multiplying the Power Spectrums with the 26 Mel filters and summing the results for a given Mel filter
• Calculate the $\log_{10}$ of the coefficients
• Apply a dct on a frame's 26 coefficients

My goal was to use the MFCC's of the template as well as the MFCC's of the repeated work and compare them using a DWT algorithm. My DWT algorithm is already programmed and functional.

However, my algorithm does not work very well and it seems like certain parameters affect the results quite a lot. Here are my questions:

1. Are these steps enough to detect a spoken word?

2. Would it be better to use a large number of fixed templates instead of having the user pre-record a template? Which method should result in better recognition performance?

3. If the person repeats the word using a different distance from the microphone, the increased/decreased values of the MFCC's are enough to mess up the DTW results. Is there a smart way to normalize the MFCCs to try and cancel the effect of the microphone distance?

4. Some websites recommend using only the 13 MFCC's with the smallest values.

• Why is that?
• Also, are they talking about the smallest magnitudes, or the smallest values?
• Assuming 13 MFCC's are very big negative numbers, while 13 other MFCC's are small positive numbers, which set would I keep?

EDIT: Also, the first coefficient of each frame is always much bigger than the other coefficients. I would say it's magnitude is bigger my a factor of 100. Obviously, when I caculate the DTW using Euclidian distance, I'd say this coefficient is the only relevant one since it is so much bigger than all the other values. Should it be discarded?

1. Yes, this should be enough for a basic isolated word recognition system. Probably not something for a commercial product, but good enough for a university project or demo...

2. It would be better to ask the user to record a word and match against this, rather than attempt to match against a large database of utterances of the same word by different speakers. The larger the database the more likely you'd find an utterance matching the user's voice, but matching against a large database would be computationally expensive!

3. The first MFCC captures the signal energy - you might try to remove it when doing the matching (your feature vector will thus contain MFCC #2 to 13) - this will make recognition more robust to changes in amplitude.

4. You might have misunderstood something. Do you have a link to such a website?

A general proporty of MFCC is that as the coefficient index increases, the standard deviation of this coefficient decreases (the DCT can be thought of as an approximation of a PCA) - so the lower coefficients will have greater magnitude. You can compensate for that by estimating the standard deviation of each MFCC coefficient on a training set, once and for all, and dividing each coefficient by its standard deviation (or a power of it < 1.0) prior to the DTW step.

I think that this approach should work rather well (I did very similar project few years ago). Things you might consider:

1. You probably might want to use pre-emphasis filter on a signal.
2. In addition to MFCC features you can also include $\Delta$ and $\Delta\Delta$ (first and second derivatives - simple differences).
3. Comparing against more templates in my case largely improved recognition rate. I think that the easiest way do so is by using k-NN algorithm on distances returned from DWT.

Good luck!