Skip to main content
. 2016 Aug 20;16(8):1314. doi: 10.3390/s16081314
Algorithm 2: Dynamic time warping.
 1: Input:
 2: st: template segment, with nst sampling points st1 to stnst.
 3: s: segment for recognition, whose class is unknown, with ns sampling points s1 to sns.
 4: Output:
 5: d: DTW distance between s and st.
 6: normalize the amplitude of each sampling point in s into [-1, 1];
 7: normalize the amplitude of each sampling point in st into [-1, 1];
 8: d00 = 0;
 9: for i = 1 to nst do
 10:  di0 = +;
 11: end for
 12: for j = 1 to ns do
 13:  d0j = +;
 14: end for
 15: for i = 1 to nst do
 16:  for j = 1 to ns do
 17:   d˜ij = |sti-sj|;
 18:   dij = d˜ij+ min(d(i-1)j, d(i-1)(j-1), di(j-1));
 19:  end for
 20: end for
 21: d = dnstns;