48 static bool kalman_filter_param_check(
EST_FVector &x,
68 if(!kalman_filter_param_check(x,P,Q,R,A,H,z))
70 cerr <<
"Kalman filter parameters inconsistent !" << endl;
80 cerr <<
"predict" << endl;
88 cerr <<
"correct" << endl;
99 if(!
inverse( HPHt_R , HPHt_R_inv, singularity))
101 if(singularity != -1)
103 cerr <<
" H * P * Ht + R is singular !" << endl;
106 cerr <<
"Matrix inversion failed for an unknown reason !" << endl;
110 K = PHt * HPHt_R_inv;
142 if(!kalman_filter_param_check(x,Pinv,Q,Rinv,A,H,z))
144 cerr <<
"Kalman filter parameters inconsistent !" << endl;
156 cerr <<
"Compute P" << endl;
161 Pinv = Pinv + (Ht * Rinv *
H);
163 if(!
inverse(Pinv,P,singularity))
165 if(singularity != -1)
167 cerr <<
"P is singular !" << endl;
170 cerr <<
"Matrix inversion failed for an unknown reason !" << endl;
186 if(!
inverse(P,Pinv,singularity))
188 if(singularity != -1)
190 cerr <<
"Pinv is singular !" << endl;
193 cerr <<
"Matrix inversion failed for an unknown reason !" << endl;
219 int measurement_dim=z.
length();
223 if((state_dim <= 0) ||
224 (measurement_dim <= 0))
226 cerr <<
"No state or measurements !!" << endl;
236 cerr <<
"P, or Pinv, must be a symmetrical square matrix of the same dimension" << endl;
237 cerr <<
"as the state vector, x" << endl;
245 cerr <<
"Q must be a symmetrical square matrix of the same dimension" << endl;
246 cerr <<
"as the state vector, x" << endl;
251 if((R.
num_rows() != measurement_dim) ||
254 cerr <<
"R, or Rinv, must be a symmetrical square matrix of the same dimension" << endl;
255 cerr <<
"as the measurement vector, z" << endl;
262 cerr <<
"A must be a square matrix of the same dimension" << endl;
263 cerr <<
"as the state vector, x" << endl;
267 if((H.
num_rows() != measurement_dim) ||
270 cerr <<
"H must have dimensions to fit z = Hx" << endl;
EST_FVector subtract(const EST_FVector &a, const EST_FVector &b)
elementwise subtract
ssize_t num_columns() const
return number of columns
A vector class for floating point numbers. EST_FVector x should be used instead of float *x wherever ...
ssize_t num_rows() const
return number of rows
void eye(EST_FMatrix &a, const ssize_t n)
some useful matrix creators make an identity matrix of dimension n
void symmetrize(EST_FMatrix &a)
enforce symmetry
EST_FVector add(const EST_FVector &a, const EST_FVector &b)
elementwise add
INLINE ssize_t length() const
number of items in vector.
void transpose(const EST_FMatrix &a, EST_FMatrix &b)
exchange rows and columns
bool kalman_filter(EST_FVector &x, EST_FMatrix &P, EST_FMatrix &Q, EST_FMatrix &R, EST_FMatrix &A, EST_FMatrix &H, EST_FVector &z)
bool kalman_filter_Pinv(EST_FVector &x, EST_FMatrix &Pinv, EST_FMatrix &Q, EST_FMatrix &Rinv, EST_FMatrix &A, EST_FMatrix &H, EST_FVector &z)
int inverse(const EST_FMatrix &a, EST_FMatrix &inv)
inverse