hilbert — Construct analytic signals with the Hilbert transform.
z = hilbert(x) returns the analytic signal associated with a real signal x. The real part of z is the original signal, and the imaginary part is the Hilbert transform of x.
Syntax
z = hilbert(x)
z = hilbert(x, N)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
x | NumericArray | Yes | — | Real-valued signal vector, matrix, or N-D array. |
N | NumericScalar | No | [] | FFT length along the first non-singleton dimension. |
Returns
| Name | Type | Description |
|---|---|---|
z | NumericArray | Analytic signal with real part equal to the input signal. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:hilbert:ArgCount | More than two input arguments are supplied. | hilbert: expected hilbert(X) or hilbert(X, N) |
RunMat:hilbert:InvalidLength | Length argument N is non-scalar, negative, non-finite, or fractional. | hilbert: invalid length argument |
RunMat:hilbert:InvalidInput | Input cannot be converted to a real numeric/logical signal. | hilbert: expected real numeric input |
RunMat:hilbert:Internal | FFT execution or tensor shaping fails internally. | hilbert: internal error |
How hilbert works
- Accepts real numeric, logical, integer, vector, matrix, and N-D tensor inputs.
- Operates along the first non-singleton dimension, matching MATLAB's column-wise behavior for matrices and row-wise behavior for row vectors.
hilbert(x, N)pads with zeros or truncates along the transform dimension before constructing the analytic signal.- Returns complex scalar or complex tensor output; output shape follows the input shape except that the transform dimension becomes
Nwhen supplied. - The FFT-domain multiplier preserves DC and, for even lengths, Nyquist bins; positive-frequency bins are doubled and negative-frequency bins are zeroed.
- Complex inputs are rejected because MATLAB's
hilbertexpects a real signal.
Does RunMat run hilbert on the GPU?
GPU inputs are downloaded through the active provider with dtype normalization.
The host FFT implementation then applies MATLAB-compatible analytic-signal weighting.
The output is a complex host value, matching the runtime's current complex tensor representation.
GPU memory and residency
hilbert accepts GPU tensors through the normal gather path. Because the result is complex and the runtime currently materializes complex analytic signals on the host, downstream GPU residency resumes only after an explicit gpuArray or another operation that uploads the result.
Examples
Analytic signal of a sampled cosine
x = [1 0 -1 0];
z = hilbert(x)Expected output:
z = [1.0000 + 0.0000i, 0.0000 + 1.0000i, -1.0000 + 0.0000i, 0.0000 - 1.0000i]Use Hilbert output for phase demodulation
fs = 8000;
t = 0:1/fs:0.1;
s = cos(2*pi*500*t + 2*sin(2*pi*20*t));
z = hilbert(s);
phase = unwrap(angle(z));Specify an FFT length
x = [1 0 -1 0];
z = hilbert(x, 8);
size(z)Expected output:
ans = [1 8]Operate down matrix columns
X = [1 0; 0 1; -1 0; 0 -1];
Z = hilbert(X);Using hilbert with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how hilbert changes the result.
Run a small hilbert example, explain the result, then change one input and compare the output.
FAQ
What does hilbert return?⌄
hilbert returns an analytic signal. Its real part is the input signal and its imaginary part is the Hilbert transform.
Which dimension is transformed?⌄
RunMat follows MATLAB's default: the first non-singleton dimension. For a column vector this is rows, for a row vector this is columns, and for a matrix this means each column is transformed independently.
How is the transform computed?⌄
RunMat computes an FFT, applies the standard one-sided analytic-signal multiplier, and then computes an inverse FFT.
Can I pass complex input?⌄
No. hilbert is defined for real input signals and returns a complex analytic signal.
Does hilbert run on GPU tensors?⌄
GPU tensors are supported as inputs. The current implementation gathers through the active provider, computes the analytic signal with the host FFT path, and returns a complex host tensor.
Related Math functions
Signal
blackman · butter · conv · conv2 · deconv · downsample · filter · filtfilt · fir1 · freqz · gauspuls · hamming · hann · pulstran · rectpuls · sawtooth · sinc · square · tripuls · unwrap · upsample
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 hilbert is executed, line by line, in Rust.
- View the source for hilbert 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.