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.

flowchart LR A["Raw BodyKinematics stream"] --> B["intervals package:\nTriadStaticIntervalDetector"] B --> C["generators package:\nMeasurementsGenerator"] C --> D["StandardDeviationBodyKinematics\n(one per static interval)"] C --> E["BodyKinematicsSequence\n(one per dynamic interval)"] D --> F["Accelerometer calibrator\n(gravity-norm family)"] E --> G["Gyroscope calibrator\n(Easy family)"]

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 is

    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 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

SUDDEN_EXCESSIVE_MOVEMENT_DETECTED

, where is instantaneousNoiseLevelFactor (default 2.0)

On every sample before initialStaticSamples is reached, once the window is full. It catches a bump or a hand movement during the baseline period.

OVERALL_EXCESSIVE_MOVEMENT_DETECTED

baseNoiseLevelAbsoluteThreshold

Once, when initialization would otherwise complete. The default threshold is Double.MAX_VALUE, so this check is disabled unless you set a limit (in m/s^2 for the accelerometer).

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):

  • onStaticIntervalDetected fires when a static interval starts (including the first one after initialization), and receives the current window mean and standard deviation.

  • onDynamicIntervalDetected fires 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.

stateDiagram-v2 [*] --> IDLE IDLE --> INITIALIZING : first sample INITIALIZING --> INITIALIZING : N below initialStaticSamples and ratio within factor INITIALIZING --> FAILED : ratio above instantaneousNoiseLevelFactor INITIALIZING --> FAILED : base noise above absolute threshold INITIALIZING --> INITIALIZATION_COMPLETED : N reached and window full INITIALIZATION_COMPLETED --> STATIC_INTERVAL : window std norm below threshold INITIALIZATION_COMPLETED --> DYNAMIC_INTERVAL : window std norm not below threshold STATIC_INTERVAL --> DYNAMIC_INTERVAL : window std norm not below threshold DYNAMIC_INTERVAL --> STATIC_INTERVAL : window std norm below threshold FAILED --> IDLE : reset STATIC_INTERVAL --> IDLE : reset DYNAMIC_INTERVAL --> IDLE : 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 thresholdFactor parameter, 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

minStaticSamples

202 (2 windows of 101)

A static interval with fewer samples is skipped (no measurement). Setter minimum is 3.

maxDynamicSamples

3030 (30 windows of 101)

A dynamic interval longer than this is skipped. Setter minimum is 3.

windowSize, initialStaticSamples, thresholdFactor, …​

as in the detector

Forwarded to the internal detector (getWindowSize(), getInitialStaticSamples() and so on).

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, and onStaticIntervalSkipped is raised.

  • If the dynamic counter exceeds maxDynamicSamples, the current dynamic interval is flagged as skipped (once, with onDynamicIntervalSkipped) until the next static interval begins.

flowchart TD S["New sample"] --> D["Detector classifies sample"] D -->|"static"| CS["static counter + 1, dynamic counter = 0"] D -->|"dynamic"| CD["dynamic counter + 1, static counter = 0"] CD --> MD{"dynamic counter above maxDynamicSamples?"} MD -->|"yes"| SKD["Skip this dynamic interval"] MD -->|"no"| REC["Keep sample for the sequence"] D -->|"static interval ends"| MS{"static counter below minStaticSamples?"} MS -->|"yes"| SKS["Skip this static interval"] MS -->|"no"| EMIT["Emit measurement from accumulated mean and std"]

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

AccelerometerMeasurementsGenerator

One StandardDeviationBodyKinematics per kept static interval (accumulated mean specific force, average of the three axis deviations)

Gravity-norm / position accelerometer calibrators

GyroscopeMeasurementsGenerator

One BodyKinematicsSequence per kept dynamic interval, bracketed by the mean specific force before and after

EasyGyroscopeCalibrator / KnownBiasEasyGyroscopeCalibrator

MagnetometerMeasurementsGenerator

One StandardDeviationBodyMagneticFluxDensity per kept static interval (mean field, and the norm of the field standard deviation measured in the initial period as its deviation)

Norm/position magnetometer calibrators

AccelerometerAndGyroscopeMeasurementsGenerator

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

AccelerometerGyroscopeAndMagnetometerMeasurementsGenerator

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 counts the first timestamp, which produces no interval, intervals are averaged with weight . Unrolling the mean recursion gives, after timestamps,

so the estimate is low by a factor , which is negligible for the default run length. The same off-by-one weighting applies to the variance, which also uses a running mean rather than the final one; treat it as an approximate spread of the sampling period, not an exact unbiased variance.

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

com.irurueta.navigation.inertial.calibration.intervals (detection, 9 classes)

Javadoc

Source

com.irurueta.navigation.inertial.calibration.generators (measurement building, 13 classes)

Javadoc

Source

BodyKinematicsGenerator

Javadoc

Source

BodyMagneticFluxDensityGenerator

Javadoc

Source

TimeIntervalEstimator

Javadoc

Source

TimeIntervalEstimatorListener

Javadoc

Source

AccelerationTriadStaticIntervalDetector

Javadoc

Source

AccelerationTriadStaticIntervalDetectorListener

Javadoc

Source

AccelerometerMeasurementsGenerator

Javadoc

Source

TriadStaticIntervalDetector

Javadoc

Source

MeasurementsGenerator

Javadoc

Source

GyroscopeMeasurementsGenerator

Javadoc

Source

BodyKinematicsSequence

Javadoc

Source

BodyKinematics

Javadoc

Source

StandardDeviationBodyKinematics

Javadoc

Source

Where to go next