Filters
applyFilterAuto(channel_data, dataFilt)
Source code in src/model/filters.py
def applyFilterAuto(channel_data, dataFilt):
"""
Args:
Returns:
"""
samFreq = 20e3 * 1.0
passband = [250, 4000]
stopband = [5, 6000]
max_loss_passband = 3
min_loss_stopband = 30
order, normal_cutoff = signal.buttord(passband, stopband, max_loss_passband, min_loss_stopband, fs=samFreq)
b, a = signal.butter(order, normal_cutoff, btype='bandpass', fs=samFreq)
dataFilt = signal.filtfilt(b, a, channel_data)
return dataFilt
applyFilterAutoTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterAutoTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
samFreq = 20e3 * 1.0
passband = [250, 4000]
stopband = [5, 6000]
max_loss_passband = 3
min_loss_stopband = 30
order, normal_cutoff = signal.buttord(passband, stopband, max_loss_passband, min_loss_stopband, fs=samFreq)
b, a = signal.butter(order, normal_cutoff, btype='bandpass', fs=samFreq)
print('Order = ' + str(order))
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.filtfilt(b, a, dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterFastBandpass(channel_data, dataFilt)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterFastBandpass(channel_data, dataFilt):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 4000 / nyq
b, a = signal.butter(1, [cutoff1, cutoff2], btype='bandpass', analog=False)
dataFilt= signal.filtfilt(b, a, channel_data)
return dataFilt
applyFilterFastBandpassTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterFastBandpassTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 4000 / nyq
b, a = signal.butter(1, [cutoff1, cutoff2], btype='bandpass', analog=False)
print('Order = ' + str(1))
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.filtfilt(b, a, dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterFasterBandpass(channel_data, dataFilt)
Source code in src/model/filters.py
def applyFilterFasterBandpass(channel_data, dataFilt):
"""
Args:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 4000 / nyq
sos1 = signal.butter(1, [cutoff1, cutoff2], btype='bandpass', output='sos')
dataFilt = signal.sosfiltfilt(sos1, channel_data)
return dataFilt
applyFilterFasterBandpassTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterFasterBandpassTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 4000 / nyq
sos1 = signal.butter(1, [cutoff1, cutoff2], btype='bandpass', output='sos')
print('Order = ' + str(1))
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.sosfiltfilt(sos1, dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterH0bandpass(channel_data, dataFilt)
Source code in src/model/filters.py
def applyFilterH0bandpass(channel_data, dataFilt):
"""
Args:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 4000 / nyq
b, a = signal.butter(5, [cutoff1, cutoff2], btype="bandpass", analog=False)
dataFilt = signal.filtfilt(b, a, channel_data)
return dataFilt
applyFilterH0bandpassTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterH0bandpassTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 4000 / nyq
b, a = signal.butter(5, [cutoff1, cutoff2], btype="bandpass", analog=False)
print('Order = ' + str(5))
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.filtfilt(b, a, dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterHierlemann(channel_data, dataFilt)
Source code in src/model/filters.py
def applyFilterHierlemann(channel_data, dataFilt):
"""
Args:
Returns:
"""
BP_LOW_CUTOFF = 100.0
NUM_TAPS = 75
TAPS = signal.firwin(NUM_TAPS,
[BP_LOW_CUTOFF, ],
pass_zero=False,
fs=20e3 * 1.0)
a = 1
dataFilt= signal.filtfilt(TAPS, [a], channel_data)
return dataFilt
applyFilterHierlemannTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterHierlemannTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
BP_LOW_CUTOFF = 100.0
NUM_TAPS = 75
TAPS = signal.firwin(NUM_TAPS,
[BP_LOW_CUTOFF, ],
pass_zero=False,
fs=20e3 * 1.0)
a = 1
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.filtfilt(TAPS, [a], dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterHighpass(channel_data, dataFilt)
Source code in src/model/filters.py
def applyFilterHighpass(channel_data, dataFilt):
"""
Args:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff = 250 / nyq
b, a = signal.butter(5, [cutoff], btype="highpass", analog=False)
dataFilt = signal.filtfilt(b, a, channel_data)
return dataFilt
applyFilterHighpassTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterHighpassTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff = 250 / nyq
b, a = signal.butter(5, [cutoff], btype="highpass", analog=False)
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.filtfilt(b, a, dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterLitke(channel_data, dataFilt)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterLitke(channel_data, dataFilt):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 2000 / nyq
b, a = signal.butter(2, [cutoff1, cutoff2], btype="bandpass", analog=False)
dataFilt = signal.filtfilt(b, a, channel_data)
return dataFilt
applyFilterLitkeTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterLitkeTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
nyq = 0.5 * (20e3 * 1.0)
cutoff1 = 250 / nyq
cutoff2 = 2000 / nyq
b, a = signal.butter(2, [cutoff1, cutoff2], btype="bandpass", analog=False)
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.filtfilt(b, a, dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterModHierlemann(channel_data, dataFilt)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel_data |
required | ||
dataFilt |
required |
Source code in src/model/filters.py
def applyFilterModHierlemann(channel_data, dataFilt):
"""
Args:
channel_data:
dataFilt:
Returns:
"""
BP_LOW_CUTOFF = 250.0
BP_HIGH_CUTOFF = 4000.0
NUM_TAPS = 100
TAPS = signal.firwin(NUM_TAPS,
[BP_LOW_CUTOFF, BP_HIGH_CUTOFF],
pass_zero=False,
fs=20e3 * 1.0)
a = 1
dataFilt = signal.filtfilt(TAPS, [a], channel_data)
return dataFilt
applyFilterModHierlemannTimed(dataAll, dataFilt, numChan, chMap)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
dataFilt |
required | ||
numChan |
required | ||
chMap |
required |
Source code in src/model/filters.py
def applyFilterModHierlemannTimed(dataAll, dataFilt, numChan, chMap):
"""
Args:
dataAll:
dataFilt:
numChan:
chMap:
Returns:
"""
BP_LOW_CUTOFF = 250.0
BP_HIGH_CUTOFF = 4000.0
NUM_TAPS = 100
TAPS = signal.firwin(NUM_TAPS,
[BP_LOW_CUTOFF, BP_HIGH_CUTOFF],
pass_zero=False,
fs=20e3 * 1.0)
a = 1
for k in range(0, numChan):
start = time.time()
dataFilt[chMap[0, k], chMap[1, k], :] = signal.filtfilt(TAPS, [a], dataAll[chMap[0, k], chMap[1, k], :])
end = time.time()
text1 = 'Estimated Time Remaining: ' + str.format('{0:.2f}', (end - start) * (numChan - k) / 60) + ' min'
text2 = str(k + 1) + '/' + str(numChan) + ' Channels Filtered'
print(text1 + ' ' + text2, end="\r")
return dataFilt
applyFilterToAllData(dataAll, numChan, chMap, filtType='Modified Hierlemann', debug=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataAll |
required | ||
numChan |
required | ||
chMap |
required | ||
filtType |
'Modified Hierlemann' |
Source code in src/model/filters.py
def applyFilterToAllData(dataAll, numChan, chMap, filtType='Modified Hierlemann', debug = False):
"""
Args:
dataAll:
numChan:
chMap:
filtType:
Returns:
"""
# Future update: only calculate for channels recorded not all
dataFilt = np.zeros((np.shape(dataAll)))
if filtType == 'Hierlemann':
dataFilt = applyFilterHierlemannTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'Modified Hierlemann':
dataFilt = applyFilterModHierlemannTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'Highpass':
dataFilt = applyFilterHighpassTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'H0 Bandpass':
dataFilt = applyFilterH0bandpassTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'Auto':
dataFilt = applyFilterAutoTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'Fast Bandpass':
dataFilt = applyFilterFastBandpassTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'Faster Bandpass':
dataFilt = applyFilterFasterBandpassTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'Litke':
dataFilt = applyFilterLitkeTimed(dataAll, dataFilt, numChan, chMap)
elif filtType == 'None':
dataFilt = np.copy(dataAll)
else:
dataFilt = np.copy(dataAll)
print('Filter not recognized. Options include Hierlemann, highpass, bandpass, Litke or none')
if debug:
print("Filter type: " +str(filtType))
return dataFilt
applyFilterToChannelData(channel_data, filtType='Hierlemann', debug=False)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
channel_data |
required | ||
filtType |
'Hierlemann' |
Source code in src/model/filters.py
def applyFilterToChannelData(channel_data, filtType='Hierlemann', debug = False):
"""
Args:
channel_data:
filtType:
Returns:
"""
dataFilt = np.zeros((np.shape(channel_data)))
if filtType == 'Hierlemann':
dataFilt = applyFilterHierlemann(channel_data, dataFilt)
elif filtType == 'Modified Hierlemann':
dataFilt = applyFilterModHierlemann(channel_data, dataFilt)
elif filtType == 'Highpass':
dataFilt = applyFilterHighpass(channel_data, dataFilt)
elif filtType == 'H0 Bandpass':
dataFilt = applyFilterH0bandpass(channel_data, dataFilt)
elif filtType == 'Auto':
dataFilt = applyFilterAuto(channel_data, dataFilt)
elif filtType == 'Fast Bandpass':
dataFilt = applyFilterFastBandpass(channel_data, dataFilt)
elif filtType == 'Faster Bandpass':
dataFilt = applyFilterFasterBandpass(channel_data, dataFilt)
elif filtType == 'Litke':
dataFilt = applyFilterLitke(channel_data, dataFilt)
elif filtType == 'None':
dataFilt = np.copy(channel_data)
else:
dataFilt = np.copy(channel_data)
print('Filter type "' + str(filtType) +'" not recognized. Options include Hierlemann, highpass, bandpass, Litke or none')
if debug:
print("Filter type: " +str(filtType))
return dataFilt