analytic_signal.py 文件源码

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

项目:dyfunconn 作者: makism 项目源码 文件源码
def analytic_signal(signal, fb, fs=128, order=3):
    """ Passband filtering and Hilbert transformation


    Parameters
    ----------
    signal: real array-like, shape(n_channels, n_samples)
        Input signal

    fb: list of length 2
        The low and high frequencies

    fs: int
        Sampling frequency

    order : int
        Filter order

    Returns
    -------
    filtered_signal: real array-like, shape(n_channels, n_samples)
        The input signal, filtered within the given frequencies

    hilberted_signal: complex array-like, shape(n_channels, n_samples)
        The Hilbert representation of the input signal

    unwrapped_phase: real array-like, shape(n_channels, n_samples)
        The unwrapped phase of the Hilbert representation


    Notes
    -----
    Internally, we use SciPy's Butterworth implementation (`scipy.signal.butter`)
    and the two-pass filter `scipy.signal.filtfilt` to achieve results identical
    to MATLAB.
    """
    fs = float(fs)

    passband = [fb[0] / (fs / 2.0), fb[1] / (fs / 2.0)]
    passband = np.ravel(passband)
    b, a = scipy.signal.butter(
        order, passband, 'bandpass', analog=False, output='ba')

    filtered_signal = scipy.signal.filtfilt(b, a, signal)
    hilberted_signal = scipy.signal.hilbert(filtered_signal)
    unwrapped_phase = np.unwrap(np.angle(hilberted_signal))

    return (filtered_signal, hilberted_signal, unwrapped_phase)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号