filtering.py 文件源码

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

项目:tensorpac 作者: EtienneCmb 项目源码 文件源码
def filtdata(x, sf, f, axis, filt, cycle, filtorder):
    """Filt the data using a forward/backward filter to avoid phase shifting.

    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.

    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.
    """
    # fir1 filter :
    if filt == 'fir1':
        forder = fir_order(sf, x.shape[axis], f[0], cycle=cycle)
        b, a = fir1(forder, f / (sf / 2))

    # butterworth filter :
    elif filt == 'butter':
        b, a = butter(filtorder, [(2 * f[0]) / sf, (2 * f[1]) / sf],
                      btype='bandpass')
        forder = None

    # bessel filter :
    elif filt == 'bessel':
        b, a = bessel(filtorder, [(2 * f[0]) / sf, (2 * f[1]) / sf],
                      btype='bandpass')
        forder = None

    return filtfilt(b, a, x, padlen=forder, axis=axis)

###############################################################################
###############################################################################
#                       FILTER ORDER
###############################################################################
###############################################################################
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号