# Compare two spoken words with MFCC and DTW

Processing of the speech signal is done using Matlab. I want to use MFCC (Mel-frequency cepstral coefficients) is implemented using HTK and DTW (dynamic time warping v2.1) algorithms to make a speech comparison script. I calculated MFCC and got 13 coefficients for each frame.

1. How do I calculate DWT from Applying DTW on MFCC frames?
2. DTW gives me a distance between two patterns. How do I determine if they match or not?

How do I edit this code? this is the code I am using:

function d=dtw(s,t,w)

% s: signal 1, size is ns*k, row for time, colume for channel
% t: signal 2, size is nt*k, row for time, colume for channel
% w: window parameter
% if s(i) is matched with t(j) then |i-j|<=w

if nargin<3
w=Inf;
end

ns=size(s,1);
nt=size(t,1);

if size(s,2)~=size(t,2)
error('Error in dtw(): the dimensions of the two input signals do not match.');
end

w=max(w, abs(ns-nt)); % adapt window size

%% initialization

D=zeros(ns+1,nt+1)+Inf; % cache matrix
D(1,1)=0;

%% begin dynamic programming

for i=1:ns

for j=max(i-w,1):min(i+w,nt)

oost=norm(s(i,:)-t(j,:));

D(i+1,j+1)=oost+min( [D(i,j+1), D(i+1,j), D(i,j)] );

end

end

d=D(ns+1,nt+1);

• Does this answer and links in it help you? In a nutshell, for DTW you need to have a "database" of exemplars for each of the words and then determine which exemplar is closest to your utterance. Of course, this can be improved e.g. by using k-NN algorithms, etc. – jojek Jul 15 '20 at 10:09