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 , where is the number of samples actually stored in the window, which is once the window is full; before that the statistics are computed over the stored samples and a single sample gives a variance of 0). The detector uses the variance norm of the window, the same statistic as imu_tk:The 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 variance norm of the accumulated
estimator, and from it the classification threshold:
where is thresholdFactor (default 4.0, it was 2.0 when the statistic was the standard-deviation norm).
The base noise level and the threshold accessors keep their names, but their unit is now variance based
((m/s2)2 for the accelerometer; the same holds for baseNoiseLevelAbsoluteThreshold). The previous
standard-deviation based quantity remains available as the base noise standard deviation norm. 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 the variance norm of the accumulated estimator and 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, samples are classified by comparing the windowed variance norm with the threshold. The window is centred: the sample that receives the status is the one at the centre of the window, not the latest one,
so every status change is reported getDetectionDelaySamples() samples (half a window) after the sample where it
happened. In exchange, boundaries are symmetric: a dynamic interval starts about half a window before the
statistic of a trailing window would exceed the threshold, and a static interval starts about half a window after the
motion ends, so the static means no longer contain motion samples. Listener callbacks and the accumulated averages
refer to the classified (delayed) sample, whereas the getInstantaneous* values still describe the current window.
The initialization behaviour (INITIALIZING, INITIALIZATION_COMPLETED) is unchanged.
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 that is centred on the classified sample, boundaries are
reported with a fixed delay of about samples (getDetectionDelaySamples()). Generators use it to align
their items with the classified samples. windowSize should still cover about one to two seconds of data, and 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
-
Variance norm, as in imu_tk. The detector compares the norm of the windowed per-axis variances with times the same norm of the base period, as the paper/imu_tk does. Earlier versions used the norm of the standard deviations, and a factor on standard deviations corresponds to a factor \(k_{\text{reference}} \approx k^{2}\) on the variance norm. Every
thresholdFactor,instantaneousNoiseLevelFactorand absolute threshold you tuned for a previous version changes meaning: square the former standard-deviation factors (the defaultthresholdFactorwent from 2.0 to 4.0). The power spectral densities reported by the detectors are still derived from the standard deviation based base noise level. -
Centred window. As in imu_tk the classified sample is the one at the centre of the window (see above), which delays every status change by half a window.
-
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) and does not provide a gravity reference. 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. -
The initialization period is static, so its samples are part of the first static interval: the average of that interval includes the initialization samples (the accumulated estimator is not reset when initialization completes), and they also count towards
minStaticSamples, for every generator. -
If the dynamic counter exceeds
maxDynamicSamples, the current dynamic interval is flagged as skipped (once, withonDynamicIntervalSkipped) until the next static interval begins. A gyroscope sequence made of joined dynamic intervals is discarded in the same way when its total number of items exceedsmaxDynamicSamples. -
Noise levels and thresholds are variance-based as plain
doublevalues; their measurement-typed variants (…AsMeasurement) are the square root of those values, expressed in the unit of the sensor.
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) divided by , because the standard deviation of the mean of samples is
(previously the undivided average was reported). For the first interval includes the
initialization samples. 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). Sequences follow the rules of imu_tk:
-
A sequence needs a valid static interval (at least
minStaticSamplessamples) on both sides. If a static interval is too short, it provides no gravity reference and the dynamic intervals on both of its sides are joined into a single sequence. A sequence whose preceding static interval has no samples is discarded. -
A sequence is emitted when the static interval that follows it ends, so that its
afterMeanSpecificForceis the accumulated average of that entire static interval (previously it was the last window at the moment the static interval was detected). The same average is thebeforeMeanSpecificForceof the next sequence. Consequently, when a recording ends while the device is at rest, the last sequence is still pending: callflush()once no more samples are going to be processed to generate it from the static samples classified so far (at leastminStaticSamples). -
The initialization period is static: its average (initialization samples included) is the first
beforeMeanSpecificForce, so a motion starting right after initialization never gets a(0, 0, 0)reference. -
The items of the sequence are aligned with the samples classified as dynamic by the centred-window detector, taking
getDetectionDelaySamples()into account. -
Each sequence carries a gravity direction standard deviation (
BodyKinematicsSequence.getGravityDirectionStandardDeviation()/setGravityDirectionStandardDeviation(…), dimensionless, default 0, included incopyFrom,equalsandhashCode):
where is the accelerometer noise standard deviation, the number of averaged samples of
the static intervals before and after, the gyroscope noise root PSD (rad/s/sqrt(Hz)) and the
duration of the sequence, so that the integrated gyroscope noise term is dimensionless.
EasyGyroscopeCalibrator uses it as the standard deviation
of its three-component residual, see Gyroscope Calibration.
The 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
applies minStaticSamples only to decide which static intervals are valid gravity references (as described above).
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.