unwrap

Removes jumps of more than pi in a phase sequence by adding multiples of 2*pi.

Category: Mathematics > Elementary Math

Syntax

Q = unwrap(P)

Corrects radian phase angles along the first non-singleton dimension.

Q = unwrap(P, tol)

Uses tol instead of pi as the jump threshold.

Q = unwrap(P, [], dim)

Unwraps along dimension dim.

Description

Functions such as angle return phase in the interval from -pi to pi, so a steadily growing phase appears to jump back at the boundary. unwrap looks at the difference between consecutive elements. When that difference exceeds the tolerance in magnitude, it adds or subtracts the multiple of 2*pi that brings the step back inside the tolerance, and carries that correction forward to all later elements.

The first element is never changed. The result is useful for plotting the phase response of a filter or for tracking a rotating signal.

Input arguments

P
Vector or matrix of phase angles in radians.
tol
Jump size above which a correction is applied. The default is pi.
dim
Dimension along which to unwrap.

Output arguments

Q
Array of the same size as P with the same values modulo 2*pi, but continuous.

Example

Continuing a phase ramp

t = 0:0.5:6;
wrapped = angle(exp(1i*t));
unwrapped = unwrap(wrapped);
disp(max(abs(unwrapped - t)) < 1e-12)
unwrap([0 2.5 5 0.5])
Output
   1
ans = 1×4

         0    2.5000    5.0000    6.7832

The last value, 0.5, is lifted by 2*pi because the step from 5 to 0.5 is larger than pi in magnitude.

See also

angle mod rem cumsum diff