Combining Two Measurements

A good thermometer and a bad one disagree. Their plain average is twice as noisy as the good one alone. Weight each by one over its variance, and the result beats both.

Pick an estimator, then drag the noise of sensor B. Watch the four error bars under the chart. Then we build the rule piece by piece: precision, the error bowl, the shrinking variance, and the Kalman update hidden inside it.

You need basic arithmetic and the idea of a bell curve. We build the rest from zero.

Lesson 3 of 22 in Sensor Fusion: Classical to Modern. It follows Fusion Architectures and leads to The Bayes Filter.

Fuse a good sensor and a bad one

±0.5 °C
±2.0 °C

Toy simulation, illustrative: the true temperature is 21 °C and each sensor adds Gaussian noise of the size you set. The bars are the root mean square error over the last 300 readings.

Chapter 0

Two Thermometers, One Truth

See two honest sensors disagree on every reading, and name what you must know about each

You hold two thermometers in one pot of water. One reads 20.0 °C. The other reads 22.0 °C. The water has one temperature, and you must write one number on the sheet. Which number?

Every Kalman filter, GPS receiver and poll average answers this question many times a second: two noisy readings of one quantity, one best estimate. The first guess is to split the difference, 21.0 °C. That is right only if both thermometers are equally good. Usually you know more: one is a cheap probe and one is a lab instrument.

What we know about each sensor

Each sensor gives a reading and a variance: the average of its squared errors. A small variance means the readings sit close to the truth. With made-up numbers: errors of +0.4, −0.6 and +0.2 °C give a variance of (0.16 + 0.36 + 0.04)/3 = 0.19 °C².

Two assumptions carry the whole lesson. Chapter 9 breaks each one.

Pile up readings from both sensors

Each press adds 20 readings from each sensor. Blue is the lab thermometer, orange the cheap probe. Drag the noise and watch the width of each pile.

±0.5 °C
±2.0 °C

Illustrative toy: true value 21 °C, Gaussian noise, seeded so every visit shows the same readings.

Both piles centre on the dashed truth, so neither sensor leans. The orange pile is four times wider. If you treat the two as equals, the estimate jumps around with the probe. Measure each sensor's spread on a pot of known temperature, then trust it in proportion. The rest of this lesson computes that proportion.

The road

  1. A trust dial: the weighted average, and why the plain average is a special case.
  2. Precision: one over the variance, the number for trust.
  3. The error bowl: find the weight that makes the error smallest.
  4. The rule: the precision-weighted average, worked by hand.
  5. Precisions add: why the result beats the better sensor, and the square root of n law.
  6. The Kalman update: the same rule, renamed.
  7. Showcase: a thousand fusions, then a sensor that lies.
  8. Where variances come from: measure them, and gate out faults.
  9. Three traps: optimistic variances, correlation and bias.
  10. Field guide: the numbers, the code and where to go next.
A cheap thermometer reads 20 °C and a lab thermometer reads 22 °C. Why can 21 °C be a poor answer?

Chapter 1

A Weighted Average Has a Trust Dial

Replace the fixed half and half with a dial, and watch where the fused estimate lands

Take an extreme case. Sensor A is accurate to about 1 m and reads 100 m. Sensor B is accurate to about 10 m and reads 130 m. The plain average says 115 m. It gives B's wild reading half the say.

The fix is a dial. Call the number you report the fused estimate, x-f. Call the weight on sensor A w, a number from 0 to 1. Sensor B gets the rest, 1 − w.

Say it aloud

x-f equals w times x-A, plus one minus w, times x-B.

xf
x-f the fused estimate: the one number you report.
w
w the weight on sensor A, from 0 to 1.
xA
x-A the reading of sensor A.
1 − w
one minus w the weight on sensor B. The two weights add to 1.
xB
x-B the reading of sensor B.
In plain words

Take a share w of reading x-A and the rest of reading x-B, then add them. If both sensors read the same value, x-f is that value for any w.

With numbers

A reads 100 m, B reads 130 m. With w = 0.5, x-f = 50 + 65 = 115 m, the plain average. With w = 0.8, x-f = 80 + 26 = 106 m. With w = 1, x-f = 100 m and B drops out.

So the plain average is the dial stuck at 0.5. Which setting is best? One pair of readings cannot tell you, because noise moves them. Repeat the experiment many times and look at the spread of x-f.

Turn the trust dial, watch the cloud

Each teal dot is one fused estimate from a fresh pair of readings. Sensor A has a noise of ±1 m, sensor B ±3 m. Drag w and find the narrowest teal cloud.

0.50

Illustrative toy: true position 100 m, 60 seeded pairs of Gaussian readings. The spread is the expected standard deviation of x-f at this w.

The narrowest cloud sits near w = 0.9, not 0.5. The best dial depends on which sensor is tighter. A dial set by hand also goes stale: rain or age changes a sensor, and the estimate drifts toward the worse one. Chapter 3 computes w from the variances, so it follows the sensors.

In x-f = w · x-A + (1 − w) · x-B, what does w = 0.5 give, and why is it often not the best choice?

Chapter 2

Precision: One Over the Variance

Turn the vague word trust into a number that grows as a sensor gets better

A lab thermometer has a typical error of 0.5 °C. A cheap probe has 2 °C. The typical error is the standard deviation σ (sigma). Its square σ² is the variance: 0.25 °C² for the lab thermometer and 4 °C² for the probe.

Squaring does two jobs. Every error counts as positive, so +2 and −2 do not cancel. Big errors count more: an error of 4 adds 16, an error of 2 adds only 4.

Variance is small for a good sensor. We want a number that is big for a good sensor, so we flip it. Call it the precision P.

Say it aloud

P equals one over sigma squared.

P
P the precision: how sure a sensor is, in one over the reading's units squared.
σ²
sigma squared the variance: the square of the typical error σ.
In plain words

Square the sensor's typical error sigma to get its variance. Divide 1 by the variance. A small error gives a big precision P.

With numbers

Lab thermometer: sigma = 0.5 °C, sigma squared = 0.25, P = 1/0.25 = 4. Cheap probe: sigma = 2 °C, sigma squared = 4, P = 0.25. The lab thermometer is 16 times more precise.

Widen a bell, watch its precision fall

The bells show how each sensor's readings spread. The purple bars show each sensor's share of the total precision. Drag a sigma.

0.5 °C
2.0 °C

Illustrative values. The bars show P-A/(P-A + P-B) and P-B/(P-A + P-B), the vote shares Chapter 3 derives.

Why flip the variance and not use sigma? When you combine independent sensors, precision is the quantity that adds. Chapter 5 proves it.

Precision is only as good as the sigma you feed it. Suppose a datasheet says 0.5 °C but the probe wanders by 1.5 °C. You compute P = 4 when the truth is 0.44, so you overstate its precision nine times. Chapter 8 measures sigma properly.

Sensor A has variance 0.25 and sensor B has variance 4. What are their precisions?

Chapter 3

Find the Bottom of the Error Bowl

Write the fused variance as a function of the dial, then find the dial that makes it smallest

Which w is best? Choose the w that makes the fused estimate's error smallest on average. Measure that error by its variance, sigma-f squared. Two facts about variance do the work. Scale a reading by c and its variance scales by c squared. Add two independent readings and their variances add.

Say it aloud

sigma-f squared of w equals w squared times sigma-A squared, plus one minus w, squared, times sigma-B squared.

σf²(w)
sigma-f squared of w the variance of the fused estimate when the dial is at w.
w²
w squared the share of A's noise that leaks into x-f.
σA²
sigma-A squared the variance of sensor A.
(1 − w)²
one minus w, squared the share of B's noise that leaks into x-f.
σB²
sigma-B squared the variance of sensor B.
In plain words

Multiply A's variance by w squared and B's variance by one minus w, squared. Add the two. The sum is how noisy x-f is at that dial setting.

With numbers

Thermometers: sigma-A squared = 0.25, sigma-B squared = 4. At w = 0.5: 0.25 × 0.25 + 0.25 × 4 = 1.06. At w = 1: 0.25. At w = 0.94: 0.235, the lowest point.

Slide the dial into the bowl

The teal curve is sigma-f squared for every w. The faint blue and orange curves are the two leak terms. Drag w to the bottom, then change a variance and watch the bottom move.

0.50
0.25
4.00

Exact curve for independent sensors; the starting values are the two thermometers.

The bottom of the bowl is where the slope is zero. Take the slope with respect to w, set it to zero and solve:

2w · σA² − 2(1 − w) · σB² = 0  →  w* = σB² / (σA² + σB²)

Call the best weight w-star. Divide its top and bottom by sigma-A squared times sigma-B squared. Each variance turns into a precision:

Say it aloud

w-star equals P-A over, P-A plus P-B.

w*
w-star the best weight on sensor A, at the bottom of the bowl.
PA
P-A the precision of A, one over sigma-A squared.
PA + PB
P-A plus P-B the total precision of both sensors.
In plain words

Add the two precisions. The weight w-star on A is A's share of that total. B gets the rest.

With numbers

P-A = 4 and P-B = 0.25, so the total is 4.25. w-star = 4/4.25 = 0.941, and B gets 0.059.

One failure hides here. If you set a variance to zero, its precision is infinite and w-star pins to 1. The weights read 1.00 and 0.00, and the second sensor does nothing. Give every variance a floor above zero.

We set the slope of the fused variance to zero. What does that find, and what is w-star when both variances are equal?

Chapter 4

The Precision-Weighted Average

Put the best weight into the dial and get the one rule this whole series builds on

Put w-star into the trust dial. Each sensor's weight becomes its share of the total precision. Each reading votes, as loud as its precision.

Say it aloud

x-f equals P-A times x-A, plus P-B times x-B, all over P-A plus P-B.

xf
x-f the fused estimate.
PA
P-A the precision of sensor A: how loud its vote is.
xA
x-A the reading of sensor A.
PB
P-B the precision of sensor B.
xB
x-B the reading of sensor B.
PA + PB
P-A plus P-B the total precision. Dividing by it turns the votes into an average.
In plain words

Multiply each reading by its precision. Add the two products. Divide by the sum of the precisions.

With numbers

Thermometers: (4 × 22.0 + 0.25 × 20.0)/4.25 = (88 + 5)/4.25 = 21.88 °C. The plain average said 21.00. The rule leans 94% toward the lab thermometer.

This is the inverse-variance weighted average. Statisticians call it the best linear unbiased estimator (BLUE): no other weighted average of unbiased readings has a smaller variance. A second case: a survey GPS reads 100.0 m with variance 0.25 m², a phone chip reads 109.0 m with variance 9 m². The precisions are 4 and 0.111, so x-f = 100.24 m. The plain average, 104.5 m, lands 4.3 m toward the chip.

Edge caseWeights A / Bx-f becomes
Equal variances0.5 / 0.5the plain average
B's variance huge (a dead sensor)near 1 / near 0A's reading, with no special code
A's variance tinynear 1 / near 0A's reading

Set two readings, watch the trust split

The purple bar shows how the vote splits. Below it, each sensor's reading has a bar of one sigma, and the teal dot is x-f. Raise B's variance and watch x-f slide toward A.

70
1.0
30
4.0

Exact arithmetic on the numbers you set; the bars are one sigma wide on each side.

pythondef fuse(x_a, var_a, x_b, var_b):
    p_a, p_b = 1.0 / var_a, 1.0 / var_b           # precisions: the vote strengths
    x_f = (p_a * x_a + p_b * x_b) / (p_a + p_b)    # precision-weighted average
    var_f = 1.0 / (p_a + p_b)                    # precisions add (Chapter 5)
    return x_f, var_f

fuse(22.0, 0.25, 20.0, 4.0)    # (21.88, 0.235)  leans to A, tighter than A
fuse(22.0, 1.0, 20.0, 1.0)     # (21.0, 0.5)     equal trust: the plain average
fuse(22.0, 0.25, 20.0, 1e9)    # (22.0, 0.25)    a dead sensor drops out

A dead sensor needs no special code: give it a huge variance. A frozen sensor is worse. It repeats its last value and still reports its normal variance. If a sensor's readings stop changing, set its variance huge until they move again.

Sensor A reads 10 with variance 1. Sensor B reads 16 with variance 2. What is x-f?

Chapter 5

Precisions Add, So Fusion Sharpens

Find how sure the fused estimate is, and see it beat the better sensor

How sure is x-f? Put w-star back into the bowl formula. The algebra collapses to the product of the two variances over their sum:

σf² = σA² · σB² / (σA² + σB²)

Take one over both sides. Call one over sigma-f squared the fused precision, P-f:

Say it aloud

P-f equals P-A plus P-B.

Pf
P-f the fused precision, one over sigma-f squared.
PA
P-A the precision of sensor A.
PB
P-B the precision of sensor B.
In plain words

Add the two precisions to get P-f. One over P-f is the fused variance.

With numbers

P-f = 4 + 0.25 = 4.25, so sigma-f squared = 1/4.25 = 0.235 °C² and sigma-f = 0.485 °C. The lab thermometer alone had 0.5 °C. A worse sensor made the best one better.

Both precisions are positive, so P-f is larger than either one. The fused variance is always below the smaller input variance. For honest, independent sensors, fusion never hurts.

The square root of n law

Fuse n readings that each have sigma. The precision adds n times, so the fused sigma falls with the square root of n:

σf = σ / √n

With sigma = 2 °C: 4 readings give 1 °C, 16 give 0.5 °C, 100 give 0.2 °C. Each halving of the error costs four times the readings.

A second road: multiply two bells

Treat each reading as a bell of belief, centred at the reading, as wide as its sigma. To combine independent evidence, multiply the two bells point by point. The product of two bells is another bell. Its centre is x-f and its precision is P-A + P-B. Two different derivations reach one answer.

Multiply two bells

Blue and orange are the two sensors' bells. Teal is their product, scaled to area 1. Drag the centres and widths: the teal bell is always the narrowest.

−1.5
0.70
1.5
1.40

Exact Gaussian product, on an illustrative axis.

The square root of n law needs independent readings. Ten readings one millisecond apart share the same slow drift. The symptom is that averaging stops helping after a few readings. Plot the error against n to see it, then space the readings out or use an Allan variance plot (Chapter 8).

You fuse a lab thermometer (variance 0.25) with a cheap one (variance 4). What is the fused variance?

Chapter 6

The Kalman Update Is This Rule, Renamed

Rename sensor A as the prediction and sensor B as the new measurement, and derive the Kalman gain

A Kalman filter tracks a quantity over time. At each tick it holds a prior: its prediction, with a variance. Then a measurement arrives with its own variance. The filter fuses the two with this lesson's rule.

Kalman books use their own names. The prior is x-minus with variance P-minus. The measurement is z with variance R. Add and subtract the prior inside x-f: x-f = x-minus + (1 − w)(z − x-minus). The fraction 1 − w is the Kalman gain K.

Say it aloud

K equals P-minus over, P-minus plus R.

K
K the Kalman gain: the fraction of the gap to the measurement the filter moves, from 0 to 1.
P−
P-minus the variance of the prior. In Kalman notation P is a variance, not a precision.
P− + R
P-minus plus R the total variance of prior and measurement.
R
R the variance of the measurement noise.
In plain words

Add the two variances. K is the prior's share of that total. An unsure prior gives a big K.

With numbers

Prior variance P-minus = 4, measurement variance R = 1. K = 4/5 = 0.8.

Say it aloud

x equals x-minus plus K times, z minus x-minus.

x
x the updated estimate, the same number as x-f.
x−
x-minus the prior estimate: the filter's prediction.
K
K the Kalman gain from above.
z − x−
z minus x-minus the innovation: the measurement z minus the prediction, how much the measurement surprised the filter.
In plain words

Find the surprise, z minus x-minus. Start at the prediction x-minus and move a fraction K of the surprise.

With numbers

Prior x-minus = 60, measurement z = 40, K = 0.8. Innovation = −20. x = 60 + 0.8 × (−20) = 44. The precision-weighted average gives (0.25 × 60 + 1 × 40)/1.25 = 44 as well.

The variance update matches Chapter 5. Call the new variance P: P = (1 − K) · P-minus = 0.2 × 4 = 0.8, and 1/(0.25 + 1) = 0.8.

SituationKThe filter
Measurement noisy (R large)near 0stays near its prediction
Prediction unsure (P-minus large)near 1jumps to the measurement
Equal variances0.5splits the difference

See one fusion under two names

Top: the prior and the measurement vote by precision. Bottom: start at the prior and move a fraction K toward the measurement. Change the variances; both teal dots stay on one vertical line.

4.00
1.00

Exact arithmetic with prior x-minus = 60 and measurement z = 40.

If you set R too small, K stays near 1 and the filter chases every noisy measurement. The symptom is a jittery track. The innovations come out larger than the square root of P-minus plus R predicts. The fix is to raise R to the measured noise.

K = P-minus/(P-minus + R). If the measurement is extremely noisy (R huge), what does the filter do?

Chapter 7

Run a Thousand Fusions, Then Bias One Sensor

Check every claim of this lesson on a thousand trials, then break the unbiased assumption and watch the rule stay sure

Every claim so far is about averages over many trials. So run many trials. Each trial draws a fresh reading from each sensor and fuses them. The teal histogram is the thousand fused estimates. The blue outline is sensor A alone.

Run 1,000 fusions, then bias sensor B

The teal line over the histogram is the spread the formula claims. The dashed line is the truth. Set the variances, then switch on the bias.

4.0
1.0
+8.0

Illustrative toy: truth 50, Gaussian noise, 1,000 seeded trials. The bias adds a fixed offset to every reading of B while B still reports its variance.

Try these in order:

  1. Set both variances to 4. The histogram centres on 50 with spread 1.41: that is 2 over the square root of 2.
  2. Set A to 0.5 and B to 16. The teal histogram hugs A and is a little narrower than A's outline.
  3. Change anything. The teal spread is always below the smaller input sigma, and the teal line fits the bars.
  4. Set A to 4, B to 1, and switch on a bias of +8. The histogram jumps to 56.4. The claimed line keeps its width of 0.89.
  5. Keep the bias and raise B's variance to 9. The pull drops to about +2.5, because a sloppy liar earns less weight.

Work step 4 by hand. A is honest at 50 with variance 4; B reads 58 with variance 1. The precisions are 0.25 and 1, so x-f = (12.5 + 58)/1.25 = 56.4. The formula claims sigma-f = 0.89. The real error is 6.4, about 7 claimed sigmas. The rule did its arithmetic right on a wrong input.

Sensor B reads 8 units high. When does it pull the fused estimate furthest from the truth?

Chapter 8

Where the Variances Come From

Get an honest variance for each sensor, and reject the readings no variance can explain

The arithmetic is easy. The variances are the hard part, because wrong variances give wrong weights, even with clean maths. There are four sources, from quick to careful.

SourceHowWatch out for
DatasheetSquare the 1-sigma accuracy: ±0.5 °C gives 0.25 °C².Specs given at 2 sigma or as a maximum; lab conditions on a new unit.
Known truthRead a known value many times. Average the squared errors.A reference that is itself noisy.
Allan variancePlot variance against averaging time for drifting sensors, such as gyros and clocks.One number will not describe a drifting sensor.
Innovations, onlineKeep a running average of squared innovations and raise the variance when they grow.Faults that inflate the estimate; gate them out first.

A worked case for the second row. A rangefinder aims at a wall placed at exactly 5.00 m. Ten readings give errors in cm of +2, −1, +3, 0, −2, +1, +2, −3, +1, −3. The squares sum to 42. The variance is 42/10 = 4.2 cm², so sigma is about 2.05 cm.

Datasheet variances come from a lab, on a fresh unit, at room temperature. A hot, dusty, ageing sensor is noisier. Trust the datasheet as is and the fusion becomes overconfident. Start from the datasheet, then inflate from the measured innovations.

Gate before you fuse

A fault is not noise: reject it, do not fuse it. The test uses the innovation ν (nu), the measurement minus the prediction. Its expected variance S is the prior variance plus the measurement variance, P-minus + R. Pick a gate width g in sigmas, and reject a reading when:

|ν| > g · √S

With P-minus = 4 and R = 1, S = 5 and its square root is 2.24. A 3-sigma gate rejects any innovation beyond 6.7.

Set the gate width

Orange dots are 195 honest innovations. Red dots are 5 faults. The band is the gate. Narrow it and you reject honest readings; widen it and faults slip through.

3.0

Illustrative toy: S = 5, so one sigma is 2.24. The faults sit at 3.4, 4.0, 5.4, 3.7 and 6.0 sigma.

Your fusion code is correct, but in the field its error bars are too narrow. What is the likely cause?

Chapter 9

Three Ways to Fool the Rule

Break each assumption in turn, and learn the test that catches it

The rule is optimal only if its inputs are true: unbiased sensors, independent errors, correct variances. Break one and it still returns a confident number. The danger is not a crash. It is a narrow error bar around a wrong answer.

TrapSymptomTestFix
Optimistic variancesReal errors larger than the claimed sigmaThe average of ν²/S, the normalized innovation squared, sits well above 1Measure the variances; inflate them
Correlated sensorsA second sensor adds little real accuracyList shared error sources; check whether the two residuals move togetherModel the correlation, or use sensors of different kinds
BiasA steady offset in one directionThe mean of a sensor's residuals over time is far from 0Calibrate out the offset, or reject the sensor

Correlation, worked

Two GPS receivers on one car share the same atmospheric delay. Each has variance sigma squared = 4 m². Call the correlation of their errors ρ (rho): 0 when independent, 1 when the errors are identical. Average the two readings. The true variance of the average, sigma-true squared, is:

Say it aloud

sigma-true squared equals sigma squared times, one plus rho, over two.

σtrue²
sigma-true squared the real variance of the average of the two readings.
σ²
sigma squared the variance of each receiver, 4 m² here.
(1 + ρ) / 2
one plus rho, over two the share of the variance that averaging keeps. Rho is the correlation, from 0 to 1.
In plain words

With rho at 0, averaging halves the variance. As rho grows, the second receiver repeats the first one's error. At rho = 1 averaging keeps the whole variance.

With numbers

sigma squared = 4 m². Rho = 0 gives 2 m², rho = 0.5 gives 3 m², rho = 1 gives 4 m². The independent formula reports 2 m² every time.

Correlate the two receivers

Each dot is one pair of errors: A across, B up. Raise rho and the cloud stretches along the diagonal. The bars compare what the formula claims with the truth.

0.50

Illustrative toy: 140 seeded error pairs, each receiver with sigma = 2 m. The bars use the exact formula.

Bias, worked

Sensor B's residuals, its reading minus the fused estimate, over six ticks: +1.8, +2.1, +1.9, +2.0, +2.2, +1.7. All are positive and the mean is +1.95. An honest sensor's residuals straddle zero. Subtract 2 from every reading of B before you fuse.

pythondef monitor(innovations, S, residuals):
    # innovations: measurement - prediction; S = P_minus + R, their expected variance
    nis = sum(v * v / S for v in innovations) / len(innovations)   # near 1 if variances are honest
    mean_r = sum(residuals) / len(residuals)                    # near 0 if the sensor is unbiased
    return {"overconfident": nis > 2.0, "mean_residual": mean_r}

monitor([2.1, -1.5, 3.0, -2.4], 5.0, [1.8, 2.1, 1.9, 2.0, 2.2, 1.7])
# {'overconfident': False, 'mean_residual': 1.95}  -> the variances look fine, B is biased
The fused estimate sits a steady 2 units off the truth, always in one direction. Which trap is this, and which test finds it?

Chapter 10

Field Guide

Keep the numbers, the checklist and the code in one place, and see where the rule goes next

Two unbiased, independent readings of one quantity combine best when you weight each one by its precision, one over its variance. The precisions add, so the result is tighter than either sensor. Rename the readings as prediction and measurement and you have the Kalman update. The rule trusts its inputs, so check them.

QuantityFormulaThermometer numbers
PrecisionP = 1/σ²4 and 0.25
Weight on Aw* = PA/(PA + PB)0.941
Fused estimatexf = (PAxA + PBxB)/(PA + PB)21.88 °C
Fused precisionPf = PA + PB4.25, so sigma-f = 0.485 °C
n equal readingsσf = σ/√n2 °C over 16 readings: 0.5 °C
Kalman gainK = P−/(P− + R)4/(4 + 1) = 0.8
Gatereject if |ν| > g√S, S = P− + R3 sigma with S = 5: 6.7
Correlated pairσtrue² = σ²(1 + ρ)/24 m² at rho 0.5: 3 m²

Checklist before you fuse

  1. Get a starting variance for each sensor: square its 1-sigma spec.
  2. Check it against a known reference, or with an Allan variance plot for a drifting sensor.
  3. List the error sources the sensors share. If they share one, do not treat them as independent.
  4. Gate each reading on its innovation, using S = P-minus + R.
  5. Fuse with the precision-weighted average.
  6. Watch two numbers in operation: the average normalized innovation squared (near 1) and each sensor's mean residual (near 0).
pythondef kalman_update(x_prior, P_prior, z, R, gate=3.0):
    S = P_prior + R                            # expected variance of the innovation
    nu = z - x_prior                          # innovation: the surprise
    if nu * nu > gate * gate * S:              # outside the gate: a fault, not noise
        return x_prior, P_prior                # reject; keep the prediction
    K = P_prior / S                           # gain = the weight on the measurement
    return x_prior + K * nu, (1 - K) * P_prior    # same as the precision-weighted average

kalman_update(60, 4, 40, 1)      # innovation -20 is beyond 6.7: rejected -> (60, 4)
kalman_update(60, 4, 55, 1)      # innovation -5 passes -> (56.0, 0.8)

The first call shows the gate at work: with S = 5, a surprise of 20 is almost 9 sigmas, so the update keeps the prediction. Chapter 6 fused the same numbers without a gate and got 44.

Where it runs

SystemThe two estimatesWhat the rule gives
Any Kalman filterthe prediction and the new measurementthe update, every tick
A GNSS receiverranges to many satellites, each with its own qualityone position, from weighted least squares: this rule in matrix form
Poll of polls, meta-analysismany studies of one effect, each with an error barthe fixed-effect estimate: big studies weigh more
Redundant gaugestwo or three readings of one pressurea sharper reading when the variances are known; median voting is the common fault-tolerant choice

A poll worked by hand: poll A of 2,400 people gives 52% with a margin of about ±2 points, so sigma is about 1. Poll B of 600 gives 47% with ±4, so sigma is about 2. The precisions are 1 and 0.25, the weights 0.8 and 0.2, and the fused value is 51.0% with sigma 0.89.

Keep going

References

The takeaway. Weight each reading by one over its variance. The precisions add, so two flawed sensors beat the better one. The rule is the Kalman update, and it believes whatever variances and readings you give it.
A colleague says: I will average my two sensors, it is simplest. When is that optimal?

Now press Present or Teach and derive it from memory: precision, the error bowl, the fused estimate, why precisions add, and the Kalman gain. Then go back to the hero and say why the plain average loses to sensor A alone.

Credit

Lesson 3 of 22 in Sensor Fusion: Classical to Modern on Engineermaxxing. The derivations follow the standard treatments in the references above. Every toy number on this page carries the word illustrative.

Sensor Fusion: Classical to Modern · Lesson 3: Combining Two Measurements
Previous: Fusion Architectures · Next: The Bayes Filter · Back to Gleams