@@ -161,7 +161,9 @@ class KalmanFilter(object):
161
161
Here is a filter that tracks position and velocity using a sensor that only
162
162
reads position.
163
163
164
- First construct the object with the required dimensionality.
164
+ First construct the object with the required dimensionality. Here the state
165
+ (`dim_x`) has 2 coefficients (position and velocity), and the measurement
166
+ (`dim_z`) has one. In FilterPy `x` is the state, `z` is the measurement.
165
167
166
168
.. code::
167
169
@@ -191,28 +193,20 @@ class KalmanFilter(object):
191
193
f.F = np.array([[1.,1.],
192
194
[0.,1.]])
193
195
194
- Define the measurement function:
196
+ Define the measurement function. Here we need to convert a position-velocity
197
+ vector into just a position vector, so we use:
195
198
196
199
.. code::
197
200
198
- f.H = np.array([[1.,0.]])
201
+ f.H = np.array([[1., 0.]])
199
202
200
- Define the covariance matrix. Here I take advantage of the fact that
201
- P already contains np.eye(dim_x), and just multiply by the uncertainty:
202
-
203
- .. code::
204
-
205
- f.P *= 1000.
206
-
207
- I could have written:
203
+ Define the state's covariance matrix P.
208
204
209
205
.. code::
210
206
211
207
f.P = np.array([[1000., 0.],
212
208
[ 0., 1000.] ])
213
209
214
- You decide which is more readable and understandable.
215
-
216
210
Now assign the measurement noise. Here the dimension is 1x1, so I can
217
211
use a scalar
218
212
@@ -226,7 +220,7 @@ class KalmanFilter(object):
226
220
227
221
f.R = np.array([[5.]])
228
222
229
- Note that this must be a 2 dimensional array, as must all the matrices .
223
+ Note that this must be a 2 dimensional array.
230
224
231
225
Finally, I will assign the process noise. Here I will take advantage of
232
226
another FilterPy library function:
@@ -239,15 +233,14 @@ class KalmanFilter(object):
239
233
240
234
Now just perform the standard predict/update loop:
241
235
242
- while some_condition_is_true:
243
-
244
236
.. code::
245
237
246
- z = get_sensor_reading()
247
- f.predict()
248
- f.update(z)
238
+ while some_condition_is_true:
239
+ z = get_sensor_reading()
240
+ f.predict()
241
+ f.update(z)
249
242
250
- do_something_with_estimate (f.x)
243
+ do_something_with_estimate (f.x)
251
244
252
245
253
246
**Procedural Form**
@@ -309,7 +302,7 @@ class KalmanFilter(object):
309
302
310
303
x_prior : numpy.array(dim_x, 1)
311
304
Prior (predicted) state estimate. The *_prior and *_post attributes
312
- are for convienence ; they store the prior and posterior of the
305
+ are for convenience ; they store the prior and posterior of the
313
306
current epoch. Read Only.
314
307
315
308
P_prior : numpy.array(dim_x, dim_x)
@@ -325,16 +318,18 @@ class KalmanFilter(object):
325
318
Last measurement used in update(). Read only.
326
319
327
320
R : numpy.array(dim_z, dim_z)
328
- Measurement noise matrix
321
+ Measurement noise covariance matrix. Also known as the
322
+ observation covariance.
329
323
330
324
Q : numpy.array(dim_x, dim_x)
331
- Process noise matrix
325
+ Process noise covariance matrix. Also known as the transition
326
+ covariance.
332
327
333
328
F : numpy.array()
334
- State Transition matrix
329
+ State Transition matrix. Also known as `A` in some formulation.
335
330
336
331
H : numpy.array(dim_z, dim_x)
337
- Measurement function
332
+ Measurement function. Also known as the observation matrix, or as `C`.
338
333
339
334
y : numpy.array
340
335
Residual of the update step. Read only.
0 commit comments