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

feature: added Arin's butterfilter

parent 6f84a19a
No related branches found
No related tags found
No related merge requests found
import numpy as np
from scipy import signal
def butterfilter(timeseries, 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",
)
# subtract time series by mean
timeseries_norm = timeseries - np.nanmean(timeseries, axis=1).reshape(
timeseries.shape[0], 1
)
filtered_timeseries = signal.sosfiltfilt(sos, timeseries_norm, axis=1)
return filtered_timeseries
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