[Numpy-discussion] phase unwrapping (1d)

Pierre Haessig pierre.haessig@crans....
Mon Jan 14 07:08:34 CST 2013


Hi Neal,

Le 11/01/2013 16:40, Neal Becker a écrit :
> I wanted to be able to handle the case of
>
> unwrap (arg (x1) + arg (x2))
>
> Here, phase can change by more than 2pi.
It's not clear to me what you mean by "change more than 2pi" ? Do you
mean that the consecutive points of in input can increase by more than
2pi ? If that's the case, I feel like there is no a priori information
in the data to detect such a "giant leap".

Also, I copy-paste here for reference the numpy.wrap code from [1] :

def unwrap(p, discont=pi, axis=-1):
    p = asarray(p)
    nd = len(p.shape)
    dd = diff(p, axis=axis)
    slice1 = [slice(None, None)]*nd # full slices
    slice1[axis] = slice(1, None)
    ddmod = mod(dd+pi, 2*pi)-pi
    _nx.copyto(ddmod, pi, where=(ddmod==-pi) & (dd > 0))
    ph_correct = ddmod - dd;
    _nx.copyto(ph_correct, 0, where=abs(dd)<discont)
    up = array(p, copy=True, dtype='d')
    up[slice1] = p[slice1] + ph_correct.cumsum(axis)
    return up

I don't know why it's too slow though. It looks well vectorized.

Coming back to your C algorithm, I'm not C guru so that I don't have a
clear picture of what it's doing. Do you have a Python prototype ?

Best,
Pierre

[1]
https://github.com/numpy/numpy/blob/master/numpy/lib/function_base.py#L1117

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 900 bytes
Desc: OpenPGP digital signature
Url : http://mail.scipy.org/pipermail/numpy-discussion/attachments/20130114/4f1db7cc/attachment.bin 


More information about the NumPy-Discussion mailing list