Signal envelope extraction
Estimate instantaneous amplitude from a real waveform.
SciPy · Function
Computes the analytic signal of a real-valued input using an FFT-based Hilbert transform. The result is complex, with the original signal in the real part and its Hilbert transform in the imaginary part.
hilbert computes an analytic signal with an FFT: negative-frequency components are removed and positive-frequency amplitudes are doubled. The result is complex; its imaginary part is the Hilbert transform, while its real part reconstructs the real input. Processing defaults to the last axis, and N can crop or zero-pad that axis before the transform.
scipy.signal.hilbert(x, N=None, axis=-1)| Name | Type | Description |
|---|---|---|
x | array_like | Signal data; must be real. |
N | int, optional | Number of output samples. The input is cropped or zero-padded to this length along axis. Defaults to x.shape[axis]. |
axis | int, optional | Axis along which to perform the transformation. Defaults to -1. |
ndarray — The analytic signal of x, with each one-dimensional array along axis transformed.
import numpy as np
from scipy.signal import hilbert
samples = np.sin(2 * np.pi * 5 * np.arange(100) / 100)
analytic = hilbert(samples)
envelope = np.abs(analytic)
phase = np.unwrap(np.angle(analytic))
print(envelope.shape, phase.shape)This computes an analytic signal, then derives its amplitude envelope and unwrapped phase.
Estimate instantaneous amplitude from a real waveform.
Analyze phase evolution of oscillatory data.
Apply the transform independently across rows or columns of an array.
It returns the analytic signal obtained by zeroing negative FFT frequencies and doubling positive-frequency amplitudes. The imaginary component is the Hilbert transform of the real input.
Follow-up: How would you obtain the amplitude envelope? Take the magnitude with abs(result), which combines the real and imaginary components.
x must be real-valued signal data. N is the requested number of output samples and defaults to the input length along axis; axis defaults to -1.
Follow-up: What happens when N differs from the input length? The input is cropped or zero-padded along the selected axis before processing.
The transform operates along the last axis by default, but axis selects another dimension. For multidimensional input, each one-dimensional slice along that axis is transformed independently.
Follow-up: How can the ordinary Hilbert transform be recovered? Use np.imag(hilbert(x)); np.real(hilbert(x)) recovers the original real signal.
scipy.signal.hilbert2scipy.signal.hilbert