extracting phase information using numpy fft

后端 未结 2 827
野性不改
野性不改 2021-02-14 09:10

I am trying to use a fast fourier transform to extract the phase shift of a single sinusoidal function. I know that on paper, If we denote the transform of our function as T, th

相关标签:
2条回答
  • 2021-02-14 09:59

    The phase value in the result bin of an unrotated FFT is only correct if the input signal is exactly integer periodic within the FFT length. Your test signal is not, thus the FFT measures something partially related to the phase difference of the signal discontinuity between end-points of the test sinusoid. A higher sample rate will create a slightly different last end-point from the sinusoid, and thus a possibly smaller discontinuity.

    If you want to decrease this FFT phase measurement error, create your test signal so the your test phase is referenced to the exact center (sample N/2) of the test vector (not the 1st sample), and then do an fftshift operation (rotate by N/2) so that there will be no signal discontinuity between the 1st and last point in your resulting FFT input vector of length N.

    0 讨论(0)
  • 2021-02-14 10:07

    Your points are not distributed equally over the interval, you have the point at the end doubled: 0 is the same point as 1. This gets less important the more points you take, obviusly, but still gives some error. You can avoid it totally, the linspace has a flag for this. Also it has a flag to return you the dt directly along with the array.

    Do

    t, dt = np.linspace(0, 1, num_t, endpoint=False, retstep=True)
    

    instead of

    t = np.linspace(0,1,num_t)
    dt = 1.0/num_t
    

    then it works :)

    0 讨论(0)
提交回复
热议问题