Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K
JAX  documentation - Home

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 ofnumpy.unwrap().

Parameters:
  • p (ArrayLike) – input array

  • discont (ArrayLike |None) – the maximum allowable discontinuity in the sequence. Thedefault isperiod/2

  • axis (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 ofp.

Return type:

Array

Notes

This implementation follows that ofnumpy.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 thex andy locations 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 thex andy coordinates, 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 thesex andy coordinates, 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 angletheta above, but after this thevalues are wrapped because thesin andcos observations 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 thandiscont (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.

Contents

[8]ページ先頭

©2009-2025 Movatter.jp