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

SUDDEN_EXCESSIVE_MOVEMENT_DETECTED

, where is the variance norm of the accumulated estimator and is instantaneousNoiseLevelFactor (default 9.0, it was 2.0 for standard deviations; it is larger than the square of the old value because the variance norm of a short window is noisier and 4.0 produced false sudden-movement failures on very low noise data)

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 (variance based, in (m/s2)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, 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):

  • 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 variance norm below threshold INITIALIZATION_COMPLETED --> DYNAMIC_INTERVAL : window variance norm not below threshold STATIC_INTERVAL --> DYNAMIC_INTERVAL : window variance norm not below threshold DYNAMIC_INTERVAL --> STATIC_INTERVAL : window variance norm below threshold FAILED --> IDLE : reset STATIC_INTERVAL --> IDLE : reset DYNAMIC_INTERVAL --> IDLE : 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, instantaneousNoiseLevelFactor and absolute threshold you tuned for a previous version changes meaning: square the former standard-deviation factors (the default thresholdFactor went 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 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) and does not provide a gravity reference. 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.

  • 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, with onDynamicIntervalSkipped) 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 exceeds maxDynamicSamples.

  • Noise levels and thresholds are variance-based as plain double values; their measurement-typed variants (…​AsMeasurement) are the square root of those values, expressed in the unit of the sensor.

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) 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 minStaticSamples samples) 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 afterMeanSpecificForce is 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 the beforeMeanSpecificForce of the next sequence. Consequently, when a recording ends while the device is at rest, the last sequence is still pending: call flush() once no more samples are going to be processed to generate it from the static samples classified so far (at least minStaticSamples).

  • 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 in copyFrom, equals and hashCode):

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

AccelerometerMeasurementsGenerator

One StandardDeviationBodyKinematics per kept static interval (accumulated mean specific force, average of the three axis deviations divided by the square root of the number of averaged samples)

Gravity-norm / position accelerometer calibrators

GyroscopeMeasurementsGenerator

One BodyKinematicsSequence per dynamic interval (or joined dynamic intervals) bracketed by two valid static intervals, with the mean specific force before and after and a gravity direction standard deviation

EasyGyroscopeCalibrator / KnownBiasEasyGyroscopeCalibrator

MagnetometerMeasurementsGenerator

One StandardDeviationBodyMagneticFluxDensity per kept static interval (mean field of the samples classified as static, and the average of the three axis deviations divided by the square root of the number of averaged samples)

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