NumPy unwrap()

The numpy.unwrap() function corrects phase angles in a signal by replacing abrupt jumps larger than a threshold with their 2π (or specified period) complement. This ensures continuity in phase data.

Syntax

</>
Copy
numpy.unwrap(p, discont=None, axis=-1, *, period=6.283185307179586)

Parameters

ParameterTypeDescription
parray_likeInput array containing phase values.
discontfloat, optionalMaximum discontinuity allowed between consecutive values before unwrapping occurs. Default is period/2.
axisint, optionalAxis along which unwrapping is performed. Default is the last axis (-1).
periodfloat, optionalDefines the range over which the phase wraps. Default is (6.283).

Return Value

Returns an ndarray with phase values corrected for discontinuities, ensuring smooth transitions.


Examples

1. Basic Unwrapping of a Wrapped Phase Signal

Here, we apply numpy.unwrap() to a simple wrapped phase sequence.

</>
Copy
import numpy as np

# Simulated wrapped phase values in radians
wrapped_phase = np.array([0, np.pi/2, np.pi, -np.pi, -np.pi/2, 0])

# Unwrap the phase to remove discontinuities
unwrapped_phase = np.unwrap(wrapped_phase)

# Print results
print("Wrapped phase values:", wrapped_phase)
print("Unwrapped phase values:", unwrapped_phase)

Output:

Wrapped phase values: [ 0.          1.57079633  3.14159265 -3.14159265 -1.57079633  0.        ]
Unwrapped phase values: [0.         1.57079633 3.14159265 3.14159265 4.71238898 6.28318531]