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

NameTypeRequiredDefaultDescription
xNumericArrayYesReal-valued signal vector, matrix, or N-D array.
NNumericScalarNo[]FFT length along the first non-singleton dimension.

Returns

NameTypeDescription
zNumericArrayAnalytic signal with real part equal to the input signal.

Errors

IdentifierWhenMessage
RunMat:hilbert:ArgCountMore than two input arguments are supplied.hilbert: expected hilbert(X) or hilbert(X, N)
RunMat:hilbert:InvalidLengthLength argument N is non-scalar, negative, non-finite, or fractional.hilbert: invalid length argument
RunMat:hilbert:InvalidInputInput cannot be converted to a real numeric/logical signal.hilbert: expected real numeric input
RunMat:hilbert:InternalFFT 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 N when 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 hilbert expects a real signal.

Does RunMat run hilbert on the GPU?

The WGPU provider computes FFT, analytic-signal weighting, and inverse FFT without gathering the source tensor to host.

The output handle is marked as complex-interleaved GPU storage for downstream resident complex operations.

If the provider hook is unavailable or the requested transform length is zero, the runtime gathers and uses the MATLAB-compatible host FFT implementation.

GPU memory and residency

hilbert keeps real GPU tensors resident when the active provider implements signal_hilbert, returning a complex-interleaved GPU tensor. Unsupported providers retain the host fallback path.

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?

Yes. Providers with signal_hilbert support keep real GPU tensor inputs resident and return a complex GPU tensor. Providers without that hook fall back to the host FFT path.

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 hilbert 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.