Created
February 20, 2019 23:29
-
-
Save ahwillia/4dbba6196918420b37db13c543779ce4 to your computer and use it in GitHub Desktop.
Bandpass filter in python... (I have no idea why scipy does not provide this)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def bandpass(x, lowcut, highcut, fs, order=5, axis=-1, kind='butter'): | |
""" | |
Parameters | |
---------- | |
x : ndarray | |
1d time series data | |
lowcut : float | |
Defines lower frequency cutoff (e.g. in Hz) | |
highcut : float | |
Defines upper frequency cutoff (e.g. in Hz) | |
fs : float | |
Sampling frequency (e.g. in Hz) | |
order : int | |
Filter order parameter | |
kind : str | |
Specifies the kind of filter | |
axis : int | |
Axis along which to bandpass filter data | |
""" | |
nyq = 0.5 * fs | |
low = lowcut / nyq | |
high = highcut / nyq | |
if kind == "butter": | |
b, a = butter(order, [low, high], btype="band") | |
else: | |
raise ValueError("Filter kind not recognized.") | |
return filtfilt(b, a, x, axis=axis) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment