View License

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

» Watch video

Highlights from
Dynamic Time Warping (DTW)

4.6 | 12 ratings Rate this file 189 Downloads (last 30 days) File Size: 3.18 KB File ID: #43156 Version: 1.4
image thumbnail

Dynamic Time Warping (DTW)


Quan Wang (view profile)


20 Aug 2013 (Updated )

This package implements Dynamic Time Warping (DTW).

| Watch this File

File Information

DTW is implemented in both Matlab and C/MEX. The C/MEX function is very fast. The algorithm we use is the standard one from wiki:
There is a demo in the package. To use, just call:
d=dtw(s,t,w) or d=dtw_c(s,t,w)


This file inspired Jsantarc/Dynamic Time Alignment K Means Kernel Clustering For Time Sequence Clustering.

Required Products MATLAB Compiler
MATLAB release MATLAB 8.0 (R2012b)
MATLAB Search Path
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (24)
24 May 2016 Beil Zheng

17 May 2016 kalarmago

What is a common value for the w parameter?

17 Apr 2016 yabing hu

good job

Comment only
10 Feb 2016 Yijun Yan

Hi Quan,

Just wonder, which is the corresponding paper for this code?

16 Dec 2015 Yuanliang Meng

Hi Quan,
It is nice. It would be useful if you can add an option to force the alighment of start/end points of two signals. Or force the alignment of selected points (so it becomes interpolation in a sense).

Comment only
29 Nov 2015 Chanmann Lim

Hi Quan, This is a great piece of work and I have made slight changes to normalize the DTW distance by its warping path for both matlab and c versions for my project. Please let me know if I can contribute that here.


26 Nov 2015 Grace Pan

Hi,Quan Wang
Could i ask you a question? The code works perfectly when two input data have the same length. But if two input data have different length, such as [10 12 14 18 14 12 10 10 12 14 18 14 12 10] and [NaN 12 14 18 14 12 10 10 12 14 18 NaN NaN NaN], the output is NaN. Could you think how to deal with it?

Comment only
27 Sep 2015 Sahan Priyanga

07 Jul 2015 nguyen anh

Hi Quan Wang.
I have a question:
What the paper does algorithm DTW using adapt window size belong to ?

Thank you.

Comment only
14 May 2015 Haoyi Xu

02 Dec 2014 Tipu Rahaman

I am getting error as
'Maximum variable size allowed by the program is exceeded.'

for below line.

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

Comment only
16 Nov 2014 Quan Wang

Quan Wang (view profile)

Hi Yongqiang,

The window parameter w in function dtw(s,t,w) is the parameter that prevents big gradients.

Comment only
14 Nov 2014 Yongqiang

Hi Quan,

Could I ask you a question? I just want to confirm with you, so that I correctly understand what is written in your file. You didn't implement the slope constraint (the one that prevents too much or too little gradient, namely the fifth condition in Sakoe & Chiba 1978), did you?

Sakoe & Chiba 1978: Dynamic programming algorithm optimization for spoken word recognition.

Comment only
14 Nov 2014 Chang hsiung


25 Sep 2014 Quan Wang

Quan Wang (view profile)

Hi Daniel,

You need to learn what is a MATLAB function first.

Comment only
24 Sep 2014 Daniel

Daniel (view profile)

What does MATLAB Compiler do? When I try to run the code, I get an error message for Line 1 (function d=dtw(a,b,w)).


Comment only
08 Sep 2014 Quan Wang

Quan Wang (view profile)

Hi Steven du,

Yes, you are right. I forgot to update it when I extended it for multi-dimensional signals.

Comment only
08 Sep 2014 Steven du

I thinks line 19 of dtw.m
Ought to be ns=size(s,1)

As length(s)=max(size(s))

08 May 2014 ryphodoras

great job!

21 Mar 2014 Blaise

Blaise (view profile)

works perfectly!

03 Mar 2014 Yan Ou

Yan Ou (view profile)

03 Mar 2014 Siqi

Siqi (view profile)

26 Feb 2014 Quan Wang

Quan Wang (view profile)

Hi Leonel Rozo, it now supports multidimensional signals.

Comment only
05 Dec 2013 Leonel Rozo

Does it consider multidimensional signals?

Comment only
27 Feb 2014 1.2

removed mex file

28 Feb 2014 1.3

added Matlab compiler as required products

13 Nov 2014 1.4

Minor bug fixed according to the suggestion from Steven du, NTU. Thanks.

Contact us