Source code for engram.procedural.filters


from scipy.signal import butter, filtfilt

[docs]def select(filter,data,min=0,max=None,fs=2000,order=5): selection = { "bandpass": butter_bandpass_filter } # Get the function from switcher dictionary func = selection.get(filter, lambda: "Invalid event parser") # Execute the function return func(data,min,max,fs,order)
[docs]def butter_lowpass(cutoff, fs, order=5): nyq = 0.5 * fs normal_cutoff = cutoff / nyq b, a = butter(order, normal_cutoff, btype='low', analog=False) return b, a
[docs]def butter_lowpass_filter(data, cutoff, fs, order=5): b, a = butter_lowpass(cutoff, fs, order=order) y = filtfilt(b, a, data) return y
[docs]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
[docs]def butter_bandpass_filter(data, lowcut, highcut, fs, order=5): b, a = butter_bandpass(lowcut, highcut, fs, order=order) y = filtfilt(b, a, data) return y