I have calculated 26 MFCCs for two sample speech data. My mfcc matrices thus contain 26 columns and 120 rows each, where 120 is the number of frames. Now I want to apply DTW on them and I am doing this (on MATLAB):
mfcc1=mfcc1'; mfcc2=mfcc2'; M=simmx(mfcc1,mfcc2); [p,q,c]=dp(1-M); v=c(size(c,1),size(c,2))
which I have taken from this post
But I don't quite understand why the similarity matrix and why it has to be
Also if I exclude the first co-efficient, the result becomes totally invalid i.e it seems the first co-efficient is mandatory for DTW.
Is there something wrong with my approach? If it is, then how can I make it right?
function [p,q,D] = dp(M) % [p,q] = dp(M) % Use dynamic programming to find a min-cost path through matrix M. % Return state sequence in p,q % 2003-03-15 email@example.com % Copyright (c) 2003 Dan Ellis <firstname.lastname@example.org> % released under GPL - see file COPYRIGHT [r,c] = size(M); % costs D = zeros(r+1, c+1); D(1,:) = NaN; D(:,1) = NaN; D(1,1) = 0; D(2:(r+1), 2:(c+1)) = M; % traceback phi = zeros(r,c); for i = 1:r; for j = 1:c; [dmax, tb] = min([D(i, j), D(i, j+1), D(i+1, j)]); D(i+1,j+1) = D(i+1,j+1)+dmax; phi(i,j) = tb; end end % Traceback from top left i = r; j = c; p = i; q = j; while i > 1 & j > 1 tb = phi(i,j); if (tb == 1) i = i-1; j = j-1; elseif (tb == 2) i = i-1; elseif (tb == 3) j = j-1; else error; end p = [i,p]; q = [j,q]; end % Strip off the edges of the D matrix before returning D = D(2:(r+1),2:(c+1));
function M = simmx(A,B) % M = simmx(A,B) % calculate a sim matrix between specgram-like feature matrices A and B. % size(M) = [size(A,2) size(B,2)]; A and B have same #rows. % 2003-03-15 email@example.com % Copyright (c) 2003 Dan Ellis <firstname.lastname@example.org> % released under GPL - see file COPYRIGHT EA = sqrt(sum(A.^2)); EB = sqrt(sum(B.^2)); %ncA = size(A,2); %ncB = size(B,2); %M = zeros(ncA, ncB); %for i = 1:ncA % for j = 1:ncB % % normalized inner product i.e. cos(angle between vectors) % M(i,j) = (A(:,i)'*B(:,j))/(EA(i)*EB(j)); % end %end % this is 10x faster M = (A'*B)./(EA'*EB);