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, can be used to change the number of
workers used for the FFTs.
scipy.fft.set_workers
Parameters:
x : array_like
Input signal. Must be at least two-dimensional.
N : int or tuple of two ints, optional
Number of output samples. x is initially cropped or zero-padded to length
N along axes. Default: x.shape[i]foriinaxes
axes : tuple of two ints, optional
Axes along which to do the transformation. Default: (-2, -1).
Returns:
xa : ndarray
Analytic signal of x taken 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.,
X[p,q]=k,l=0∑N0,N1x[k,l]e−2jπkp/N0e−2jπlq/N1
Zero negative frequency bins and double their positive counterparts, i.e.,
Xa[p,q]=(1+sN0(p))(1+sN1(q))X[p,q]
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.
Bülow, Thomas, and Gerald Sommer. “A novel approach to the 2D analytic
signal.” In International Conference on Computer Analysis of Images and
Patterns, pp. 25-32. Berlin, Heidelberg: Springer Berlin Heidelberg, 1999.
PDF
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.
>>> importnumpyasnp>>> fromscipy.fftimportfft2,fftshift,ifftshift>>> fromscipy.signalimporthilbert2...>>> # Input signal is unit impulse with a constant offset:>>> x=np.ones((5,5))/5>>> x[0,0]+=1...>>> X=fftshift(fft2(x))# Zero frequency bin is at center>>> print(X)[[1.-0.j 1.-0.j 1.-0.j 1.+0.j 1.+0.j] [1.-0.j 1.-0.j 1.-0.j 1.+0.j 1.+0.j] [1.-0.j 1.-0.j 6.-0.j 1.+0.j 1.+0.j] [1.-0.j 1.-0.j 1.+0.j 1.+0.j 1.+0.j] [1.-0.j 1.-0.j 1.+0.j 1.+0.j 1.+0.j]]>>> 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:
>>> fromscipy.fftimportfft2,fftshift,ifft2,ifftshift>>> fromscipy.signalimporthilbert2...>>> # Create a real signal by ensuring `Z[-p,-q] == np.conj(Z[p,q])` holds:>>> Z=np.array([[0,0,0
with sN(.) being a modified sign function defined as
sN(p):=⎩⎨⎧−1−0+1−0 for p<0, for p=0, for 1≤p<(N+1)//2, elsewhere.
The limitation of the “+1” case to the range of [1:(N+1)//2]
accounts for the unpaired Nyquist frequency bin at N/2 for even
N. Note that Xa[p]=(1+sN(p))X[p] is the
one-dimensional Hilbert function (as in hilbert) in Fourier
space.