check phase measurement

t = linspace(0,8,501);
period = 3.0;
wt = 2*pi*t/period;
y1 = sin(wt);
y2 = sin(wt-pi/4);
subplot(2,1,1);
n = length(t);
idx =find(y1(1:n-1)<0 & y1(2:n)>0);
k = idx(1);
t1 = t(k);
plot(t,y1,[t(k) t(k)],[-1 1],'k--');
ylabel('v1');
subplot(2,1,2);
idx =find(y2(1:n-1)<0 & y2(2:n)>0);
k = idx(2);
t2 = t(k);
plot(t,y2,[t(k) t(k)],[-1 1],'k--');
xlabel('time');
ylabel('v2');
diff = (t2-t1)/period;
fprintf('phase(1->2) %g degrees\n',diff*360);
phase(1->2) 44.16 degrees