Bin wise phase difference using FFT - 2pi shifts even after using phase unwrapping

StackOverflow https://stackoverflow.com/questions/22242791

  •  10-06-2023
  •  | 
  •  

Question

I have looked at similar questions on StackOverflow and none seem to address this specifically.

I am trying to find the bin wise phase difference between two signals. To validate if this result is usable the I have introduced a single sample delay between the two signals.

Something like this:

    ch1 = randn(frame_length * 100, 1);
    ch2 = [0 ; ch1(1:end-1) ];

Thereafter I window the signal, take the FFT and plot the phase diff. Like this:

    phase_1 = unwrap(arg(bin_wise_struct.fft_out_ch1));
    phase_2 = unwrap(arg(bin_wise_struct.fft_out_ch2));
    phase_diff = (phase_1 - phase_2);

However I notice that the final phase difference has random jumps of 2*pi. I would like to know why's this happening despite unwrapping the phase of the original signals.

Was it helpful?

Solution

If you don't center the FFT phase reference to the center of the aperture (by using fftshift), rather than the front/back edge, then the phase of any signal discontinuity (between the beginning and end of the FFT aperture) alternates between FFT result bins.

An unwrap will possibly take the sign flip and add 2pi.

The phase sign alternates because the FFT is trying to measure the phase of the Sinc function that represents a rectangular window on any non-periodic-in-aperture data. An fftshift "twists" the complex Sinc function so it's phase no longer alternates.

Try your phase comparison using an fftshift (either pre-fft data rotation or post-fft alternate sign flipping), and see if that produces more reliable phase offset results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top