Search code examples
pythonnumpysignal-processingcomplex-numbersphase

Unwrap angle to have continuous phase


Let's say I have an array of phases similar to this:

import numpy as np
import matplotlib.pyplot as plt
phase = np.linspace(0., 100., 1000) % np.pi
plt.plot(phase)
plt.show()

(with many discontinuities like this)

How to get an array of more "continuous" phases from it?

Of course, I already tried with np.unwrap:

plt.plot(np.unwrap(phase))

or

plt.plot(np.unwrap(phase),discont=0.1)

but it stays exactly similar:

What I expected was an unwrapping like this:

enter image description here


Solution

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