def hilbert(x, N=None, axis=(-1)):
 x = asarray(x)
 if iscomplexobj(x):
  raise ValueError('x must be real.')
 if (N is None):
  N = x.shape[axis]
 if (N <= 0):
  raise ValueError('N must be positive.')
 Xf = fftpack.fft(x, N, axis=axis)
 h = zeros(N)
 if ((N % 2) == 0):
  h[0] = h[(N // 2)] = 1
  h[1:(N // 2)] = 2
 else:
  h[0] = 1
  h[1:((N + 1) // 2)] = 2
 if (x.ndim > 1):
  ind = ([newaxis] * x.ndim)
  ind[axis] = slice(None)
  h = h[ind]
 x = fftpack.ifft((Xf * h), axis=axis)
 return x

def hilbert ( x , N = None , axis = ( - 1 ) ) : x = asarray ( x ) if iscomplexobj ( x ) : raise ValueError ( 'x must be real.' ) if ( N is None ) : N = x . shape [ axis ] if ( N <= 0 ) : raise ValueError ( 'N must be positive.' ) Xf = fftpack . fft ( x , N , axis = axis ) h = zeros ( N ) if ( ( N % 2 ) == 0 ) : h [ 0 ] = h [ ( N // 2 ) ] = 1 h [ 1 : ( N // 2 ) ] = 2 else : h [ 0 ] = 1 h [ 1 : ( ( N + 1 ) // 2 ) ] = 2 if ( x . ndim > 1 ) : ind = ( [ newaxis ] * x . ndim ) ind [ axis ] = slice ( None ) h = h [ ind ] x = fftpack . ifft ( ( Xf * h ) , axis = axis ) return x
compute the analytic signal .