diff --git a/preload/apps/ecg/__init__.py b/preload/apps/ecg/__init__.py index 53e4795fc0682f326db7db597a583f61a0852507..59466effcddfd8eace78b1ba163dc9803e204a39 100644 --- a/preload/apps/ecg/__init__.py +++ b/preload/apps/ecg/__init__.py @@ -51,12 +51,13 @@ last_sample_count = 1 leds.dim_top(1) COLORS = [((23 + (15 * i)) % 360, 1.0, 1.0) for i in range(11)] - # variables for high-pass filter +# note: corresponds to 1st order hpf with -3dB at ~18.7Hz +# general formula: f(-3dB)=-(sample_rate/tau)*ln(1-betadash) moving_average = 0 alpha = 2 beta = 3 - +betadash = beta/(alpha+beta) def update_history(datasets): global history, moving_average, alpha, beta, last_sample_count @@ -64,7 +65,8 @@ def update_history(datasets): for val in datasets: if current_mode == MODE_FINGER: history.append(val - moving_average) - moving_average = (alpha * moving_average + beta * val) / (alpha + beta) + moving_average += betadash*(val-moving_average) + # identical to: moving_average = (alpha * moving_average + beta * val) / (alpha + beta) else: history.append(val)