Dynamic Time Warp DTW of a 2D path

4 views (last 30 days)
ShDoran
ShDoran on 18 Feb 2020
Commented: Ines on 5 Dec 2023
I want to compute the spatial dissimilarity between two paths through 2D space, but warping them to allow for different temporal dynamics.
I receive these two paths as 2-by-N matrices, with the 2 rows describe the X and Y coordinate of 2D spatial samples taken at each column (1 to N), sampled across columns (time) with the same frequency (fs).
I think dynamic time warping (dtw function) is the way to do this?
However in the below example, two paths (path1 and path2) have the same sampling rate (fs) and operate over different lengths of time (T1 and T2). But given that they have identical exponential curvature, the warping should be able to resample them to a euclidean distance of 0, but this is not the case?
fs = .01;
T1 = 2.5;
T2 = 2;
X_path1 = 0:fs:T1;
Y_path1 = (0:fs:T1).^2;
path1 = [X_path1;Y_path1];
X_path2 = (0:fs:T2);
Y_path2 = (0:fs:T2).^2;
path2 = [X_path2;Y_path2];
subplot(211);
hold on;
p(1) = plot(X_path1,Y_path1,'bo');
p(2) = plot(X_path2,Y_path2,'yx');
legend([p(1) p(2)],'path1 orig','path2 orig','Location','NorthWest');
[dist_path1path2,XI,YI] = dtw(path1,path2);
subplot(212);
hold on;
p(1) = plot(path1(1,XI),path1(2,XI),'bo');hold on;
p(2) = plot(path2(1,YI),path2(2,YI),'yx');
legend([p(1) p(2)],'path1 warped','path2 warped','Location','NorthWest');
title(['distance = ',num2str(dist_path1path2)]);
  1 Comment
Ines
Ines on 5 Dec 2023
I am also trying to compare 2D paths. By any chance, did you solve your problem ?
I would like to visualize my paths after wrapping.
Thanks

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!