I am trying to find the time lag between two time series over t = [0,1000] using MATLAB (not that it matters). The first time series is simply t^2. The second is (t-15)^2 which is, of course, shifted to the right 15 units (e.g., seconds). My approach has been to find the cross correlation (computed using FFT) and then use the maximum of these to determine the appropriate time shift. For some reason, the answer I keep getting is 0, which doesn't make any sense. Can anyone tell me what I'm doing wrong? Thanks!
I've calculated the cross correlation using FFT as shown (all code is in MATLAB; note fft is the Fast Fourier Transform function and ifft is the inverse Fast Fourier Transform function):
t = [1:1000]; a = t.^2; b = (t-15).^2; if (length(a) < length(b)) c = [zeros(1,length(b)-1) a zeros(1,length(b)-length(a))]; d = [b zeros(1,length(b)-1)]; else c = [zeros(1,length(a)-1) a]; d = [b zeros(1,length(a)-length(b)+length(a)-1)]; end c_fft = fft(c); d_fft = fft(d); cross_spectral_density = c_fft.*conj(d_fft); cross_correlations = ifft(cross_spectral_density); [max_xcorr shift_idx] = max(abs(cross_correlations)); shift = shift_idx - max(length(a),length(b));