jax.numpy.unwrap
Contents
jax.numpy.unwrap#
- jax.numpy.unwrap(p,discont=None,axis=-1,period=6.283185307179586)[source]#
Unwrap a periodic signal.
JAX implementation of
numpy.unwrap().- Parameters:
p (ArrayLike) – input array
discont (ArrayLike |None) – the maximum allowable discontinuity in the sequence. Thedefault is
period/2axis (int) – the axis along which to unwrap; defaults to -1
period (ArrayLike) – the period of the signal, which defaults to\(2\pi\)
- Returns:
An unwrapped copy of
p.- Return type:
Notes
This implementation follows that of
numpy.unwrap(), and is notwell-suited for integer-period unwrapping of narrow-width integers(e.g.int8,int16) or unsigned integers.Examples
Consider a situation in which you are making measurements of the position ofa rotating disk via the
xandylocations of some point on that disk.The underlying variable is an always-increasing angle which we’ll generatethis way, using degrees for ease of representation:>>>rng=np.random.default_rng(0)>>>theta=rng.integers(0,90,size=(20,)).cumsum()>>>thetaarray([ 76, 133, 179, 203, 230, 233, 239, 240, 255, 328, 386, 468, 513, 567, 654, 719, 775, 823, 873, 957])
Our observations of this angle are the
xandycoordinates, given bythe sine and cosine of this underlying angle:>>>x,y=jnp.sin(jnp.deg2rad(theta)),jnp.cos(jnp.deg2rad(theta))
Now, say that given these
xandycoordinates, we wish to recoverthe original angletheta. We might do this via theatan2()function:>>>theta_out=jnp.rad2deg(jnp.atan2(x,y)).round()>>>theta_outArray([ 76., 133., 179., -157., -130., -127., -121., -120., -105., -32., 26., 108., 153., -153., -66., -1., 55., 103., 153., -123.], dtype=float32)
The first few values match the input angle
thetaabove, but after this thevalues are wrapped because thesinandcosobservations obscure the phaseinformation. The purpose of theunwrap()function is to recover the originalsignal from this wrapped view of it:>>>jnp.unwrap(theta_out,period=360)Array([ 76., 133., 179., 203., 230., 233., 239., 240., 255., 328., 386., 468., 513., 567., 654., 719., 775., 823., 873., 957.], dtype=float32)
It does this by assuming that the true underlying sequence does not differ by more than
discont(which defaults toperiod/2) within a single step, and when it encountersa larger discontinuity it adds factors of the period to the data. For periodic signalsthat satisfy this assumption,unwrap()can recover the original phased signal.
