File Exchange

image thumbnail

Continuous Dynamic Time Warping

version 1.0 (4.75 KB) by

A version of the DTW algorithm. The CDTW calculates the similarity between 2 vectors

11 Ratings



View License

If you pass in 2 vectors it returns the unnormalized distance between the vectors, the accumulated distance between them, the length of the warping path (the normalizing factor), the warping path points and both warped input vectors.
You can plot the results too if select the pflag=1

Comments and Ratings (15)

Daniele Gamba

Nan Ye

Nan Ye (view profile)

Rig Das


Céldor (view profile)

Thanks for the file.

In your dtw.m code, in line 49

could be changed to [~,number] = ...

to avoid MATLAB warning.

Also, size of your matrix w changes with every iteration. Have you considered, allocating space before and then reduce its size to minimum when the loop is over? I think the max number of possible iteration is M + N, or even M+N-2 -- the worst case when each step would be non-diagonal.


Loïc (view profile)

Jan Motl

Jan Motl (view profile)


Hi! any one know how to modify the script if two vectors are in different length?

Fatemeh Saki

very very helpful code thank you so much

marco gomez

I don't understand the followig lines:

w=[m n; w];

% warped waves

Could you explain to me? please.

Vlad Atanasiu

Vlad Atanasiu (view profile)

Harish Kumar


This refers to 2 vectors. What if this were to be used for polyline to polyline comparison?

Appreciate your replies. Thanks & Regards,

jose tabora

Nice code, and nice demo.

Also thanks to Darryl Wallace for providing the needed correction to the div error.

Ahmed Bderhman

I think this is a good working and had help me more.

I have this question: i like to change euclidean distance{d=(repmat(Test',1,N)-repmat(Ref,M,1)).^2;} with mahalanobis distance is it possipole? if yes how can i do that?

because i like to test the efficiency of my system when i use euclidean distance and when i used mahalnobis distance.

Darryl Wallace

Ok yeah so I wrote a div function that is just

%% Start div function
q = div(num,den)
q = floor(num/den);
%% End div function.

and it appears to be working properly now.

Darryl Wallace

It looks good. And the portion from the original dtw.m file by Timothy Felty works. But it stops for me at when calling the function 'div'. I'm not entirely certain what this will do so I have been reluctant to change it. But if I had to guess, would it be an integer division? i.e. div(11,2) => 11/2 = 5?


demo included

MATLAB Release
MATLAB 7 (R14)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video