1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.hipparchus.filtering.kalman.linear;
19
20 import org.hipparchus.exception.MathRuntimeException;
21 import org.hipparchus.filtering.kalman.AbstractKalmanFilter;
22 import org.hipparchus.filtering.kalman.Measurement;
23 import org.hipparchus.filtering.kalman.ProcessEstimate;
24 import org.hipparchus.linear.MatrixDecomposer;
25 import org.hipparchus.linear.RealMatrix;
26 import org.hipparchus.linear.RealVector;
27
28
29
30
31
32
33 public class LinearKalmanFilter<T extends Measurement> extends AbstractKalmanFilter<T> {
34
35
36 private final LinearProcess<T> process;
37
38
39
40
41
42
43 public LinearKalmanFilter(final MatrixDecomposer decomposer,
44 final LinearProcess<T> process,
45 final ProcessEstimate initialState) {
46 super(decomposer, initialState);
47 this.process = process;
48 }
49
50
51 @Override
52 public ProcessEstimate estimationStep(final T measurement)
53 throws MathRuntimeException {
54
55 final LinearEvolution evolution = process.getEvolution(measurement);
56
57
58 final RealMatrix a = evolution.getStateTransitionMatrix();
59 final RealMatrix b = evolution.getControlMatrix();
60 final RealVector u = (b == null) ? null : evolution.getCommand();
61 final RealMatrix q = evolution.getProcessNoiseMatrix();
62
63 RealVector predXk = a.operate(getCorrected().getState());
64 if (b != null) {
65 predXk = predXk.add(b.operate(u));
66 }
67
68 predict(measurement.getTime(), predXk, a, q);
69
70
71 final RealMatrix h = evolution.getMeasurementJacobian();
72 final RealMatrix s = computeInnovationCovarianceMatrix(measurement.getCovariance(), h);
73 final RealVector innovation = (h == null) ? null : measurement.getValue().subtract(h.operate(predXk));
74 correct(measurement, a, innovation, h, s);
75 return getCorrected();
76
77 }
78
79 }