I have a problem with phase measuring.
I'm acquiring two signal with a USRP (complex signals) with a coherent generator and I want to measure the phase different between them.. One is at 150Mhz and the other one at 400MHz. When I plot the signals I see they are 150Mhz + 8Hz and 400Mhz + 50 hz, because of the way the daugtherboard works not tunning the correct frequency, which is the error I'm trying to measure.
Like these are two different frequencies I have take them to same frequency so I multiply by 8 and by 3 to measure the phase at 1.2GHz. Also, like these are different frequencies, I expect the phase to be a rect line with a slope.
I'm doing it by two ways:
First way is to get the DFT and extract the phase of the bin with the maximum power and plot it.
$$ 2\pi t(f_1+\Delta f_1) + \phi_1= \mbox{phase}(\text{150MHz}) $$ $$ 2\pi t(f_2+\Delta f_2) + \phi_2 = \mbox{phase}(400\text{MHz}) $$
as $$ 8f_1 = 3f_2 $$the phase difference should be $$ \mbox{unwrap}(2\pi (8\Delta f_1 - 3\Delta f_2) t + 8\phi_1-3\phi_2) $$ So it should be $$(540.08 t + \phi_1-\phi_2)$$
This way gives me this plot.
plot(time,phase)
Second way is I get the DFT, identify the maximum power bin and I set all the others bins to zero, then I get the IDFT.
The ifft gives me the two complex signals $$ x=e^{(2\pi t(f_1+\Delta f_1)+\phi_1)j} $$ and $$ y=e^{(2\pi t(f_2+\Delta f_2)+\phi_2)j} $$ then
$$\mbox{unwrap}(\mbox{angle}(x^8/y^3))$$
This way gives me this plot.
plot(time,phase)
Problem is that I get two really different results.
So which method is correct and why? The second way seems more accurate but why the expected values are so different?
--Edit-- Code:
for i in range(0,(nsfft)):
#nsfft contains the numbers of fft availables (17)
#nfft contains the number of point for fft (8192)
#noffset = nfft
#_fft400,_fft150,P400,P150,_ifft150,_ifft400 are 2d array
ser = buf400[noffset*i:noffset*i+nfft] #reading data
_fft400[i] = fftshift(fft(ser))/nfft #fourier of 400Mhz
ser = buf150[noffset*i:noffset*i+nfft] #reading data
_fft150[i] = fftshift(fft(ser))/nfft #fourier of 150MHz
P400[i] = Px(_fft400[i]).real #power
P150[i] = Px(_fft150[i]).real #power
#narrow filtering for second way
_fft150[i,argmax(P150[i])+2:] = 0j
_fft150[i,:argmax(P150[i])-2] = 0j
_fft400[i,argmax(P400[i])+2:] = 0j
_fft400[i,:argmax(P400[i])-2] = 0j
######
_ifft400[i] = (ifft(ifftshift(_fft400[i]))) #IFFT for secondway
_ifft150[i] = (ifft(ifftshift(_fft150[i])))
phase400[i] = angle(_fft400[i][argmax(P400[i])])*3 #first way
phase150[i] = angle(_fft150[i][argmax(P150[i])])*8 #first way
phase_difference2 = zeros(nsfft*nfft)
for i in range(nsfft):
phase_difference2[i*nfft:i*nfft+nfft] = angle((_ifft400[i] ** 3)/(_ifft150[i] ** 8))
phase_difference = phase400 - phase150
phase_difference = unwrap(phase_difference)
time = np.linspace(0,read_sec,nsfft)
time2 = arange(0,nsfft*nfft)/sample_f
plt.plot(time,phase_difference)
plt.plot(time2,unwrap(phase_difference2))
Also the data has been decimated from 400Ksps to 5Ksps