Class: KalmanFilter

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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(options={})
  @covariance           = nil
  @value                = nil
  @measurement          = nil

  # setup defaults
  @process_noise        = (options[:process_noise]        ||  1.0)
  @measurement_noise    = (options[:measurement_noise]    ||  1.0)
  @state_vector         = (options[:state_vector]         ||  1.0)
  @control_vector       = (options[:control_vector]       ||  0.0)

  @measurement_vector   = (options[:measurement_vector]   ||  1.0)
end

Instance Attribute Details

#control_vector=(value) ⇒ Object

Sets the attribute control_vector

Parameters:

  • value

    the value to set the attribute control_vector to.



25
26
27
# File 'lib/kalman_filter.rb', line 25

def control_vector=(value)
  @control_vector = value
end

#measurementObject

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

Parameters:

  • value

    the value to set the attribute measurement_noise to.



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

Parameters:

  • value

    the value to set the attribute measurement_vector to.



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

Parameters:

  • value

    the value to set the attribute process_noise to.



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

Parameters:

  • value

    the value to set the attribute state_vector to.



25
26
27
# File 'lib/kalman_filter.rb', line 25

def state_vector=(value)
  @state_vector = value
end

#valueObject

Returns the current value of the KalmanFilter.



29
30
31
# File 'lib/kalman_filter.rb', line 29

def value
  @value
end