MATLAB: Calculate shifts/translation between two curves

curveshifttranslationxcorr

Dear all,
Is there a way to determine if the blue curve has shifted from the purple curve? (see graph). As you can see, before the black line the blue curve shifts to the right of the purple one and after the black line the curve shifts to the left. Is there a way to do an analysis that tells us this? Maybe a separate analysis of regions that tells us the shift of the curve? I have seen that the xcorr command is used to measure displacements, but in a generalized way. When I apply it to this case, the maximum lags are zero.
Thanks in advance!

Best Answer

The blue curve is not ‘shifting’. It has a different scale with respect to the independent variable than the purple curve. The correct way to characterise it would be to compare the characteristics of the two curves.
For example —
x = linspace(-100, 100);
yb = 1./(1+exp(-0.1*x));
yp = 1./(1+exp(-0.05*x));
ratio = mean(gradient(yb)./gradient(x)) / mean(gradient(yp)./gradient(x));
figure
plot(x, yb, '-b')
hold on
plot(x, yp, '-m')
hold off
grid
Here, the ‘ratio’ metric compares the means of the numeric derivatives (calculated by the the gradient function) to characterise them. I am certain there are more appropriate metrics for your curves, however something like that would likely be more appropriate than measuring a ‘shift’ that is actually not a shift.