Weighing Gold Example

In this example, we estimate the state of a static system. A static system is a system that doesn’t change its state over a reasonable period. Here, we we estimate the weight of the gold bar. We have unbiased scales (the measurements don’t have a systematic error), but the measurements do include random noise.

  • System: Gold bar
  • System state: Weight of gold bar
  • Model: The dynamic model of the system is constant since we assume that the weight doesn’t change over short periods

To estimate the system state (i.e., the weight value), we can make multiple measurements and average them.

At the time , an estimate would be the average of all previous measurements:

  • is the true value of the weight
  • is the measured value of the weight at time
  • is the estimate of at time (the estimate is made after taking the measurement )
  • is the estimate of the future state () of . The estimate is made at the time . In other words, is a predicted state or extrapolated state.
  • is the estimate of at time (the estimate is made after taking the measurement ).
  • is a prior prediction – the estimate of the state at time . The prediction is made at the time .
    • Basically, the first subscript is the time we are making the estimate for. The second subscript is the time at which the estimate is made.

The dynamic model in this example is static/constant since the weight of gold doesn’t change over time, therefore .

Although our previous equation for is mathematically correct, it is not practical for implementation. In order to estimate , we need to remember all historical measurements; therefore, we need a large memory. We also need to recalculate the average repeatedly if we want to update the estimated value after every new measurement.

It would be more practical to only keep the last estimate, () and update it after every new measurement. The following figure exemplifies the required algorithm:

  • Estimate the current state based on the measurement and prior prediction.
  • Predict the next state based on the current state estimate using the Dynamic Model.

We can modify the averaging equation for our needs using a small mathematical trick.

First, we have the average formula (sum of measurements divided by ):

We can re-arrange this as the sum of measurements plus the last measurement divided by :

Expanding:

Multiplying the first term by :

Re-order:

Re-writing the sum:

Distributing the term :

Re-ordering:

Recall that is the estimated state of at time based on the measurement at the time .

Let’s find (the predicted state of at the time ), based on (the estimation at the time ). In other words, we would like to extrapolate to the time . Since the dynamic model in this example is static, the predicted state of equals the estimated state of with:

Based on the above, we can write the State Update Equation:

The State Update Equation is one of the five Kalman filter equations. It means the following:

The factor is specific to our example. This is called the Kalman Gain. It is denoted by . The subscript indicates that the Kalman Gain can change with every iteration.

Before we get into the Kalman Filter in depth, we will use the Greek letter instead of :

The term is called the measurement residual or innovation – this is the difference between the actual measured state and the state previously predicted based on past information. The innovation contains past information.

In this example, decreases as increases. In the beginning, we don’t have enough information about the current state; thus, the first estimation is based on the first measurement . As we continue, each successive measurement has less weight in the estimation process, since decreases. At some point, the contribution of the new measurements will become negligible.

Let’s continue with the example. Before we make the first measurement, we can guess (or rough estimate) the gold bar weight simply by reading the stamp on the gold bar. It is called the initial guess, and it is our first estimate. The Kalman Filter requires the initial guess as a preset, which can be very rough.

Numerical Example

Iteration 0

Initialization: Our initial guess of the gold bar weight is 1000 grams. The initial guess is used only once for the filter initiation. Thus, it won’t be required for successive iterations.

Prediction: The weight of the gold bar is not supposed to change. Therefore, the dynamic model of the system is static. Our next state estimate (prediction) equals the initialization:

Iteration 1

Making the weight measurement with the scales:

Calculating the gain. In our example, , so we have

Calculating the current estimate using the state update equation:

The dynamic model of the system is static; thus our next state estimate (prediction) is the same as the current state estimate:

Iteration 2

After a unit time delay, , the predicted estimate from the previous iteration becomes the prior estimate in the current iteration:

Making a second weight measurement:

Calculating the gain:

Calculating the current estimate:

Calculating the prediction:

Iteration 3

Iteration 4

Results

We can keep doing this. The below table summarizes up to the 10th iteration.

The following chart compares the true, measured, and estimated values. The estimation algorithm has a smoothing effect on the measurements and converges toward the true value.

In this example, we’ve developed a simple estimation algorithm for a static system. We have also derived the state update equation, one of the five Kalman Filter equations.