# Phase Unwrapping Behaving Oddly For Optics Simulation

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:

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:

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):

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.

• but you eliminate the $\pi$ jumps intentionally with np.unwrap, or am I missing something? Jun 21, 2023 at 16:52
• @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 Jun 21, 2023 at 17:00
• 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?
– Peter K.
Jun 21, 2023 at 17:49
• @PeterK. ahh that makes sense, thank you. I've edited my post accordingly. Jun 21, 2023 at 18:25
• 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 ? Jun 21, 2023 at 18:58