Search code examples
pythonsignal-processinginterpolationsamplingphase

Interpolating measured sine wave using python


I have 2 sampled sine waves obtained as a measurement from a DSO. The sampling rate of the DSO is 160 GSa/s and my signal is 60 GHz. I need to find the phase difference between the two sine waves. Both are the same frequency. However, the sampling rate is not enough to accurately determine the phase. Is there any way to interpolate the measured signal to get a better sine wave and then calculate the phase difference?


Solution

  • You may fit to sine functions, but for the phase difference (delta phi=2pi frequency delta t) it would be sufficient to detect and compare the zero-crossings (respective a possible constant offset), which may be found from a segment of your series by an interpolation like

    w=6.38    # some radian frequency
    t = np.linspace(0, 0.5)   # time interval containing ONE zero-crossing
    delta_phi=0.1   # some phase difference
    x = np.sin(w*t-delta_phi)    # x(t)
    f = interpolate.interp1d(x, t)     # interpolate t(x), default is linear 
    delta_t = f(0)    # zero-crossing time referred to t=0
    delta_phi_detected= w*delta_t
    

    You need to relate two adjacent zero-crossings of your signals.

    Alternatively, you may obtain an average value by multiplication of both signals and numerical integration over time T which converges to (T/2)cos(delta_phi), if both signals have (or are made to) zero mean value.