%
%  shcorrfn - function called by "shcorr" to
%             determine the optimal shift
%
%  Bob Newell, April 1996
%
%------------------------------------------------
function crit = shcorrfn( k )
global data
%
k = fix( k );
% calculate the shift
[ n, m ] = size( data );
% determine the correlation coefficients
if k < 0,
  cor = corrcoef( [ data(1:n+k,1) data(-k+1:n,2) ] );
else,
  cor = corrcoef( [ data(k+1:n,1) data(1:n-k,2) ] );
end;
% criterion is one minus cross correlation
crit = 1 - cor(1,2);
return;
%-------------------------------------------------
