Unwrap angle to have continuous phase
If you want to keep your original phase with pi-periodicity, you should first double it, unwrap it, then divide it by two:
plt.plot(np.unwrap(2 * phase) / 2)
My problem came from that fact I had a 2D array (n,1)
(without noticing it) in my real code, instead of a 1D array of length n
. Then the parameter axis
:
np.unwrap(phase, axis=0)
solved it.
The other answers are still useful because of 2 pi
vs. pi
question.
From the doc of np.unwrap
:
Unwrap radian phase
p
by changing absolute jumps greater thandiscont
to their 2*pi complement along the given axis.
But the 2*pi complement of all the elements in your vector are the values themselves since no value is every > 2*pi.
Try this:
phase = np.linspace(0., 20., 1000) % 2*np.piplt.figure()plt.subplot(1, 2, 1)plt.plot(phase)plt.subplot(1, 2, 2)plt.plot(np.unwrap(phase))