X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=altoslib%2FAltosTimeSeries.java;h=d12fbe701d67b83741010d29df4d6a53969f4dad;hp=9f3b4d807ef26bb36ae9a358515ac41c17f3bad5;hb=HEAD;hpb=6e4c104c28952f2010c7b1cbc9ce59e148ab2d8f diff --git a/altoslib/AltosTimeSeries.java b/altoslib/AltosTimeSeries.java index 9f3b4d80..d12fbe70 100644 --- a/altoslib/AltosTimeSeries.java +++ b/altoslib/AltosTimeSeries.java @@ -12,7 +12,7 @@ * General Public License for more details. */ -package org.altusmetrum.altoslib_12; +package org.altusmetrum.altoslib_14; import java.util.*; @@ -20,15 +20,33 @@ public class AltosTimeSeries implements Iterable, Comparable values; + boolean data_changed; + double min_time = -2; public int compareTo(AltosTimeSeries other) { return label.compareTo(other.label); } public void add(AltosTimeValue tv) { - values.add(tv); + if (tv.time >= min_time) { + data_changed = true; + values.add(tv); + } + } + + public void erase_values() { + data_changed = true; + this.values = new ArrayList(); + } + + public void clear_changed() { + data_changed = false; } +// public boolean changed() { +// return data_changed; +// } + public void add(double time, double value) { add(new AltosTimeValue(time, value)); } @@ -264,14 +282,35 @@ public class AltosTimeSeries implements Iterable, Comparable 0); + return s; + } + + private static double kaiser(double n, double m, double beta) { + double alpha = m / 2; + double t = (n - alpha) / alpha; + + if (t > 1 || t < -1) + t = 1; + double k = i0 (beta * Math.sqrt (1 - t*t)) / i0(beta); + return k; + } + + private double filter_coeff(double dist, double width) { + return kaiser(dist + width/2.0, width, 2 * Math.PI); } public AltosTimeSeries filter(AltosTimeSeries f, double width) { + double half_width = width/2; + int half_point = values.size() / 2; for (int i = 0; i < values.size(); i++) { double center_time = values.get(i).time; double left_time = center_time - half_width; @@ -303,6 +342,16 @@ public class AltosTimeSeries implements Iterable, Comparable max) value = max; + clip.add(v.time, value); + } + return clip; + } + public AltosTimeSeries(String label, AltosUnits units) { this.label = label; this.units = units;