zero-phase filtering with scipy
This commit is contained in:
parent
85490e8b59
commit
5379004d1c
1 changed files with 53 additions and 0 deletions
53
ride_data.py
Normal file
53
ride_data.py
Normal file
|
|
@ -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)
|
||||
Loading…
Reference in a new issue