This type of question has been asked quite a few times on this forum and others now, but I still haven't found a satisfactory answer to my problem.
Given an input signal: $$x_1(t)=\cos\big(2\pi ft\big)$$ A process derives an output signal: $$x_2(t)=\cos\big(2\pi (f+b)t+\phi\big)$$ My objective is to determine the phase lag $\phi$.
$b$ is an unknown perturbation to the input frequency very close to 0 due to the mechanical nature of the process. For example, a human trying to track this signal.
If the perturbation is exactly zero, I'm able to use cross spectral density to determine the phase lag. However, if the perturbation is even 0.1% of the original frequency, then my answer is totally erroneous.
For example, in Python:
import numpy as np Fs = 1000 t = np.arange(0,1,1/Fs) x1 = np.cos(2*np.pi*100*t) x2 = np.cos(2*np.pi*100.1*t + np.pi/4) dft1 = np.fft.fft(x1); dft1 = dft1[0:int(n/2)+1]/Fs; dft2 = np.fft.fft(x2); dft2 = dft2[0:int(n/2)+1]/Fs; n = len(t) f = np.multiply(range(0,int(n/2)+1), Fs/n) csd = np.conj(dft1)*dft2 print(np.rad2deg(np.angle(csd[abs(csd)>0.05])))
Expect 45 but get 62.9 instead.
I've tried Hilbert transform and straight fft. Any idea?