Repository navigation
AccelAverageFilter
Up | Previous | Next | Русский
Below is the full source of the class in documentation form. The comments inside the block explain the purpose of the parts of the class, but they are not stored in the working file AccelAverageFilter.java: the production code stays clean and the explanations live in the wiki.
package com.velitask.plugin.official.processing.filters;
import com.velitask.sdk.data.AccelerometerSensorAtom;
/* Smoothing by average for the accelerometer: three axes X, Y, Z. */
public final class AccelAverageFilter extends VectorAverageFilter<AccelerometerSensorAtom> {
/* Stable step name in the import plans. */
public static final String NAME = "accelAverage";
/* Step logic version is 1; atoms are AccelerometerSensorAtom. */
public AccelAverageFilter() {
super(NAME, 1, AccelerometerSensorAtom.class);
}
/* Three components: x, y, z. */
@Override
protected int components() {
return 3;
}
/* Index 0, 1, 2 is the x, y, z axis; any other index throws IndexOutOfBoundsException. */
@Override
protected double component(AccelerometerSensorAtom atom, int index) {
return switch (index) {
case 0 -> atom.x;
case 1 -> atom.y;
case 2 -> atom.z;
default -> throw new IndexOutOfBoundsException(index);
};
}
/* The x, y, z fields are integers (mm/s2), so the average is rounded. */
@Override
protected void setComponent(AccelerometerSensorAtom atom, int index, double value) {
int rounded = (int) Math.round(value);
switch (index) {
case 0 -> atom.x = rounded;
case 1 -> atom.y = rounded;
case 2 -> atom.z = rounded;
default -> throw new IndexOutOfBoundsException(index);
}
}
}The "Smoothing by average: acceleration" step replaces every acceleration value on the axes with the average over a window around it. It removes sensor noise and vibration, but also softens short impacts (the Plugin.ImportStep.accelAverage.description string). An implementation of VectorAverageFilter for AccelerometerSensorAtom.
The algorithm is in VectorAverageFilter: the windowSec parameter (default 0), averaging of every component through WindowAverage, recalculation of the increments. The class only defines the composition of the atom:
-
components()— 3; -
component(atom, index)—atom.x,atom.y,atom.z; -
setComponent(atom, index, value)— writesMath.round(value), because thex,y,zfields are integers; -
period()is not overridden: the values are not angular.
It is used by the GoPro import plan: a window of 0.04 s for the camera acceleration (the stage after "Pauses from the file" and before "Tolerance compression: acceleration" — AccelToleranceCompress); the sensor is disabled in the plan by default. The step is also registered in BuiltinScenarios.steps().
- The storage unit is mm/s² (1 g ≈ 9807 mm/s², as in the compression tolerance hint), the result is rounded to an integer.
- The axes are smoothed independently.
- The default window is 0: without an explicit value in the plan the step changes nothing.