Skip to content
Snippets Groups Projects
Commit e8c95562 authored by Peter Swain's avatar Peter Swain
Browse files

change: rename butterworth_filter ; lowpass_filter

Renamed butterworth_filter to flavin_filter.
parent ac00fff8
No related branches found
No related tags found
No related merge requests found
......@@ -105,24 +105,18 @@ def snr(fft_freqs, fft_power, cutoff_freq):
return snr
def butterworth_filter(data, params=None):
"""Apply Butterworth filter to time series arranged in rows."""
# second-order-sections output
# by default, using a digital filter
if params is None:
params = {
"order": 2,
"critical_freqs": (1 / 350),
"filter_type": "highpass",
"sampling_freq": 1 / 3,
}
sos = signal.butter(
N=params["order"],
Wn=params["critical_freqs"],
btype=params["filter_type"],
fs=params["sampling_freq"],
output="sos",
)
def lowpass_filter(data, cutoff, fs, N):
"""Apply low-pass filter to a single time-series."""
data = data - np.mean(data)
sos = signal.butter(N, cutoff, btype="lowpass", fs=fs, output="sos")
filtered_data = signal.sosfiltfilt(sos, data)
return filtered_data + np.mean(data)
def flavin_filter(data, cutoff=1 / 350, fs=1 / 5, N=2):
"""Apply high-pass Butterworth filter to time series arranged in rows."""
# use a digital filter assuming regularly spaced sampling
sos = signal.butter(N=N, Wn=cutoff, btype="highpass", fs=fs, output="sos")
# fill NaNs between data points
data = pd.DataFrame(data).interpolate(axis=1).to_numpy()
# subtract time series by mean
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment