Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamic Time Warping for geology time series, Matlab
    text
    copied!<p>Background: Basically I'm using a dynamic time warping algorithm like used in speech recognition to try to warp geological data (filter out noise from environmental conditions) The main difference between these two problems is that dtw prints a warping function that allows both vectors that are input to be warped, whereas for the problem I'm trying to solve I need to keep one reference vector constant while stretching and shrinking the test variable vector to fit. </p> <p>here is dtw in matlab:</p> <pre><code>function [Dist,D,k,w]=dtw() %Dynamic Time Warping Algorithm %Dist is unnormalized distance between t and r %D is the accumulated distance matrix %k is the normalizing factor %w is the optimal path %t is the vector you are testing against %r is the vector you are testing [t,r,x1,x2]=randomtestdata(); [rows,N]=size(t); [rows,M]=size(r); %for n=1:N % for m=1:M % d(n,m)=(t(n)-r(m))^2; % end %end d=(repmat(t(:),1,M)-repmat(r(:)',N,1)).^2; %this replaces the nested for loops from above Thanks Georg Schmitz D=zeros(size(d)); D(1,1)=d(1,1); for n=2:N D(n,1)=d(n,1)+D(n-1,1); end for m=2:M D(1,m)=d(1,m)+D(1,m-1); end for n=2:N for m=2:M D(n,m)=d(n,m)+min([D(n-1,m),D(n-1,m-1),D(n,m-1)]); end end Dist=D(N,M); n=N; m=M; k=1; w=[]; w(1,:)=[N,M]; while ((n+m)~=2) if (n-1)==0 m=m-1; elseif (m-1)==0 n=n-1; else [values,number]=min([D(n-1,m),D(n,m-1),D(n-1,m-1)]); switch number case 1 n=n-1; case 2 m=m-1; case 3 n=n-1; m=m-1; end end k=k+1; w=cat(1,w,[n,m]); end w=flipud(w) %w is a matrix that looks like this: % 1 1 % 1 2 % 2 2 % 3 3 % 3 4 % 3 5 % 4 5 % 5 6 % 6 6 </code></pre> <p>so what this is saying is that the both the first and second points of the second vector should be mapped to the first point of the first vector. i.e. 1 1 1 2 and that the fifth and sixth points on the first vector should be mapped to the second vector at point six. etc. so w contains the x coordinates of the warped data.</p> <p>Normally I would be able to say</p> <pre><code>X1=w(:,1); X2=w(:,2); for i=1:numel(reference vector) Y1(i)=reference vector(X1(i)); Y2(i)=test vector(X2(i)); end </code></pre> <p>but I need not to stretch the reference vector so I need to use the repeats in X1 to know how to shrink Y2 and the repeats in X2 to know how to stretch Y2 rather than using repeats in X1 to stretch Y1 and repeats in X2 to stretch Y2.</p> <p>I tried using a find method to find the repeats in both X1 and X2 and then average(shrink) or interpolate linearly(stretch) as needed but the code became very complicated and difficult to debug.</p> <p>Was this really unclear? I had a hard time explaining this problem, but I just need to know how to take w and create a Y2 that is stretched and shrunk accordingly. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload