altoslib: Use a longer filter for descent values
authorKeith Packard <keithp@keithp.com>
Wed, 24 Jun 2015 04:38:37 +0000 (21:38 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 24 Jun 2015 04:42:35 +0000 (21:42 -0700)
This makes descent speeds almost useful, a huge improvement

Signed-off-by: Keith Packard <keithp@keithp.com>
altoslib/AltosState.java

index a120e0c..8eacf97 100644 (file)
@@ -31,8 +31,9 @@ public class AltosState implements Cloneable, Serializable {
 
        public int set;
 
+       static final double filter_len = 2.0;
        static final double ascent_filter_len = 0.5;
-       static final double descent_filter_len = 0.5;
+       static final double descent_filter_len = 5.0;
 
        /* derived data */
 
@@ -64,8 +65,10 @@ public class AltosState implements Cloneable, Serializable {
                }
 
                void set_filtered(double new_value, double time) {
-                       if (prev_value != AltosLib.MISSING)
-                               new_value = (prev_value * 15.0 + new_value) / 16.0;
+                       if (prev_value != AltosLib.MISSING) {
+                               double f = 1/Math.exp((time - prev_set_time) / filter_le);
+                               new_value = f * new_value + (1-f) * prev_value;
+                       }
                        set(new_value, time);
                }