沿水平方向对齐曲线

时间:2018-07-11 10:04:23

标签: matlab alignment overlap curves sequence-alignment

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

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

name

曲线如下:

enter image description here

这就是我想要得到的:

Expected output

(在这里,我将曲线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) y1对准了曲线y2的顶部)


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

y

但这给了我[cc,lag] = xcorr(y,y1,'none'); [~,ind] = max(cc); sh = lag(ind);

有更好的方法吗?

1 个答案:

答案 0 :(得分:1)

这是我使用“反向”插值方法的想法(反向通常意味着我们想找到与某些y对应的x值,但是这是另一种方法左右):

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

和:

Desired output