[Numpy-discussion] phase unwrapping (1d)

Nadav Horesh nadavh@visionsense....
Mon Jan 14 00:21:36 CST 2013

There is an unwrap function in numpy. Doesn't it work for you?

From: numpy-discussion-bounces@scipy.org [numpy-discussion-bounces@scipy.org] on behalf of Neal Becker [ndbecker2@gmail.com]
Sent: 11 January 2013 17:40
To: numpy-discussion@scipy.org
Subject: [Numpy-discussion] phase unwrapping (1d)

np.unwrap was too slow, so I rolled by own (in c++).

I wanted to be able to handle the case of

unwrap (arg (x1) + arg (x2))

Here, phase can change by more than 2pi.

I came up with the following algorithm, any thoughts?

In the following, y is normally set to pi.
o points to output
i points to input
nint1 finds nearest integer

  value_t prev_o = init;
  for (; i != e; ++i, ++o) {
    *o = cnt * 2 * y + *i;
    value_t delta = *o - prev_o;

    if (delta / y > 1 or delta / y < -1) {
      int i = nint1<int> (delta / (2*y));
      *o -= 2*y*i;
      cnt -= i;

    prev_o = *o;

NumPy-Discussion mailing list

More information about the NumPy-Discussion mailing list