Calculate shifts/translation between two curves

16 ビュー (過去 30 日間)
Angelavtc
Angelavtc 2020 年 10 月 21 日
コメント済み: Star Strider 2020 年 10 月 23 日
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!

採用された回答

Star Strider
Star Strider 2020 年 10 月 21 日
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.
  5 件のコメント
Angelavtc
Angelavtc 2020 年 10 月 23 日
@Star Strider, thank you for your answer! Do you have any idea why when I use the finddelay function in the attached data, the answer is 0? Even when there is a clear shift to the right on my data? Both codes give me zero :(
finddelay(x1,x2)
finddelay(y1,y2)
Star Strider
Star Strider 2020 年 10 月 23 日
As always, my pleasure!
The problem is that there does not appear to be much difference between the signals, at least with respect to the indices. The finddelay funciton assumes that one signal is zero-padded with respect to the other, and the related functions also assume a common independent variable vector. Also, the independent variable vectors are not only not common, they also have different sampling intervals and ranges.
That is most evident with:
[S1,L1] = bounds(x1);
[S2,L2] = bounds(x2);
range_x1 = L1-S1
range_x2 = L2-S2
producing:
range_x1 =
9666
range_x2 =
16096
even though they have the same number of elements(30000 each).
so likely the best you can hope for is:
delay = min(x2)-min(x1)
producing:
delay =
3257
assuming that the units of the independent variables are the same (for example, seconds).
One function you can experiment with is dtw that measures the distance between signals using ‘dynamic time warping’:
[disty,ix,iy] = dtw(y1,y2);
figure
dtw(y1,y2)
I defer to you to interpret the results, sdince I do not know what your signals are.
.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by