In short, I am coding an optics simulation for an experiment I am running. There is a point where I perform a Fourier transform on my incoming signal and want to extract the phase; however, I get unexpected results.

More specifically, I want to unwrap the phase from the signal below:

enter image description here To extract the phase I use the following function:

def phase_extractor(fourier, t_max, t):     
    phase = np.angle(fourier)
    # Unwrap the phase to remove jumps or discontinuities
    phase_spectrum = np.unwrap(phase)
    #proper_phase = torch.from_numpy(phase_realtime)
    return phase_spectrum 

Ignore the t_max and t inputs - they aren't of interest for now

After running the function on this input data and simply plotting the phase spectrum, I get the following result:

enter image description here

I was expecting it to have discrete steps at pi intervals (i.e., it would look like a staircase with steps of height pi).

So far in terms of debugging, I have done the following:

  1. After using np.angle() I checked the difference between consecutive elements in a list and the maximum was pi, so that tells me resolution isn't an issue.
  2. I've tried doing an fftshift of my data so that unwrapping starts at the zero-frequency; however that doesn't change much - the only notable difference is a small bump in the centre of the output.

If anyone knows about phase unwrapping and could help me out that'd be great. I am not too familiar with phase unwrapping and have had some major difficulty debugging this

Edit: Sorry for any clarity issues, this is very crudely what I was expecting (i.e., a staircase type function with height of ~pi):

enter image description here

Edit #2:

Here is the original signal - note I am trying to get the information from the target. Also, regarding the phase plot, y-axis is the phase in radians and the x-axis is simply the array index. enter image description here

  • $\begingroup$ but you eliminate the $\pi$ jumps intentionally with np.unwrap, or am I missing something? $\endgroup$ Jun 21, 2023 at 16:52
  • $\begingroup$ @MarcusMüller, No... isn't the point of phase unwrapping to view that behaviour? Also when I remove the np.unwrap I just get two blobs which doesn't make much sense $\endgroup$
    – user68185
    Jun 21, 2023 at 17:00
  • 1
    $\begingroup$ Welcome to SE.SP! As Marcus says, the point of np.unwrap is to remove the +/- $\pi$ jumps in the phase that happen because complex number phase can only usually be found within the range $[-\pi,+\pi)$, but complex functions of, say, frequency have phases that vary over a much larger range. Can you please include a (perhaps hand-drawn) plot of what you're expecting to see? $\endgroup$
    – Peter K.
    Jun 21, 2023 at 17:49
  • $\begingroup$ @PeterK. ahh that makes sense, thank you. I've edited my post accordingly. $\endgroup$
    – user68185
    Jun 21, 2023 at 18:25
  • $\begingroup$ Your axis aren't labelled so I can't tell with the phase is in radians or degrees. In any case, it's a mostly linear phase which probably means that your time signal isn't centered round zero. You can post your signal before the FFT ? $\endgroup$
    – Hilmar
    Jun 21, 2023 at 18:58


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.