How does DTW penalize stretching ?

4 views (last 30 days)
Mac Fuirdmith
Mac Fuirdmith on 4 Oct 2016
Answered: Greg Dionne on 21 Oct 2016
The DTW function from Signal Processing Toolbox seems to penalize stretching of a Time Series/Signal. Can i switch that off or define my own penalties/weights ?

Accepted Answer

Bert
Bert on 4 Oct 2016
hi,
I believe you misunderstood the DTW principal. DTW does directly penalizes stretching in the signals, as intended. The best way to show this is by some examples.
Try following input were the stretching is done by repeating some samples (depending on the application: but might not be the stretching normally seen, e.g. speech signals):
s1 = [1 4 7]';
s2 = [1 4 4 7]';
The error matrix will be (absolute error):
error = [0 3 6;...
3 0 3;...
3 0 3;...
6 3 0]; % s1 horizontally, s2 vertically
So there is a path from upper left to bottom right (taking horizontally, vertically or diagonal steps) with only zero penalties and thus the DTW distance will be zero! And so, DTW does not penalize this kind of stretching.
But, now consider a second example:
s1 = [1 4 7];
s2 = [1 3 5 7];
This is stretched as well. However, this is now done by interpolation (which might be a more normal kind of stretching, e.g. speech) the error matrix will now become:
error = [0 3 6;...
3 1 3;...
4 1 2;...
6 3 0]; % s1 horizontally, s2 vertically
Now there doesn't exist a path with only zeros! the minimum DTW distance (the sum of all errors on a path from upper left to bottom right) will be 2 in this case.
So: However the signals are stretched versions of each other, DTW didn't penalize the stretching itself. But DTW penalized that both signals have different sample values. Therefore, you cannot penalize this stretch any differently as differences in the signals not due to a stretch.
Hope this helps!
  1 Comment
Mac Fuirdmith
Mac Fuirdmith on 4 Oct 2016
Ok, thanks for that answer. So there should be no penalties for stretching. Would it be possible to include such penalties nonetheless ? (without further workaround like looking up the matching paths and counting stretches)

Sign in to comment.

More Answers (1)

Greg Dionne
Greg Dionne on 21 Oct 2016
Have you tried EDR? It penalizes stretching.
It might be helpful to post the data you are trying to compare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!