Unwrap angle to have continuous phase

给你一囗甜甜゛ 提交于 2019-12-22 07:39:12

问题


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:


回答1:


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)




回答2:


From the doc of np.unwrap:

Unwrap radian phase p by changing absolute jumps greater than discont 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.pi

plt.figure()

plt.subplot(1, 2, 1)
plt.plot(phase)

plt.subplot(1, 2, 2)
plt.plot(np.unwrap(phase))




回答3:


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.



来源:https://stackoverflow.com/questions/52293831/unwrap-angle-to-have-continuous-phase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!