function [X] = motiondecorr(X,Y)

[n, m]=size(Y);
%*****************************************************************
% Decorrelate between X and Y 
l=n;
if n>m
    X=X';Y=Y';
    l=min([n m]);
end;

for ii=1:l
    Cua = nancov1(detrend(X),detrend(Y(ii,:)));
    muua = Cua(1,2)/Cua(2,2);
    X = X- muua*detrend(Y(ii,:));
end
%*****************************************************************

