RunMat
GitHub

unwrap — Correct phase-angle jumps by adding multiples of 2*pi.

Q = unwrap(P) adjusts phase angles in radians by adding integer multiples of 2*pi whenever adjacent samples jump by more than the tolerance.

Syntax

Q = unwrap(P)
Q = unwrap(P, tol)
Q = unwrap(P, tol, dim)

Inputs

NameTypeRequiredDefaultDescription
PNumericArrayYesWrapped phase angles in radians.
tolNumericScalarNopiJump tolerance. Values below pi are treated as pi.
tolNumericScalarNopiJump tolerance. Use [] to keep the default.
dimNumericScalarNofirst non-singleton dimensionDimension along which to unwrap.

Returns

NameTypeDescription
QNumericArrayPhase values with jumps larger than the tolerance corrected by multiples of 2*pi.

Errors

IdentifierWhenMessage
RunMat:unwrap:ArgCountMore than three input arguments are supplied.unwrap: expected unwrap(P), unwrap(P, tol), or unwrap(P, tol, dim)
RunMat:unwrap:InvalidInputInput cannot be converted to a real numeric/logical phase array.unwrap: expected real numeric input
RunMat:unwrap:InvalidToleranceTolerance is not a finite, nonnegative scalar.unwrap: tolerance must be a finite nonnegative scalar

How unwrap works

  • Accepts real numeric, logical, integer, vector, matrix, and N-D tensor inputs.
  • Operates along the first non-singleton dimension by default.
  • unwrap(P, tol) uses max(tol, pi) as the discontinuity threshold, matching MATLAB behavior for tolerances below pi.
  • unwrap(P, [], dim) keeps the default tolerance and unwraps along dim.
  • Preserves the input shape and numeric dtype metadata.
  • Complex inputs are rejected because unwrap expects real phase angles.

Does RunMat run unwrap on the GPU?

GPU inputs are downloaded through the active provider with dtype normalization.

The host implementation performs MATLAB-compatible phase correction.

The output is a host tensor with the same shape as the input.

GPU memory and residency

unwrap accepts GPU tensors through the normal gather path. Because phase unwrapping is stateful along a dimension and currently materialized on the host, downstream GPU residency resumes only after an explicit gpuArray or another operation that uploads the result.

Examples

Correct a wrapped phase vector

p = [0 1 2 2-2*pi 3-2*pi];
q = unwrap(p)

Expected output:

q = [0 1 2 2 3]

Use a custom tolerance

p = [0 1 1-2*pi];
q = unwrap(p, 10)

Expected output:

q = [0 1 -5.2832]

Unwrap across matrix rows

P = [0 1 1-2*pi; 0 -1 -1+2*pi];
Q = unwrap(P, [], 2)

Expected output:

Q =
     0     1     1
     0    -1    -1

Recover continuous phase from an analytic signal

x = cos(0:0.1:10);
z = hilbert(x);
phase = unwrap(angle(z));

Using unwrap with coding agents

Open a RunMat example with live inputs, then ask the agent to explain how unwrap changes the result.

Run a small unwrap example, explain the result, then change one input and compare the output.

FAQ

What tolerance does unwrap use by default?

The default tolerance is pi. If you pass a tolerance below pi, RunMat uses pi, matching MATLAB's documented behavior.

Which dimension is unwrapped?

The first non-singleton dimension is used unless you pass dim.

Does unwrap change the shape?

No. The output has the same shape as the input.

Can I pass complex input?

No. Use angle(z) first to convert complex samples to real phase angles, then call unwrap.

Elementwise

abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · heaviside · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times

Trigonometry

acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh

Reduction

all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var

Rounding

ceil · fix · floor · mod · rem · round

Factor

chol · eig · lu · qr · svd

Solve

cond · det · inv · linsolve · norm · null · pinv · rank · rcond · rref

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Symbolic

limit · sym · syms

Ode

ode15s · ode23 · ode45

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how unwrap is executed, line by line, in Rust.

About RunMat

RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.

  • RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
  • Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.

Getting started · Benchmarks · Pricing

Download RunMat

Download RunMat for full performance, or use RunMat in your browser for zero setup.