bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / signal / _signaltools / hilbert2
function
scipy.signal._signaltools:hilbert2
source: build-install/usr/lib/python3.14/site-packages/scipy/signal/_signaltools.py:2597
Signature
def hilbert2(x, N = None, axes = (-2, -1))Summary
Compute the '2-D' analytic signal of x.
Extended Summary
The 2-D analytic signal is calculated as a so-called "single-orthant" transform. This is achieved by applying one-dimensional Hilbert functions (as in hilbert) to the first and to the second array axis in Fourier space.
For NumPy arrays, scipy.fft.set_workers can be used to change the number of workers used for the FFTs.
Parameters
x: array_likeInput signal. Must be at least two-dimensional.
N: int or tuple of two ints, optionalNumber of output samples.
xis initially cropped or zero-padded to lengthNalongaxes. Default:x.shape[i] for i in axesaxes: tuple of two ints, optionalAxes along which to do the transformation. Default: (-2, -1).
Returns
xa: ndarrayAnalytic signal of
xtaken along given axes.
Notes
The "single-orthant" transform, as defined in [2], is calculated by performing the following steps:
Calculate the two-dimensional FFT of the input, i.e.,
Zero negative frequency bins and double their positive counterparts, i.e.,
with being a modified sign function defined as
The limitation of the "" case to the range of
[1:(N+1)//2]accounts for the unpaired Nyquist frequency bin at for even . Note that is the one-dimensional Hilbert function (as in hilbert) in Fourier space.Produce the analytic signal by performing the inverse FFT, i.e.,
The "single-orthant" transform is not the only possible definition of an analytic signal in multiple dimensions (as noted in [1]). Consult [3] for a description of properties that this 2-D transform does and does not share with the 1-D transform. The second example below shows one of the downsides of this approach.
Examples
The following example calculates the two-dimensional analytic signal from a single impulse with an added constant offset. The impulse produces an FFT where each bin has a value of one and the constant offset component produces only a non-zero component at the ``(0,0)`` bin.import numpy as np from scipy.fft import fft2, fftshift, ifftshift from scipy.signal import hilbert2 x = np.ones((5, 5)) / 5 x[0, 0] += 1 X = fftshift(fft2(x)) # Zero frequency bin is at center print(X) x_a = hilbert2(x) X_a = fftshift(fft2(x_a))✓
print(np.round(X_a, 3))
✗[[ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j 0.+0.j 0.+0.j 0.+0.j 0.+0.j] [ 0.+0.j -0.+0.j 6.+0.j 2.+0.j 2.+0.j] [ 0.+0.j 0.+0.j 2.+0.j 4.+0.j 4.+0.j] [ 0.+0.j 0.+0.j 2.+0.j 4.+0.j 4.+0.j]]The FFT of the result illustrates that the values of the lower right quadrant (or orthant) with purely positive frequency bins have been quadrupled. The values at its borders, where only one frequency component is zero, are doubled. The zero frequency bin ``(0, 0)`` has not been altered. All other quadrants have been set to zero. This second example illustrates a problem with the "single-orthant" convention. A purely real signal can produce an analytic signal which is completely zero:
from scipy.fft import fft2, fftshift, ifft2, ifftshift from scipy.signal import hilbert2 Z = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]) * 25 z = ifft2(ifftshift(Z)) np.allclose(z.imag, 0) # z is a real signal np.sum(z.real**2) # z.real is non-zero z_a = hilbert2(z.real) np.allclose(z_a, 0) # analytic signal is zero✓
True
Aliases
scipy.signal.hilbert2