Source code for filtration
"""
In this module collected functions for band filtration
"""
import scipy as sp
import scipy.signal as spsig
import numpy as np
import matplotlib.pyplot as plt
from scipy.signal import butter, lfilter
[docs]def butter_bandpass(lowcut, highcut, fs, order=5):
"""
Calculation of bandpass Butterworth filter
:param lowcut: Low bound of passband
:type lowcut: float
:param highcut: High bound of passband
:type highcut: float
:param fs: Sampling frequency
:type fs: float
:returns: tuple
"""
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
[docs]def butter_bandpass_filter(x, lowcut, highcut, fs, order=5):
"""
Filter signal
:param lowcut: Low bound of passband
:type lowcut: float
:param highcut: High bound of passband
:type highcut: float
:param fs: Sampling frequency
:type fs: float
:returns: tuple
"""
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = lfilter(b, a, x)
return y