Qu

wrap

Builtin index · Signal processing

result = wrap(x, [lo=-pi], [hi=pi])

Input: x, lo, hi · Output: result

What it is

x: a number, vector, matrix or Signal; lo/hi (optional numbers, default -pi/pi): the half-open interval [lo, hi) to wrap into.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = wrap(x, [lo=-pi], [hi=pi])
x number, vector, matrix, or Signalx: a number, vector, matrix or Signal.
lo number, optional (default -pi)lo/hi (optional numbers, default -pi/pi): the half-open interval [lo, hi) to wrap into.
hi number, optional (default pi)lo/hi (optional numbers, default -pi/pi): the half-open interval [lo, hi) to wrap into.
result —
Returns the same shape as x, each value reduced modulo hi - lo into that range — the standard fix for angle/phase data that has accumulated past a full turn (atan2 output, an integrated angular velocity). Defaults to [-pi, pi), the convention atan2/angle already return in. Errors if hi <= lo.

Examples

No documentation example calls this form yet. The Signal processing chapter is where one belongs.

How it works

wrap(x, [lo=-pi], [hi=pi]) — wraps each value of x into the half-open interval [lo, hi) by modular arithmetic, the standard operation for angle/phase data that has accumulated past a full turn (atan2 output, an integrated angular velocity, a raw X.phase() before unwrapping). Defaults to [-pi, pi), the convention atan2/angle already return in, so wrap(angle(z)) round-trips with no arguments. rem_euclid rather than %: Rust's % can return a negative remainder for a negative x - lo, which is exactly the case (x below lo) this function exists to fix.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.