spectral.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:tensorpac 作者: EtienneCmb 项目源码 文件源码
def spectral(x, sf, f, axis, stype, dcomplex, filt, filtorder, cycle, width,
             njobs):
    """Extract spectral informations from data.

    Parameters
    ----------
    x : array_like
        Array of data

    sf : float
        Sampling frequency

    f : array_like
        Frequency vector of shape (N, 2)

    axis : int
        Axis where the time is located.

    stype : string
        Spectral informations to extract (use either 'pha' or 'amp')

    dcomplex : string
        Complex decomposition type. Use either 'hilbert' or 'wavelet'

    filt : string
        Name of the filter to use (only if dcomplex is 'hilbert'). Use
        either 'eegfilt', 'butter' or 'bessel'.

    filtorder : int
        Order of the filter (only if dcomplex is 'hilbert')

    cycle : int
        Number of cycles to use for fir1 filtering.

    width : int
        Width of the wavelet.

    njobs : int
        Number of jobs to use. If jobs is -1, all of them are going to be
        used.
    """
    # Filtering + complex decomposition :
    if dcomplex is 'hilbert':
        # Filt each time series :
        nf = range(f.shape[0])
        xf = Parallel(n_jobs=njobs)(delayed(filtdata)(
            x, sf, f[k, :], axis, filt, cycle, filtorder) for k in nf)
        # Use hilbert for the complex decomposition :
        xd = hilbert(xf, axis=axis + 1) if stype is not None else np.array(xf)
    elif dcomplex is 'wavelet':
        f = f.mean(1)  # centered frequencies
        xd = Parallel(n_jobs=njobs)(delayed(morlet)(
            x, sf, k, axis, width) for k in f)

    # Extract phase / amplitude :
    if stype is 'pha':
        return np.angle(np.moveaxis(xd, axis + 1, -1))
    elif stype is 'amp':
        return np.abs(np.moveaxis(xd, axis + 1, -1))
    elif stype is None:
        return np.moveaxis(xd, axis + 1, -1)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号