bundles / scipy latest / scipy / signal / _signaltools / hilbert2
function
scipy.signal._signaltools:hilbert2
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.
Array API Standard Support
hilbert2 has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable SCIPY_ARRAY_API=1 and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.
==================== ==================== ==================== Library CPU GPU ==================== ==================== ==================== NumPy ✅ n/a CuPy n/a ✅ PyTorch ✅ ✅ JAX ⛔ ⛔ Dask ✅ n/a ==================== ==================== ====================
See
dev-arrayapifor more information.
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))
✗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✓
Aliases
-
scipy.signal.hilbert2