[Numpy-discussion] phase unwrapping (1d)

Neal Becker ndbecker2@gmail....
Fri Jan 11 09:40:39 CST 2013


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;
  }




More information about the NumPy-Discussion mailing list