add filters to smooth signals

This commit is contained in:
Brian Delhaisse
2019-06-21 20:18:14 +02:00
parent 477c258cd7
commit 428786b126
+33
View File
@@ -0,0 +1,33 @@
#!/usr/bin/env python
"""Common filters used in signal processing
These filters can be useful to smooth signal trajectories.
"""
from scipy.signal import butter, lfilter
__author__ = "Brian Delhaisse"
__copyright__ = "Copyright 2018, PyRoboLearn"
__credits__ = ["Brian Delhaisse"]
__license__ = "GNU GPLv3"
__version__ = "1.0.0"
__maintainer__ = "Brian Delhaisse"
__email__ = "briandelhaisse@gmail.com"
__status__ = "Development"
# Butterworth Filter
# Example from http://scipy-cookbook.readthedocs.io/items/ButterworthBandpass.html
def butter_bandpass(lowcut, highcut, fs, order=5):
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
return b, a
def butter_bandpass_filter(data, lowcut, highcut, fs, order=5):
b, a = butter_bandpass(lowcut, highcut, fs, order=order)
y = lfilter(b, a, data)
return y