Advertisement
miszczo

Untitled

Jan 29th, 2021
1,180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.09 KB | None | 0 0
  1. /*
  2.  * SimpleKalmanFilter - a Kalman Filter implementation for single variable models.
  3.  * Created by Denys Sene, January, 1, 2017.
  4.  * Released under MIT License - see LICENSE file for details.
  5.  */
  6.  
  7. #include "Arduino.h"
  8. #include "SimpleKalmanFilter.h"
  9. #include <math.h>
  10.  
  11. SimpleKalmanFilter::SimpleKalmanFilter(float mea_e, float est_e, float q)
  12. {
  13.   _err_measure=mea_e;
  14.   _err_estimate=est_e;
  15.   _q = q;
  16. }
  17.  
  18. float SimpleKalmanFilter::updateEstimate(float mea)
  19. {
  20.   _kalman_gain = _err_estimate/(_err_estimate + _err_measure);
  21.   _current_estimate = _last_estimate + _kalman_gain * (mea - _last_estimate);
  22.   _err_estimate =  (1.0 - _kalman_gain)*_err_estimate + fabs(_last_estimate-_current_estimate)*_q;
  23.   _last_estimate=_current_estimate;
  24.  
  25.   return _current_estimate;
  26. }
  27.  
  28. void SimpleKalmanFilter::setMeasurementError(float mea_e)
  29. {
  30.   _err_measure=mea_e;
  31. }
  32.  
  33. void SimpleKalmanFilter::setEstimateError(float est_e)
  34. {
  35.   _err_estimate=est_e;
  36. }
  37.  
  38. void SimpleKalmanFilter::setProcessNoise(float q)
  39. {
  40.   _q=q;
  41. }
  42.  
  43. float SimpleKalmanFilter::getKalmanGain() {
  44.   return _kalman_gain;
  45. }
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement