-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPreprocessor.py
27 lines (20 loc) · 1.13 KB
/
Preprocessor.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
import scipy.signal as signal
import storage.Constants as Constants
def butter_bandstop_filter(data, cutoff_low, cutoff_high, nyq_freq, order=3):
sos = signal.butter(order, [cutoff_low / nyq_freq, cutoff_high / nyq_freq], btype='bandstop', output='sos')
y = signal.sosfiltfilt(sos, data)
return y
def butter_bandpass_filter(data, cutoff_low, cutoff_high, nyq_freq, order=3):
sos = signal.butter(order, [cutoff_low / nyq_freq, cutoff_high / nyq_freq], btype='bandpass', output='sos')
y = signal.sosfiltfilt(sos, data)
return y
# Applies a bandstop and bandpass filter to all the channels of the data
def performPreprocessing(rawData):
bandStopData = []
for channel in rawData:
# apply filters
bandChannelData = butter_bandpass_filter(channel, Constants.lowBandPassFreq,
Constants.highBandPassFreq, Constants.samplingRate * 0.5)
bandStopData.append(butter_bandstop_filter(bandChannelData, Constants.lowBandStopFreq,
Constants.highBandStopFreq, Constants.samplingRate * 0.5))
return bandStopData