Class: KalmanFilter
- Inherits:
-
Object
- Object
- KalmanFilter
- Defined in:
- lib/kalman_filter.rb
Overview
A Ruby implimentation of a Kalman Filter, linear quadratic estimator. Noisy sensor data, approximations in the equations that describe the system evolution, and external factors that are not accounted for all place limits on how well it is possible to determine the system’s state. The Kalman filter deals effectively with the uncertainty due to noisy sensor data and to some extent also with random external factors. The Kalman filter produces an estimate of the state of the system as an average of the system’s predicted state and of the new measurement using a weighted average. The purpose of the weights is that values with better (i.e., smaller) estimated uncertainty are “trusted” more. The weights are calculated from the covariance, a measure of the estimated uncertainty of the prediction of the system’s state. The result of the weighted average is a new state estimate that lies between the predicted and measured state, and has a better estimated uncertainty than either alone. This process is repeated at every time step, with the new estimate and its covariance informing the prediction used in the following iteration. This means that the Kalman filter works recursively and requires only the last “best guess”, rather than the entire history, of a system’s state to calculate a new state.
- Author
-
Joseph J. Viscomi ([email protected])
- License
-
MIT
Instance Attribute Summary collapse
-
#control_vector ⇒ Object
writeonly
Sets the attribute control_vector.
-
#measurement ⇒ Object
Returns the last value supplied to the KalmanFilter.
-
#measurement_noise ⇒ Object
writeonly
Sets the attribute measurement_noise.
-
#measurement_vector ⇒ Object
writeonly
Sets the attribute measurement_vector.
-
#process_noise ⇒ Object
writeonly
Sets the attribute process_noise.
-
#state_vector ⇒ Object
writeonly
Sets the attribute state_vector.
-
#value ⇒ Object
readonly
Returns the current value of the KalmanFilter.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ KalmanFilter
constructor
- Creates a new KalmanFilter Params:
options
-
Object
.
- Creates a new KalmanFilter Params:
Constructor Details
#initialize(options = {}) ⇒ KalmanFilter
Creates a new KalmanFilter Params:
options
-
Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/kalman_filter.rb', line 37 def initialize(={}) @covariance = nil @value = nil @measurement = nil # setup defaults @process_noise = ([:process_noise] || 1.0) @measurement_noise = ([:measurement_noise] || 1.0) @state_vector = ([:state_vector] || 1.0) @control_vector = ([:control_vector] || 0.0) @measurement_vector = ([:measurement_vector] || 1.0) end |
Instance Attribute Details
#control_vector=(value) ⇒ Object
Sets the attribute control_vector
25 26 27 |
# File 'lib/kalman_filter.rb', line 25 def control_vector=(value) @control_vector = value end |
#measurement ⇒ Object
Returns the last value supplied to the KalmanFilter.
32 33 34 |
# File 'lib/kalman_filter.rb', line 32 def measurement @measurement end |
#measurement_noise=(value) ⇒ Object
Sets the attribute measurement_noise
25 26 27 |
# File 'lib/kalman_filter.rb', line 25 def measurement_noise=(value) @measurement_noise = value end |
#measurement_vector=(value) ⇒ Object
Sets the attribute measurement_vector
25 26 27 |
# File 'lib/kalman_filter.rb', line 25 def measurement_vector=(value) @measurement_vector = value end |
#process_noise=(value) ⇒ Object
Sets the attribute process_noise
25 26 27 |
# File 'lib/kalman_filter.rb', line 25 def process_noise=(value) @process_noise = value end |
#state_vector=(value) ⇒ Object
Sets the attribute state_vector
25 26 27 |
# File 'lib/kalman_filter.rb', line 25 def state_vector=(value) @state_vector = value end |
#value ⇒ Object
Returns the current value of the KalmanFilter.
29 30 31 |
# File 'lib/kalman_filter.rb', line 29 def value @value end |