沿水平方向对齐曲线

Aligning curves along the horizontal direction

我有一些'n'相同实验条件下的实验曲线。由于系统固有的热漂移,数据集彼此之间并不完全对齐。我正在寻找一种可以为我调整数据曲线的稳健算法。

这是我到目前为止尝试过的:

x = linspace(1,100,1000);
y = tanh(0.09*x) ; figure; plot(x,y)
y1 = tanh(0.09*(x+10)) ; hold on; plot(x,y1)
y2 = tanh(0.09*(x-10)) ; hold on; plot(x,y2)

曲线看起来像这样:

这就是我想要得到的:

(这里我将曲线 y1y2 对齐到曲线 y 的顶部)


我认为互相关可以帮助我对齐数据。所以我尝试了:

[cc,lag] = xcorr(y,y1,'none');
[~,ind] = max(cc);
sh = lag(ind);

但这给了我 sh=0.

有更好的方法吗?

这是我关于如何解决这个问题的想法,使用 "reverse" 插值(在通常我们想要找到对应于某些 xy 值的意义上相反,但这里正好相反):

function q51282667
%% Generate data:
x = linspace(1,100,1000);
y{1} = tanh(0.09*x) ; 
y{2} = tanh(0.09*(x+10));
y{3} = tanh(0.09*(x-10));
% ^ y,y1,y2 are not necessarily the same length so I used a cell and not a numeric array

%% Find alignment:
% Establish a baseline: the curve with the largest vertical extent:
[~,mxi] = sort(cellfun(@max,y) - cellfun(@min,y), 'descend');
% Reverse interpolation using y-values:
ny = numel(y);
deltaX = zeros(ny,1);
for indY = 1:ny
  deltaX(indY) = interp1(y{mxi(1)}, x, y{indY}(1)) - x(1);
end

%% Plot:
% Original:
figure(); plot(x, y{1}, x, y{2}, x, y{3}); % this is the same as your example
% Shifted:
figure(); plot(x + deltaX(mxi(1)), y{mxi(1)}, ...
               x + deltaX(mxi(2)), y{mxi(2)}, ...
               x + deltaX(mxi(3)), y{mxi(3)});

导致:

deltaX = 

  10.0000063787562
  20.0000993310027
  0

和: