RunMat
GitHub

envelope — Compute upper and lower signal envelopes.

envelope(x) returns upper and lower envelopes for a finite real signal vector or for each column of a finite real matrix. The default analytic mode removes each channel mean, computes the magnitude of the analytic signal, and adds the mean back to the upper and lower bounds.

Syntax

yupper = envelope(x)
[yupper, ylower] = envelope(x)
yupper = envelope(x, n, method)
[yupper, ylower] = envelope(x, n, method)

Inputs

NameTypeRequiredDefaultDescription
xNumericArrayYesFinite real-valued signal vector or matrix, processed column-wise.
nNumericScalarYesFilter/window length for analytic or RMS mode, or peak separation for peak mode.
methodStringScalarNo"analytic"Envelope method: `analytic`, `rms`, or `peak`.

Returns

NameTypeDescription
yupperNumericArrayUpper signal envelope.
ylowerNumericArrayLower signal envelope.

Returned values from envelope depend on how many outputs the caller requests.

Errors

IdentifierWhenMessage
RunMat:envelope:ArgCountThe argument count is outside supported forms.envelope: expected envelope(x), envelope(x, n), or envelope(x, n, method)
RunMat:envelope:InvalidSignalInput is not a finite real numeric vector or matrix.envelope: x must be a finite real numeric vector or matrix
RunMat:envelope:InvalidLengthFilter/window length or peak separation is not a positive integer.envelope: n must be a positive integer scalar

How envelope works

  • yupper = envelope(x) returns the upper envelope.
  • [yupper, ylower] = envelope(x) returns both bounds.
  • envelope(x, n) uses analytic mode and accepts n for MATLAB call-form compatibility.
  • envelope(x, n, 'analytic') computes an FFT-domain analytic envelope.
  • envelope(x, wl, 'rms') computes a centered sliding RMS envelope over a window of wl samples.
  • envelope(x, np, 'peak') detects local maxima/minima separated by at least np samples and interpolates them with a spline curve.
  • Statement form with no outputs plots the signal with the upper and lower envelopes.

Examples

Analytic envelope of an amplitude-modulated tone

t = (0:127) / 128;
x = (1.25 + 0.5*sin(2*pi*t)) .* sin(2*pi*8*t);
[up, lo] = envelope(x);

Centered moving RMS envelope

x = [0 3 4 0];
[up, lo] = envelope(x, 3, 'rms');

Peak envelope

x = [0 2 0 -1 0 3 0];
[up, lo] = envelope(x, 2, 'peak');

Column-wise matrix envelopes

x = [sin(0:0.1:10)' cos(0:0.1:10)'];
[up, lo] = envelope(x);

Using envelope with coding agents

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

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

FAQ

What is the default envelope method?

The default is analytic-envelope mode using the magnitude of the analytic signal.

How are matrix inputs handled?

envelope processes each matrix column independently and returns outputs with the same shape as the input.

Does envelope plot when no outputs are requested?

Yes. Statement form renders the signal, upper envelope, and lower envelope using the line-plot pipeline.

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

Symbolic

digits · int · limit · sym · syms · vpa

Fft

fft · fft2 · fftshift · ifft · ifft2 · ifftshift

Interpolation

interp1 · interp2 · pchip · ppval · spline

Ode

ode15s · ode23 · ode45

Open-source implementation

Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how envelope 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.