Approach to Determine Short-Term Delay Between Two Signals If I have two signals(image) $A$ and $B$, how to determine their displacement(shift) by using a specific window size and search length? Figure below show two signals(green and red) with the locally matched displacement(blue, in pixels) using window of size $18$ pixels and search length of $10$ pixels both ways. 



How to perform this operation in MATLAB? Can the imabsdiff function in MATLAB do this?

Partial code:

A=rand(1,300);
B=rand(1,300);

plot(A);
hold on;
plot(B);
plot(imabsdiff(A,B));


Portion of actual data:

A=[8867.57405148489 9402.91911342364    9260.13066495026    9345.56275526595    9066.54029280105    8894.01936371044    8412.68945486749    8919.64865493583    8727.95696825579    9074.89217283470    9608.00631088673    9705.23552482552    9925.36706001762    10527.5169206531    10771.2414339404    10191.8372768611    10521.7823136932    10582.8872241675    10343.1075045963    9769.05178493597];

B=[9158.03544409186 9429.74701058754    9528.06160406599    9236.34072710901    9183.22768932609    8956.44915466926    8429.70083898040    9144.08305356044    9093.35936685047    8833.96896404156    9507.13829962295    9773.79833257334    10153.9486443920    10251.5748622237    10352.4685365480    9949.82669971615    10202.3036826683    10557.1335972593    10497.4113150230    10159.5236764117];


Thanks in advance!
Unless I misunderstood completely, you are looking for the lag between the two waveforms red and green over smaller windowed intervals of that function as the window is moved over the sequence? In this case it can simply be done with a moving window using the following function in Matlab:

[corr, lag] = xcorr(a,b)


This will return the cross-correlation as corr, and the lag variable is the delay between a and b associated with each cross correlation.

Given you want to do this as a moving window, that can be achieved by setting a window size and index, and then index the window through your data:

Note this may be pseudo code below as I haven't tested the actual code written, but should give you the idea, as shown is a moving window of size K indexing 1 sample at a time, and will compute the relative delay between the waveforms within the window view.

x= green-mean(green);    % remove mean
x=x(:)';                 % ensure row vector
y = red-mean(red);
y=y(:)';
[~,n]=size(x);

for shift = 1:n-K    % ensure x and y same size
 xwin= x(shift:shift+K); % K is the window size
 ywin= y(shift:shift+K);
 [corr,lag]= xcorr(xwin,ywin);
 disp(shift)= lag(corr==max(corr));
end 


If this is on track to what you are looking for, I would also consider normalizing the correlation by the standard deviation of the two waveforms within each window, thus giving you the correlation coefficient. This could allow for the option of optimally weighting the results for estimation of overall delay (or ignoring regions where the match was poor etc).