# UnscentedKalmanFilter - measurement noise covariance?

Hello all,
Is there a way to include measurement noise covariance when building an instance of UnscentedKalmanFilter? Thank you,
Erin

Hi @erinf

Sorry for the delay…

The answer to your question is yes and no. Please find below the code that create the measurement noise covariance.

``````        final RealMatrix covariance;
if (observedMeasurement.getMeasurementType().equals(PV.MEASUREMENT_TYPE)) {
// For PV measurements we do have a covariance matrix and thus a correlation coefficients matrix
final PV pv = (PV) observedMeasurement;
covariance = MatrixUtils.createRealMatrix(pv.getCovarianceMatrix());
} else if (observedMeasurement.getMeasurementType().equals(Position.MEASUREMENT_TYPE)) {
// For Position measurements we do have a covariance matrix and thus a correlation coefficients matrix
final Position position = (Position) observedMeasurement;
covariance = MatrixUtils.createRealMatrix(position.getCovarianceMatrix());
} else {
// For other measurements we do not have a covariance matrix.
// Thus the correlation coefficients matrix is an identity matrix.
covariance = MatrixUtils.createRealIdentityMatrix(observedMeasurement.getDimension());
final double[] sigma = observedMeasurement.getTheoreticalStandardDeviation();
for (int i = 0; i < sigma.length; i++) {
covariance.setEntry(i, i, sigma[i] * sigma[i]);
}

}
``````

Theoretically, you can’t set this matrix. Orekit computes it based on the measurement standard deviation (i.e., the sigma parameter when creating a new measurement).
They are two exceptions: `PV` and `Position` measurements.

For both there is a constructor asking the sigma values. Using it, the measurement noise matrix will be computed like the other measurement types. But, there is another constructeur that doesn’t ask for the sigma value, but for the measurement noise covariance. Like that, you can set a “custom” measurement noise covariance matrix.

I saw that @MaximeJ gave you a lot of useful information in the following post: Measurement/observation noise covariance in sequential filtering Best regards,
Bryan