-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbandpass_ndh.py
executable file
·30 lines (29 loc) · 1.24 KB
/
bandpass_ndh.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from scipy.signal import butter, lfilter
def bandpass_ndh(data, times, lowcut, highcut, order=5):
"""
% (C) Nick Holschuh - Amherst College - 2022 (Nick.Holschuh@gmail.com)
% This function applies a bandpass filter on an input series.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The inputs are as follows:
%
% data -- the input array to be filtered
% times -- the array defining the axis of variability that describes "data"
% lowcut -- the frequency that defines the high-pass transition
% highcut -- the frequency that defines the low-pass transition
% order -- the order that defines the butterworth filter
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The outputs are as follows:
%
% y -- the filtered dataset
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Modified from https://stackoverflow.com/questions/12093594/how-to-implement-band-pass-butterworth-filter-with-scipy-signal-butter
"""
fs = 1/(times[1]-times[0])
nyq = 0.5 * fs
low = lowcut / nyq
high = highcut / nyq
b, a = butter(order, [low, high], btype='band')
y = lfilter(b, a, data)
return y