Measurement Noise Covariance Estimation
| This documentation was generated with the assistance of AI. Please report any inaccuracies. |
A Kalman filter needs a measurement noise covariance matrix to
weigh how much it should trust each incoming measurement. Rather than guessing , it can be measured
directly: hold the system’s true state constant (e.g. keep a sensor motionless) and record repeated samples —
any variation left in the data, once its mean is removed, is pure measurement noise. This class implements that
idea as a running (incremental) estimate of the sample mean and covariance, updated one sample at a time rather
than requiring the whole dataset up front. It is implemented as MeasurementNoiseCovarianceEstimator in the
com.irurueta.numerical.signal.processing package; the general approach of updating a mean and covariance
incrementally, one sample at a time, is described in
Wikipedia contributors, Algorithms for calculating variance.
Running mean and covariance
For each new sample (an mp-dimensional vector, with mp the number of measurement
dimensions), the sample count, average, and covariance are all updated in place. The average is updated as:
The covariance update folds the outer product of the new sample’s deviation from the previous mean and from the updated mean into the running covariance, rescaled for the new sample count:
Since with , the outer product above is equivalent to . This is the Welford-style recursive relationship described in Wikipedia contributors, Algorithms for calculating variance, and the result equals the batch population covariance of all samples seen so far at every step.
This is the relationship implemented by update(double[]): sampleNoMean is first computed as the new sample minus
the pre-update sampleAverage, sampleAverage is then updated, the outer product of sampleNoMean is scaled by
N / (N + 1), and measurementNoiseCov is rescaled by sampleCount, has that term added, and is rescaled again by
1 / nextCount.
Library implementation
MeasurementNoiseCovarianceEstimator(int measureParams) allocates the running state for a system with
measureParams measurement dimensions (mp).
-
update(double[] sample)— folds one new sample into the running mean and covariance, and returns the updated covariance matrix.samplemust have lengthmp. -
getMeasurementNoiseCov()— the current running covariance estimate (mp×mp), suitable for passing directly toKalmanFilter.setMeasurementNoiseCov(Matrix). -
getSampleAverage()— the current running mean (lengthmp); mainly useful as a bias/offset check, since a properly zeroed sensor should show an average close to zero. -
getSampleCount()— the number of samples folded in so far.
Collect samples with the sensor in a fixed, representative state (e.g. stationary, at the operating
temperature the sensor will actually run at) before starting a
KalmanFilter — noise characteristics measured under different conditions
than the filter will actually run under can under- or over-state how much the filter should trust each
measurement.
|
Example
Estimating the noise covariance of a 3-axis accelerometer held motionless, then using it to configure a Kalman filter’s measurement noise:
final var noiseEstimator = new MeasurementNoiseCovarianceEstimator(3);
for (final var sample : stationarySamples) { // stationarySamples: List<double[]> of length-3 readings
noiseEstimator.update(sample);
}
final var measurementNoiseCov = noiseEstimator.getMeasurementNoiseCov();
final var filter = new KalmanFilter(6, 3); // e.g. position + velocity per axis, measuring acceleration
filter.setMeasurementNoiseCov(measurementNoiseCov);
| Class | Javadoc | Source |
|---|---|---|
|
||
|