Skip to content

Commit

Permalink
Expose prediction, covariance prediction methods (#9)
Browse files Browse the repository at this point in the history
* Expose prediction, covariance prediction methods

This is helpful if you would like to show a predicted next value from the filter.

* Change predictCovariance name to uncertainty
  • Loading branch information
joshbeckman authored and wouterbulten committed Feb 5, 2018
1 parent cb6b50b commit 9119297
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/kalman.js
Expand Up @@ -46,8 +46,8 @@ export default class KalmanFilter {
else {

// Compute prediction
const predX = (this.A * this.x) + (this.B * u);
const predCov = ((this.A * this.cov) * this.A) + this.R;
const predX = this.predict(u);
const predCov = this.uncertainty();

// Kalman gain
const K = predCov * this.C * (1 / ((this.C * predCov * this.C) + this.Q));
Expand All @@ -60,6 +60,23 @@ export default class KalmanFilter {
return this.x;
}

/**
* Predict next value
* @param {Number} [u] Control
* @return {Number}
*/
predict(u = 0) {
return (this.A * this.x) + (this.B * u);
}

/**
* Return uncertainty of filter
* @return {Number}
*/
uncertainty() {
return ((this.A * this.cov) * this.A) + this.R;
}

/**
* Return the last filtered measurement
* @return {Number}
Expand Down

0 comments on commit 9119297

Please sign in to comment.