ResidualFilter.java

  1. /* Copyright 2002-2024 CS GROUP
  2.  * Licensed to CS GROUP (CS) under one or more
  3.  * contributor license agreements.  See the NOTICE file distributed with
  4.  * this work for additional information regarding copyright ownership.
  5.  * CS licenses this file to You under the Apache License, Version 2.0
  6.  * (the "License"); you may not use this file except in compliance with
  7.  * the License.  You may obtain a copy of the License at
  8.  *
  9.  *   http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.orekit.estimation.measurements.filtering;

  18. import org.hipparchus.util.FastMath;
  19. import org.orekit.estimation.measurements.EstimatedMeasurementBase;
  20. import org.orekit.estimation.measurements.ObservedMeasurement;
  21. import org.orekit.propagation.SpacecraftState;

  22. /**
  23.  * Residual pre-processing filter.
  24.  * <p>
  25.  * The measurement residual is defined by the difference between
  26.  * the observed value and the estimated value of the measurement.
  27.  * </p>
  28.  * @param <T> the type of the measurement
  29.  * @author Bryan Cazabonne
  30.  * @author David Soulard
  31.  * @since 10.2
  32.  */
  33. public class ResidualFilter<T extends ObservedMeasurement<T>> implements MeasurementFilter<T> {

  34.     /** Threshold over which the measurement will be rejected. */
  35.     private final double threshold;

  36.     /**
  37.      * Constructor.
  38.      * @param threshold maximum value for the measurement residual
  39.      */
  40.     public ResidualFilter(final double threshold) {
  41.         this.threshold  = threshold;
  42.     }

  43.     /** {@inheritDoc} */
  44.     @Override
  45.     public void filter(final ObservedMeasurement<T> measurement, final SpacecraftState state) {

  46.         // Computation of the estimated value of the measurement
  47.         final SpacecraftState[]           sc             = new SpacecraftState[] {state};
  48.         final EstimatedMeasurementBase<T> estimated      = measurement.estimateWithoutDerivatives(sc);
  49.         final double[]                    estimatedValue = estimated.getEstimatedValue();

  50.         // Observed parameters (i.e. value and standard deviation)
  51.         final double[] observedValue = measurement.getObservedValue();
  52.         final double[] sigma         = measurement.getTheoreticalStandardDeviation();

  53.         // Check if observed value is not too far from estimation
  54.         for (int i = 0; i < observedValue.length; i++) {
  55.             if (FastMath.abs(observedValue[i] - estimatedValue[i]) > threshold * sigma[i]) {
  56.                 // Observed value is too far, measurement is disabled
  57.                 measurement.setEnabled(false);
  58.             }
  59.         }

  60.     }

  61. }