Static/Dynamic Interval Detection and Measurement Generation
| This documentation was generated with the assistance of AI. Please report any inaccuracies. |
Classes: com.irurueta.navigation.inertial.calibration.intervals (detection, 9 classes),
com.irurueta.navigation.inertial.calibration.generators (measurement building, 13 classes), plus the
root-level BodyKinematicsGenerator, BodyMagneticFluxDensityGenerator, TimeIntervalEstimator, and
TimeIntervalEstimatorListener (see the Class Reference table at the end of this page for Javadoc
and source links).
This is the preprocessing step behind the calibrators in Accelerometer Calibration and Gyroscope Calibration that don’t need a turntable or precisely known frames — most directly, [imu-tk]'s "Easy" gyroscope calibrator and the accelerometer’s gravity-norm family. Both need the raw sensor stream split into static periods (device held still, mean specific force reveals the local gravity direction) and dynamic periods (device being moved between orientations) — without any external ground truth telling them which is which.
TriadStaticIntervalDetector: classifying static vs. dynamic
The core class, TriadStaticIntervalDetector (specialized as AccelerationTriadStaticIntervalDetector,
AngularSpeedTriadStaticIntervalDetector, MagneticFluxDensityTriadStaticIntervalDetector), consumes one triad
per call to process(…). The generators of this page always drive an AccelerationTriadStaticIntervalDetector:
the accelerometer stream decides which samples are static, for every sensor. The detector implements the
static-interval test described in the Tedaldi et al. section, with the
differences listed at the end of this section.
Statistics used
Two noise estimators from the noise package run side by side:
-
A windowed estimator keeps the last samples (
windowSize, default 101; it must be odd and at least 3). For every new sample it recomputes, over the window only, the per-axis mean and the unbiased per-axis variance (division by ). Its standard-deviation norm isThe window only counts as valid once it holds samples, so no decision is taken before that.
-
An accumulated estimator keeps a running mean and standard deviation of every sample added to it since its last reset. During initialization it is fed every sample; afterwards it is fed only the samples classified as static and is reset each time a static interval ends.
Initialization and base noise level
The first initialStaticSamples samples (default 5000, minimum 2; about 50 s at 100 Hz) must be recorded with the
device motionless. They define the base noise level , the standard-deviation norm of the accumulated
estimator, and from it the classification threshold:
where is thresholdFactor (default 2.0). Initialization completes at the first sample for which
both initialStaticSamples and the window is full. Two checks can instead make it fail:
ErrorReason |
Condition | When it is evaluated |
|---|---|---|
|
, where is |
On every sample before |
|
|
Once, when initialization would otherwise complete. The default threshold is |
After a failure the status is FAILED, process(…) returns false and ignores further samples, and the only
way out is reset(), which also clears the counters, base noise level and both estimators.
Steady-state classification
From then on, every sample is classified by comparing the windowed norm with the threshold:
While the status is static, the sample is also added to the accumulated estimator, whose mean and standard deviation will describe that interval once it ends. Listener callbacks fire only when the status changes (the transition rules are in the diagram below):
-
onStaticIntervalDetectedfires when a static interval starts (including the first one after initialization), and receives the current window mean and standard deviation. -
onDynamicIntervalDetectedfires when a dynamic interval starts, that is when the static interval before it has just ended. It receives the window values and also the accumulated mean and standard deviation of the static interval that just finished, and then the accumulated estimator is reset.
Because the decision uses a full window of samples, boundaries are detected with a delay of the order of
samples: a static interval is only reported once the window has become quiet, and a dynamic one once
enough of the motion has entered the window. This is why windowSize should cover about one to two seconds of
data and why the generators below discard intervals shorter than a couple of windows.
AccelerationTriadStaticIntervalDetector detector = new AccelerationTriadStaticIntervalDetector(
new AccelerationTriadStaticIntervalDetectorListener() {
@Override
public void onDynamicIntervalDetected(
AccelerationTriadStaticIntervalDetector detector,
double instantaneousAvgX, double instantaneousAvgY, double instantaneousAvgZ,
double instantaneousStdX, double instantaneousStdY, double instantaneousStdZ,
double accumulatedAvgX, double accumulatedAvgY, double accumulatedAvgZ,
double accumulatedStdX, double accumulatedStdY, double accumulatedStdZ) {
// a static interval just ended: the accumulated* values describe it
}
// ...other TriadStaticIntervalDetectorListener callbacks
});
// feed raw accelerometer samples (m/s^2) as they arrive
detector.process(fx, fy, fz);
Differences from the paper
-
Standard deviation, not variance. The library compares the norm of the windowed per-axis standard deviations with times the norm of the base per-axis standard deviations. The paper compares a magnitude of the windowed variances with a multiple of the base variances. The two behave alike but are not numerically interchangeable: a test on the sum of the per-axis variances would be the same as the library test with in place of .
-
Fixed factor. The paper tunes the multiplier automatically inside its calibration loop. Here it is the
thresholdFactorparameter, and the generator Javadoc recommends repeating the gyroscope calibration with several values, because the gyroscope result depends on where intervals start and end. -
Extra safeguards. The two failure checks above are additions of the library.
MeasurementsGenerator: building calibration inputs from intervals
MeasurementsGenerator wraps an AccelerationTriadStaticIntervalDetector and reacts to its transitions to build
the objects the calibrators consume. Its constructor-time defaults are:
| Parameter | Default | Meaning |
|---|---|---|
|
202 (2 windows of 101) |
A static interval with fewer samples is skipped (no measurement). Setter minimum is 3. |
|
3030 (30 windows of 101) |
A dynamic interval longer than this is skipped. Setter minimum is 3. |
|
as in the detector |
Forwarded to the internal detector ( |
The two defaults are computed from the default window size; if you change windowSize they do not follow it, so
set them explicitly. The skip rules work on sample counters:
-
While the status is static, the static counter grows and the dynamic counter is set to 0, and vice versa.
-
When a dynamic interval starts, the static interval that just ended is skipped if the static counter is below
minStaticSamples, andonStaticIntervalSkippedis raised. -
If the dynamic counter exceeds
maxDynamicSamples, the current dynamic interval is flagged as skipped (once, withonDynamicIntervalSkipped) until the next static interval begins.
Averaging: what a measurement contains
At the end of a kept static interval of samples, with the accumulated per-axis estimates and of that interval:
AccelerometerMeasurementsGenerator emits a StandardDeviationBodyKinematics with specific force ,
zero angular rate and specific-force standard deviation (the plain average of the three axes,
not their norm). The averaging is what allows the noise term to be dropped from the model in
the Tedaldi et al. formulation; the standard deviation is kept so that
calibrators can weight or filter measurements.
Sequences for the gyroscope
GyroscopeMeasurementsGenerator needs the motion between two static intervals. It records every sample of a dynamic
interval as a StandardDeviationTimedBodyKinematics (kinematics, timestamp, plus two standard deviations taken from
the initial static period: the accelerometer base noise level and the norm of the gyroscope
standard deviations). When the next static interval is detected it emits one
BodyKinematicsSequence holding:
-
beforeMeanSpecificForce: the accumulated mean of the static interval that preceded the motion; -
the recorded items, in order;
-
afterMeanSpecificForce: the windowed mean of the new static interval at the moment it was detected.
These two mean specific forces are the start and end gravity directions of the -th motion, the quantities
the integration cost of the Tedaldi et al. method compares with the
integrated gyroscope rotation. A dynamic interval flagged as skipped produces no sequence. The gyroscope generator
does not apply minStaticSamples; only the accelerometer and magnetometer generators drop short static intervals.
| Class | Produces | Consumed by |
|---|---|---|
|
One |
|
|
One |
|
|
One |
|
|
Both of the above; it runs an accelerometer and a gyroscope generator on each sample, each with its own detector |
Calibration pipelines needing both sensors from one recording |
|
All three measurement types; it runs one generator per sensor on each sample, each with its own detector |
Full tri-sensor calibration pipelines |
The magnetometer generator averages the field during static samples (and during initialization), and clears its estimator whenever the status is dynamic, so its mean covers the same kind of interval as the accelerometer’s.
List<StandardDeviationBodyKinematics> measurements = new ArrayList<>();
AccelerometerMeasurementsGenerator generator = new AccelerometerMeasurementsGenerator(
(gen, measurement) -> measurements.add(measurement));
// feed raw BodyKinematics samples as they arrive from the IMU
for (BodyKinematics sample : rawKinematicsStream) {
generator.process(sample);
}
// 'measurements' now holds one StandardDeviationBodyKinematics per detected static
// interval, ready for calibration/accelerometer.adoc's gravity-norm calibrators
TimeIntervalEstimator
A small, separate utility: it estimates the average sampling period, and its variance, of a stream of timestamps in
seconds, so that the timeInterval of the noise estimators, the detector and the generators can be set from
measured data instead of nominal values. Call addTimestamp(t) for each sample; the first call only stores the
timestamp, and every later call updates the estimates with the interval . With
the number of timestamps processed before the call, the recursion is
where the deviation in the second equation uses the already updated mean. Because
so the estimate is low by a factor
The estimator is finite: it stops after totalSamples timestamps (default 100000, so about 33 minutes of a
50 Hz stream), isFinished() becomes true, and further timestamps are ignored (addTimestamp returns
false). reset() clears it. Listener callbacks are onStart, onTimestampAdded, onFinish and onReset.
TimeIntervalEstimator estimator = new TimeIntervalEstimator();
for (double timestampSeconds : rawTimestamps) {
estimator.addTimestamp(timestampSeconds);
}
double timeInterval = estimator.getAverageTimeInterval(); // seconds, e.g. ~0.02 for a 50 Hz IMU
double timeIntervalStd = estimator.getTimeIntervalStandardDeviation();
Root-level generators: synthetic test data (a different purpose)
BodyKinematicsGenerator and BodyMagneticFluxDensityGenerator are unrelated to interval
detection — they go the other direction, synthesizing noisy, uncalibrated measurements from
known-true kinematics/field plus a known IMUErrors model, for testing
calibrators and fixers against ground truth. They follow [book-groves]
and its companion IMU_model.m script rather than the Tedaldi et al. method.
Class Reference
Javadoc and source links for the classes used in the examples above:
| Class | Javadoc | Source |
|---|---|---|
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
Where to go next
-
Noise and Approximate-Bias Estimators — the noise estimators used inside the interval detector.
-
Gyroscope Calibration — the "Easy" calibrator that consumes
BodyKinematicsSequenceoutput. -
Accelerometer Calibration — the gravity-norm calibrators that consume
StandardDeviationBodyKinematicsoutput. -
reference.adoc#bibliography — bibliography.