'Compute analytic signal or envelope for a subset of channels.
If envelope=False, the analytic signal for the channels defined in
"picks" is computed and the data of the Raw object is converted to
a complex representation (the analytic signal is complex valued).
If envelope=True, the absolute value of the analytic signal for the
channels defined in "picks" is computed, resulting in the envelope
signal.
.. warning: Do not use ``envelope=True`` if you intend to compute
an inverse solution from the raw data. If you want to
compute the envelope in source space, use
``envelope=False`` and compute the envelope after the
inverse solution has been obtained.
.. note:: If envelope=False, more memory is required since the
original raw data as well as the analytic signal have
temporarily to be stored in memory.
.. note:: If n_jobs > 1, more memory is required as
``len(picks) * n_times`` additional time points need to
be temporaily stored in memory.
Parameters
picks : array-like of int (default: None)
Indices of channels to apply the function to. If None, all data
channels are used.
envelope : bool (default: False)
Compute the envelope signal of each channel.
n_jobs: int
Number of jobs to run in parallel.
n_fft : int | None | str
Points to use in the FFT for Hilbert transformation. The signal
will be padded with zeros before computing Hilbert, then cut back
to original length. If None, n == self.n_times. If \'auto\',
the next highest fast FFT length will be use.
verbose : bool, str, int, or None
If not None, override default verbose level (see
:func:`mne.verbose` and :ref:`Logging documentation <tut_logging>`
for more). Defaults to self.verbose.
Returns
self : instance of Raw
The raw object with transformed data.
Notes
The analytic signal "x_a(t)" of "x(t)" is::
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". One usage of the analytic
signal is the computation of the envelope signal, which is given by
"e(t) = abs(x_a(t))". Due to the linearity of Hilbert transform and the
MNE inverse solution, the enevlope in source space can be obtained
by computing the analytic signal in sensor space, applying the MNE
inverse, and computing the envelope in source space.
Also note that the n_fft parameter will allow you to pad the signal
with zeros before performing the Hilbert transform. This padding
is cut off, but it may result in a slightly different result
(particularly around the edges). Use at your own risk.'

@verbose
def apply_hilbert(self, picks=None, envelope=False, n_jobs=1, n_fft='auto', verbose=None):

    if (n_fft is None):
        n_fft = len(self.times)
    elif isinstance(n_fft, string_types):
        if (n_fft != 'auto'):
            raise ValueError(('n_fft    must    be    an    integer,    string,    or    None,    got    %s' % (type(n_fft),)))
        n_fft = next_fast_len(len(self.times))
    n_fft = int(n_fft)
    if (n_fft < self.n_times):
        raise ValueError('n_fft    must    be    greater    than    n_times')
    if (envelope is True):
        dtype = None
    else:
        dtype = np.complex64
    return self.apply_function(_my_hilbert, picks, dtype, n_jobs, n_fft, envelope=envelope)
