From 5379004d1c72e8a3e7a421ef5893e6ef70c58226 Mon Sep 17 00:00:00 2001 From: Thies Lennart Alff Date: Thu, 19 Sep 2024 21:07:01 +0200 Subject: [PATCH] zero-phase filtering with scipy --- ride_data.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 ride_data.py diff --git a/ride_data.py b/ride_data.py new file mode 100644 index 0000000..69c7227 --- /dev/null +++ b/ride_data.py @@ -0,0 +1,53 @@ +import numpy as np +from scipy.signal import butter, filtfilt + +sample_freq = 1.0 +cutoff_freq = 0.05 +order = 1 + + +def butter_lowpass_filter(data, cutoff, fs, order=5): + b, a = butter(order, cutoff, fs=fs, btype="low", analog=False) + y = filtfilt(b, a, data) + return y + + +activity = GC.activity() +power = np.array(activity["power"]) +seconds = np.array(activity["seconds"]) + +GC.setChart( + title="Ride Data", + type=GC.CHART_LINE, + animate=False, + legpos=GC_ALIGN_TOP, + stack=False, +) +GC.addCurve( + name="Power", + x=seconds, + y=power, + xaxis="Time", + yaxis="Power", + color="yellow", + line=GC_LINE_SOLID, + symbol=GC_SYMBOL_NONE, + size=3, + opacity=100, + opengl=False, +) +GC.addCurve( + name="Power Smoothed", + x=seconds, + y=butter_lowpass_filter(power, cutoff_freq, sample_freq, order), + xaxis="Time", + yaxis="Power", + color="red", + line=GC_LINE_SOLID, + symbol=GC_SYMBOL_NONE, + size=3, + opacity=100, + opengl=False, +) +GC.setAxis("Power", min=0, max=800, type=GC.AXIS_CONTINUOUS) +GC.setAxis('Time', type=GC.AXIS_TIME)