* @param timeStep\r
*/\r
public void filter(double startTime, double stopTime, double timeStep) {\r
- // TODO: this makes implicit assumptions about the values, probably not kosher\r
+ // construct a new time array with the "expected" time steps\r
int size = (int)Math.round((stopTime - startTime) / timeStep) + 1;\r
if (times.length < size) {\r
// if the original data has less time steps than requested, there is no need\r
double[] newTimes = new double[size];\r
double[] newValues = new double[size];\r
\r
- // simply skip all simulation steps that are not at the expected intervals\r
+ // generate a new value array from the original value array by walking\r
+ // through it and including only time steps that occur at the expected\r
+ // intervals (with an appropriate epsilon which is based on the \r
+ // simulation step)\r
+ double epsilon = timeStep / 1000;\r
int old = 0;\r
for (int i = 0; i < size; i++) {\r
newTimes[i] = startTime + i * timeStep;\r
- while (times[old] < newTimes[i] && old != times.length - 1) {\r
+ while (times[old] < newTimes[i] - epsilon && old != times.length - 1) {\r
old++;\r
}\r
newValues[i] = values[old];\r
}\r
\r
+ // replace the original arrays with the new ones\r
times = newTimes;\r
values = newValues;\r
}\r