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)
评论列表
文章目录