def hilbert(x, N=None, axis=-<NUM_LIT:1>):
x = asarray(x)<EOL>if iscomplexobj(x):<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if N is None:<EOL><INDENT>N = x.shape[axis]<EOL><DEDENT>if N <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>Xf = fft(x, N, axis=axis)<EOL>h = zeros(N)<EOL>if N % <NUM_LIT:2> == <NUM_LIT:0>:<EOL><INDENT>h[<NUM_LIT:0>] = h[N // <NUM_LIT:2>] = <NUM_LIT:1><EOL>h[<NUM_LIT:1>:N // <NUM_LIT:2>] = <NUM_LIT:2><EOL><DEDENT>else:<EOL><INDENT>h[<NUM_LIT:0>] = <NUM_LIT:1><EOL>h[<NUM_LIT:1>:(N + <NUM_LIT:1>) // <NUM_LIT:2>] = <NUM_LIT:2><EOL><DEDENT>if len(x.shape) > <NUM_LIT:1>:<EOL><INDENT>ind = [newaxis] * x.ndim<EOL>ind[axis] = slice(None)<EOL>h = h[ind]<EOL><DEDENT>x = ifft(Xf * h, axis=axis)<EOL>return x<EOL>
Compute the analytic signal, using the Hilbert transform.

The transformation is done along the last axis by default.

Parameters
----------
x : array_like
    Signal data.  Must be real.
N : int, optional
    Number of Fourier components.  Default: ``x.shape[axis]``
axis : int, optional
    Axis along which to do the transformation.  Default: -1.

Returns
-------
xa : ndarray
    Analytic signal of `x`, of each 1-D array along `axis`

Notes
-----
The analytic signal ``x_a(t)`` of signal ``x(t)`` is:

.. math:: x_a = F^{-1}(F(x) 2U) = x + i y

where `F` is the Fourier transform, `U` the unit step function,
and `y` the Hilbert transform of `x`. [1]_

In other words, the negative half of the frequency spectrum is zeroed
out, turning the real-valued signal into a complex signal.  The Hilbert
transformed signal can be obtained from ``np.imag(hilbert(x))``, and the
original signal from ``np.real(hilbert(x))``.

References
----------
.. [1] Wikipedia, "Analytic signal".
       http://en.wikipedia.org/wiki/Analytic_signal