From 911929764949c47b47c05db699e7ca2d9c504f3c Mon Sep 17 00:00:00 2001 From: Josh Date: Mon, 5 Feb 2018 09:35:58 -0600 Subject: [PATCH] Expose prediction, covariance prediction methods (#9) * 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 --- src/kalman.js | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/kalman.js b/src/kalman.js index 7b563be..c761c08 100644 --- a/src/kalman.js +++ b/src/kalman.js @@ -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)); @@ -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}