## Copyright (C) 2006 Robert T. Short ## ## usage: [d]=delayCorrelate(d1,d2) ## ## Estimate the delay between times series 'd1' and time series 'd2' by ## correlating and finding the peak. The index of the peak correlation ## is returned in 'd'. ## ## Author: Robert T. Short (address@hidden) ## Description: Delay Correlate. function [d,c]=delayCorrelate(d1,d2) % Check arguments and set defaults. if( (nargin<2) | (nargin>2) ) usage('[d]=delayCorrelate(d1,d2)'); end % Make everything a column vector, then get the lengths. d1 = d1(:); d2 = d2(:); N1 = length(d1); % total data length N2 = length(d2); % c = zeros(N2-N1+1,1); for (idx = 1:N2-N1) c(idx) = d1'*d2(idx:idx+N1-1)/N1; end [m,d] = max(abs(c)); end