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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x | NumericArray | Yes | — | Finite real-valued signal vector or matrix, processed column-wise. |
n | NumericScalar | Yes | — | Filter/window length for analytic or RMS mode, or peak separation for peak mode. |
method | StringScalar | No | "analytic" | Envelope method: `analytic`, `rms`, or `peak`. |
Returns
| Name | Type | Description |
|---|---|---|
yupper | NumericArray | Upper signal envelope. |
ylower | NumericArray | Lower signal envelope. |
Returned values from envelope depend on how many outputs the caller requests.
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:envelope:ArgCount | The argument count is outside supported forms. | envelope: expected envelope(x), envelope(x, n), or envelope(x, n, method) |
RunMat:envelope:InvalidSignal | Input is not a finite real numeric vector or matrix. | envelope: x must be a finite real numeric vector or matrix |
RunMat:envelope:InvalidLength | Filter/window length or peak separation is not a positive integer. | envelope: n must be a positive integer scalar |
RunMat:envelope:InvalidMethod | Method is not analytic, rms, or peak. | envelope: method must be 'analytic', 'rms', or 'peak' |
RunMat:envelope:Internal | Envelope computation or output tensor assembly fails internally. | envelope: internal error |
RunMat:envelope:TooManyOutputs | More than two output arguments are requested. | envelope: expected at most two output arguments |
How envelope works
yupper = envelope(x)returns the upper envelope.[yupper, ylower] = envelope(x)returns both bounds.envelope(x, n)uses analytic mode and acceptsnfor 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 ofwlsamples.envelope(x, np, 'peak')detects local maxima/minima separated by at leastnpsamples 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.
Related Math functions
Signal
blackman · butter · buttord · conv · conv2 · deconv · downsample · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · hilbert · periodogram · pulstran · pwelch · rectpuls · sawtooth · sinc · spectrogram · square · tripuls · unwrap · upsample · zplane
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
Structure
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how envelope is executed, line by line, in Rust.
- View the source for envelope in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
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.