r""" Unwrap by taking the complement of large deltas with respect to the period. This unwraps a signal `p` by changing elements which have an absolute difference from their predecessor of more than ``max(discont, period/2)`` to their `period`-complementary values. For the defau
(p, discont=None, axis=-1, *, period=2*pi)
| 1662 | |
| 1663 | @array_function_dispatch(_unwrap_dispatcher) |
| 1664 | def unwrap(p, discont=None, axis=-1, *, period=2*pi): |
| 1665 | r""" |
| 1666 | Unwrap by taking the complement of large deltas with respect to the period. |
| 1667 | |
| 1668 | This unwraps a signal `p` by changing elements which have an absolute |
| 1669 | difference from their predecessor of more than ``max(discont, period/2)`` |
| 1670 | to their `period`-complementary values. |
| 1671 | |
| 1672 | For the default case where `period` is :math:`2\pi` and `discont` is |
| 1673 | :math:`\pi`, this unwraps a radian phase `p` such that adjacent differences |
| 1674 | are never greater than :math:`\pi` by adding :math:`2k\pi` for some |
| 1675 | integer :math:`k`. |
| 1676 | |
| 1677 | Parameters |
| 1678 | ---------- |
| 1679 | p : array_like |
| 1680 | Input array. |
| 1681 | discont : float, optional |
| 1682 | Maximum discontinuity between values, default is ``period/2``. |
| 1683 | Values below ``period/2`` are treated as if they were ``period/2``. |
| 1684 | To have an effect different from the default, `discont` should be |
| 1685 | larger than ``period/2``. |
| 1686 | axis : int, optional |
| 1687 | Axis along which unwrap will operate, default is the last axis. |
| 1688 | period : float, optional |
| 1689 | Size of the range over which the input wraps. By default, it is |
| 1690 | ``2 pi``. |
| 1691 | |
| 1692 | .. versionadded:: 1.21.0 |
| 1693 | |
| 1694 | Returns |
| 1695 | ------- |
| 1696 | out : ndarray |
| 1697 | Output array. |
| 1698 | |
| 1699 | See Also |
| 1700 | -------- |
| 1701 | rad2deg, deg2rad |
| 1702 | |
| 1703 | Notes |
| 1704 | ----- |
| 1705 | If the discontinuity in `p` is smaller than ``period/2``, |
| 1706 | but larger than `discont`, no unwrapping is done because taking |
| 1707 | the complement would only make the discontinuity larger. |
| 1708 | |
| 1709 | Examples |
| 1710 | -------- |
| 1711 | >>> phase = np.linspace(0, np.pi, num=5) |
| 1712 | >>> phase[3:] += np.pi |
| 1713 | >>> phase |
| 1714 | array([ 0. , 0.78539816, 1.57079633, 5.49778714, 6.28318531]) # may vary |
| 1715 | >>> np.unwrap(phase) |
| 1716 | array([ 0. , 0.78539816, 1.57079633, -0.78539816, 0. ]) # may vary |
| 1717 | >>> np.unwrap([0, 1, 2, -1, 0], period=4) |
| 1718 | array([0, 1, 2, 3, 4]) |
| 1719 | >>> np.unwrap([ 1, 2, 3, 4, 5, 6, 1, 2, 3], period=6) |
| 1720 | array([1, 2, 3, 4, 5, 6, 7, 8, 9]) |
| 1721 | >>> np.unwrap([2, 3, 4, 5, 2, 3, 4, 5], period=4) |