function Xlagflag = findlagPositive(X,Y,maxlags,plotit)
% computes lag for maximum positive correlation betseen X and Y
% LB  
ii = find(isfinite(X) & isfinite(Y));
[XYcorr,xlags] = xcov(Y(ii),X(ii),maxlags,'coeff');
[~,maxXLagIndex] = max(XYcorr);
Xlagflag = maxXLagIndex-maxlags-1;

% Positive lagflag means Y is delayed compared to X .
if plotit
    figure; plot(xlags,XYcorr);grid
end
