An Intuitive Introduction to Kalman Filtering · Module 2 of 11

Smoothing
without a model

Our first real filter: blend each new reading into what we already believe, using a gain we choose by hand. It is one line of code, and it already contains the trade-off the rest of the course is about.

Arrow keys or the buttons below to move. Press N for instructor notes.

How this module is laid out

Six parts, one idea

    The one new idea is small: blend each new reading into the old estimate with a gain. We take our time with it, because every later module is this same line with a smarter gain.

    In every part you will work a few steps by hand with the real sled readings, watch the same example continue on a plot, compare several settings side by side, and then try it in MATLAB.

    Step-by-step tables reveal one row per press of the right arrow. Click a part to jump to it.

    Module 2 · Part A of F

    Averaging over a window

    Module 1 ended with an average that fell far behind the moving sled. Before we replace it, let us see exactly how a window of readings behaves, one row at a time.

    • Slide a 5-reading window along the real readings, at rest and in motion.
    • Compare short and long windows side by side.
    • Find the best window, and see why it is a poor compromise.
    Where Module 1 left us

    Averaging failed once the sled moved

    At rest, averaging 25 readings cut the error from 2 m to about 0.4 m.

    Once the sled moved, the same average of the latest 25 readings lagged up to 54 m behind, because it treated old readings of old positions as if they described the present.

    Today’s question: can we smooth the noise without falling that far behind?
    Module 1 result: averaging the latest 25 readings lags far behind the moving sled
    From Module 1. Green is the average of the latest 25 readings.
    Part A · By hand, at rest

    A window of 5 readings, parked sled

    Each time a new reading arrives, average it with the four before it. The sled is parked at 0 m, so the truth is 0 in every row.

    timelatest 5 readings [m]averagetrutherror

    Press the right arrow to reveal one row at a time.

    Single readings miss by a meter or two. The averages stay much closer to 0, because highs and lows inside the window cancel.

    Part A · By hand, in motion

    The same window once the sled is moving

    Predict first: the sled is now accelerating away. Will the average be ahead of the truth, or behind it? Will the error stay the same from row to row?

    timelatest 5 readings [m]averagetrutherror

    Press the right arrow to reveal one row at a time.

    Behind, and falling further behind on every row. The five readings in the window are of five different positions, all of them older than now.

    Part A · Side by side

    Three window lengths on the same readings

    Short windows keep up and barely smooth. Long windows smooth beautifully while parked and fall far behind once the sled moves.

    Look at each panel twice: first at the parked part (0 to 5 s), where the longest window is best, then at the push, where it is by far the worst.

    The obvious fix

    Use a shorter window?

    Average only the latest M readings and try every M.

    • Long windows smooth a lot but fall behind.
    • Short windows keep up but barely smooth.

    The best window over the whole run is M = 2, with an RMS error of 1.87 m against the raw sensor’s 2.0 m.

    Every reading in the window counts equally, and every reading outside it counts for nothing. That all-or-nothing memory is crude. We can do better.

    RMS error versus moving-average window length: best at a window of two readings
    Average of 100 noise draws for each window length.
    Part A · Recap and explore

    What we just saw, and what to try

    What we just saw

    • A window average is the truth as it was half a window ago, plus reduced noise.
    • Longer windows cut more noise and lag more. On this fast sled the lag wins: the best window is only 2 readings.
    • Every reading in the window counts equally and every older one counts for nothing. That all-or-nothing memory is what we improve next.

    Explore in MATLAB

    1. Experiment 1. Run the script and read Step table 1 in the Command Window. Its rows should match the two tables you just stepped through.
    2. Experiment 2. Open The trade-off › Moving average. Then change windows = (1:12)' to (1:30)' and run again. Does the error ever come back down?
    Part A · Check your understanding

    Before moving on

    1. Four readings of a parked sled are 1.0, −2.0, 3.0 and 0.0 m. What is the 4-reading window average, and what is it after a fifth reading of 2.0 m arrives (the window still holds 4)?

    0.5 m, then 0.75 m. First (1 − 2 + 3 + 0)/4 = 0.5. Then the window drops the 1.0 and takes in the 2.0: (−2 + 3 + 0 + 2)/4 = 0.75.

    2. A sled moves at a steady 10 m/s and is read 5 times a second. Roughly how far behind is a 5-reading window average?

    About 4 m. The average describes the middle of the window, 2 readings or 0.4 s ago, and in 0.4 s the sled covers 4 m.

    3. Why does a long window work so well in Module 1’s rest period and so badly afterwards?

    At rest every reading in the window is of the same position, so averaging only removes noise. In motion they are readings of different, older positions, so the average is an estimate of the past.

    Module 2 · Part B of F

    The running average and the 1/k gain

    There is another way to average: keep everything, and update the average each time a reading arrives. Written that way it becomes our first estimator with a gain, and the gain turns out to be 1/k.

    • Work the first six readings by hand.
    • See the gain shrink, and the estimate settle, while the sled is parked.
    • Compare it with fixed gains, then watch it fail when the sled moves.
    A different way to write an average

    The running average is an update

    In Module 1 we averaged the first k rest readings. The same number can be computed one reading at a time:

    x^k=x^k−1+1k(zk−x^k−1)

    Read it as a sentence

    New estimate = old estimate + gain × (new reading − old estimate). That is the course’s update with the gain K = 1/k.

    Why 1/k?

    The 10th reading is one voice among ten, so it may move the average by a tenth of its disagreement. As evidence piles up, each new reading is trusted less.

    Check: average of 9 readings is 4.0 m, the 10th reads 6.0 m. New average = 4.0 + (1/10)(6.0 − 4.0) = 4.2 m, the same as adding all ten and dividing by 10.

    Part B · By hand

    The first six readings, one at a time

    The parked sled’s first six readings. Each row is the update: new average = old average + 1⁄k × (reading − old average).

    kreadinggainold + gain × (reading − old)new average

    Press the right arrow to reveal one row at a time.

    The second reading moves the estimate by half its disagreement. The sixth moves it by only a sixth.

    Part B · Checking the claim

    It really is the plain average

    Add up the six readings and divide by six:

    () / 6 = m

    That is the last row of the table. The update did not approximate the average; it is the average.

    The update needs only two stored numbers, the old average and the count k. It never looks at the old readings again.

    Why it must be so

    The average of k readings is the old total plus the new reading, over k:

    x^k=(k−1)x^k−1+zkk

    Split the fraction: the first piece is the old average minus one k-th of it, the second is one k-th of the reading.

    x^k=x^k−1+1k(zk−x^k−1)
    Part B · The gain

    A gain that shrinks as evidence piles up

    Plot the gain 1/k against the reading number.

    • Reading 1: gain 1. We know nothing, so we take it whole.
    • Reading 2: gain 0.5. One old voice, one new voice.
    • Reading 10: gain 0.1. One voice among ten.
    • Reading 25, the end of the rest period: gain 0.04.
    Read the gain as trust: “how much of this reading’s disagreement do I accept?” The more we already know, the less one more reading should move us.
    Part B · Watch it settle

    All 25 parked readings

    Drag the slider to feed in the rest readings one by one.

    • The running average swings widely at first, then barely moves.
    • The shaded band is where we expect it to be: ±σ/√k, from Module 1.
    • The readings keep scattering by ±2 m. The estimate does not.

    By k = 25 the expected error is 2/√25 = 0.4 m, five times better than one reading.

    Part B · Side by side

    While parked: a shrinking gain against fixed gains

    The same 25 rest readings through four filters. The only difference is the gain: 1/k, or a constant.

    A fixed gain keeps trusting each new reading exactly as much as the last one, so it never settles: the larger the gain, the more of the jitter comes through. The 1/k gain has the smallest error of the four.

    Part B · Predict

    So why not use 1/k all the time?

    Predict before you go on. At 5 s the sled pushes off and travels 575 m over the next 55 s. We leave the running average running, gain still 1/k.

    • What is the gain when the sled starts to move? What is it at the end of the run?
    • Sketch the estimate against the truth. Where does it finish: near 575 m, about halfway, or near 0?

    Write down a number for the final estimate, then go to the next slide.

    Part B · The failure

    The running average goes deaf

    The same update, left running for the whole trip.

    The estimate is the average of everywhere the sled has been, so it ends hundreds of meters short. Each new reading says “you are far behind”, and the filter accepts a 300th of that message.

    Part B · A variation

    What if we restart the count?

    One idea: every N readings, forget everything and start the average again at k = 1.

    • Large N: smooth, far behind, with a jump at each restart.
    • Small N: keeps up, but it is hardly averaging at all.

    Drag the slider and look for the best N.

    Forgetting helps, but forgetting everything at once is crude. We want a filter that forgets gradually.
    Part B · Recap and explore

    What we just saw, and what to try

    What we just saw

    • The running average is the update “old + gain × (reading − old)” with gain 1/k, and it equals the plain average exactly.
    • A shrinking gain means growing confidence. While the sled is parked it beats every fixed gain.
    • It never forgets, so once the sled moves it stops listening and ends hundreds of meters behind.

    Explore in MATLAB

    1. Experiment 3. Compare Step table 2 in the Command Window with your hand table, then open Step by step › Running average and press Next step twelve times.
    2. Experiment 4. In the Command Window run ra = cumsum(z_pos) ./ (1:N)'; then plot(t_pos, p_true_s, t_pos, ra). How far behind is it at 60 s? What is the gain 1/N?
    Part B · Check your understanding

    Before moving on

    1. Your running average of 4 readings is 2.0 m. The 5th reading is 7.0 m. What is the new average?

    3.0 m. The gain is 1/5, the disagreement is 7.0 − 2.0 = 5.0, so the estimate moves by 1.0.

    2. After 100 readings, a new reading disagrees with the running average by 10 m. How far does the estimate move? Is that sensible?

    0.1 m (gain 1/101, practically 1/100). It is sensible if all 100 earlier readings were of the same position, and badly wrong if the position has changed.

    3. In one sentence: why does the running average beat a fixed gain at rest but lose to it in motion?

    Its gain keeps shrinking, which keeps cutting the noise while nothing changes, but also means it responds less and less when something does change.

    Module 2 · Part C of F

    A fixed gain

    The running average forgets nothing. The moving window forgets all at once. Freezing the gain gives a filter that forgets a little at every step.

    • Meet the low-pass filter: the same update with a constant gain.
    • Work six steps by hand and see four gains side by side.
    • Find out exactly how much each old reading still counts.
    The new idea

    Fix the gain

    The 1/k gain shrinks toward zero, so a running average eventually stops listening. A moving sled needs a filter that keeps listening.

    So freeze the gain at a constant α:

    x^k=x^k−1+α(zk−x^k−1)

    This is the first-order low-pass filter (also called exponential smoothing). Each step moves the estimate a fixed fraction α of the way toward the new reading.

    Drag the slider: the gain is literally how far we are willing to be pulled.

    Reading the filter

    A weighted vote between memory and evidence

    Rearranging the same line gives a weighted average of the old estimate and the new reading:

    x^k=(1−α)x^k−1+αzk

    α = 0

    Ignore the sensor completely. The estimate never moves.

    α = 1

    Ignore memory completely. The estimate is just the latest reading: the raw sensor.

    In between

    Trust both, in proportion. Choosing α is answering the course’s question by hand.

    “How much should I trust this new measurement, compared with what I already believe?” This module answers with one fixed number. The Kalman filter will answer with a number that changes at every step.
    Part C · By hand

    Six steps with α = 0.3

    The same first readings as in Part B, but now every reading gets the same gain: move 30% of the way from the old estimate to the reading.

    kold estimatereadingreading − oldold + 0.3 × (difference)new estimate

    Press the right arrow to reveal one row at a time.

    Compare with the running average table: there the sixth reading moved the estimate by a sixth of its disagreement, here by 30%, and it will still be 30% at reading 300.

    Watch it work

    One reading at a time

    Animation: four low-pass filters with gains 0.10, 0.30, 0.50 and 0.78 run on the same readings. Small gains stay smooth but fall behind once the sled moves; large gains keep up but follow the noise.

    Same readings, four gains. At every step each estimate moves a fixed fraction α of the way from its old value (square) toward the new reading (red). By 11 s, α = 0.10 trails the sled by 16 m and α = 0.78 by only 1 m, but α = 0.78 also jumps with every reading.

    What the filter remembers

    A fading memory

    Unroll the update and today’s estimate is a weighted sum of every past reading. A reading j steps old carries weight

    α(1−α)j
    • The weights add up to 1, so it is still an average.
    • They fade smoothly instead of the moving average’s cliff edge.
    • Rule of thumb: the filter remembers roughly the last 1/α readings.

    Only one number is stored, the previous estimate, yet the whole history is in it.

    Bar chart of the weight each past reading carries, for two gains
    Part C · By hand

    Rebuilding one estimate from its memory

    Take the estimate after reading 7 with α = 0.3. It should equal a weighted sum of all seven readings, newest first.

    readingage jweight=value [m]weight × value

    Press the right arrow to reveal one row at a time.

    The newest reading counts 30%. Each step back in time multiplies the weight by 0.7.

    The last row is the surprise: the weighted sum is the same number as the step table’s estimate at k = 7, m.

    One stored number, the previous estimate, quietly carries a fading record of every reading so far.
    Part C · Recap and explore

    What we just saw, and what to try

    What we just saw

    • Freezing the gain at α gives the low-pass filter: each step moves a fixed fraction of the way to the new reading.
    • It is a weighted average of all past readings, with weights that fade by a factor (1 − α) per step.
    • Small α: long memory, smooth, slow. Large α: short memory, jumpy, quick.

    Explore in MATLAB

    1. Experiment 5. Compare Step table 3 with your hand table. Then open Step by step › Low-pass and step through twelve readings.
    2. Experiment 6. Set alpha_hand = 0.05 and run again. In Errors › Hand-picked gain, how far behind is the estimate at 13 s? Try 0.9 as well.
    Part C · Check your understanding

    Before moving on

    1. Your estimate is 50.0 m and α = 0.25. Three readings arrive: 54.0, 54.0, 54.0. What is the estimate after each?

    51.0, 51.75, 52.31 m. Each step closes a quarter of the remaining gap: 4.0, then 3.0, then 2.25.

    2. With α = 0.5, what weight does a reading 3 steps old carry in today’s estimate?

    0.0625, about 6%. The weight is α(1 − α)3 = 0.5 × 0.125.

    3. Which filter from Parts A to C stores the least, and which forgets the most smoothly?

    The running average and the low-pass filter each store a single estimate (the running average also keeps the count). A window of M must store M readings. Only the low-pass filter forgets gradually.

    Module 2 · Part D of F

    The trade-off: noise against lag

    A fixed gain has to be chosen. Small gains have one problem, large gains have another, and both can be measured, worked by hand and predicted.

    • See the two failures on the sled.
    • Isolate each one: pure noise with no motion, then pure motion with no noise.
    • Turn each into a formula and check it.
    On the sled

    Two gains, two failures

    Low-pass estimate on the first 14 seconds for a small gain and for the best gain

    α = 0.30: smooth while parked, but once the sled moves it trails the truth by many meters. This is lag.

    α = 0.78: keeps up with the motion, but much of the sensor’s jitter comes straight through. This is noise.

    The trade-off

    Feel it before we write it down

    A toy version of the run: the sled sits still for 5 s, then is pushed.

    • Slide α low: the parked part is beautifully smooth, and the moving part falls behind.
    • Slide α high: it keeps up, and the parked part is as jumpy as the sensor.

    No single α is good at both. Keep that in mind; we come back to it at the end.

    Part D · Noise on its own

    Take the sled away: filter pure noise

    Park the sled at 0 m for 200 readings, so the only thing going in is sensor noise with σ = 2 m. How much comes out?

    Faint red is the noise going in, green is what the filter lets through. The spread of the green trace is measured and compared with a formula we derive on the next slide.

    The trade-off in math, part 1

    How much noise gets through

    If the sled stands still, the error is just filtered noise. Using the memory weights and the Module 1 fact that independent variances add:

    σfiltered2=σ2∑jα2(1−α)2j=σ2α2−α
    σfiltered=σα2−α
    • α = 1 gives σ: no smoothing.
    • α = 0.3 gives 0.42σ: the 2 m sensor becomes 0.84 m.
    • α = 0.78 gives 0.80σ: only a modest cut.
    Smaller α means less noise. If noise were the only problem, we would turn α down as far as it goes.
    Part D · Lag on its own

    Now take the noise away: a sled at steady speed

    A sled at 16 m/s, read every 0.2 s, moves 3.2 m between readings. No noise. Both filters start exactly on the truth.

    steptruth [m]α = 0.5gapα = 0.3gap

    Press the right arrow to reveal one row at a time.

    Each step the truth pulls 3.2 m ahead and the filter closes only a fraction of the gap. The gap grows until what is closed each step equals what is added.

    The trade-off in math, part 2

    How far it lags

    Now remove the noise and let the sled move at constant speed v. Each step the truth moves vΔt, but the estimate only closes a fraction α of the gap. The gap settles where the two balance:

    lag=vΔt1−αα

    Δt = 0.2 s is the time between readings.

    • Lag grows with speed. A parked sled has none.
    • Lag explodes as α gets small: halve α and the lag roughly doubles.
    • At 16 m/s: α = 0.3 trails by 7.5 m; α = 0.78 by 0.90 m.
    Larger α means less lag. Lag pulls α up; noise pulls it down.
    Worked example

    Putting numbers on the trade-off

    Gain αNoise left (σ = 2 m)Lag at 16 m/sMemory ≈ 1/α
    0.100.46 m28.8 m10 readings (2 s)
    0.300.84 m7.5 m3 readings (0.7 s)
    0.501.15 m3.2 m2 readings (0.4 s)
    0.781.60 m0.90 mabout 1 reading
    1.002.00 m0 mnone: raw sensor

    Read across a row: every gain buys less noise with more lag.

    On a sled that spends most of its run at 10 to 20 m/s, lag in the tens of meters is far worse than 2 m of noise. That is why the best gain sits near 1.

    The table uses the two formulas. The MATLAB script checks both against simulation in its “Theory check” tab.

    Do the formulas hold?

    Theory against simulation

    Measured filtered noise and lag compared with the two formulas, across gains

    Dots are measured in the simulation, lines are the formulas. They agree, so we can reason about the filter with pencil and paper before running it.

    Part D · Recap and explore

    What we just saw, and what to try

    What we just saw

    • Noise that gets through: σ√(α/(2 − α)). Smaller gain, less noise.
    • Lag at steady speed: vΔt(1 − α)/α. Smaller gain, more lag, and lag grows with speed.
    • The two pull the gain in opposite directions. That tension is the subject of the rest of the course.

    Explore in MATLAB

    1. Experiment 7. After TODO 3, type noiseFactor(0.3) * sigma_pos and lagConstV(16, 0.3). Compare with the table of worked numbers, then open Inside the filter › Theory check.
    2. Experiment 8. What gain makes the lag at 22 m/s (the top speed) equal to 2 m? Solve it by hand, then check with lagConstV(22, your_alpha).
    Part D · Check your understanding

    Before moving on

    1. A sensor has σ = 3 m and you filter it with α = 0.5. What is the one-sigma noise of the output?

    1.73 m. √(0.5/1.5) = 0.577, times 3 m.

    2. A vehicle moves at 5 m/s, read 10 times a second, filtered with α = 0.2. How far behind is the estimate once settled?

    2 m. vΔt = 0.5 m per step, times (1 − 0.2)/0.2 = 4.

    3. You halve α. Roughly what happens to the noise and to the lag?

    For small gains the noise falls by about √2 (to about 71%), while the lag roughly doubles. Lag is the more sensitive of the two, which is why small gains are so costly on a fast vehicle.

    Module 2 · Part E of F

    Choosing the gain

    If one gain must serve for the whole run, which one? We find it by trying them, and then discover that the question itself is the problem.

    • Build the error-against-gain curve one gain at a time.
    • Find the best single gain, and see what “low-pass” means.
    • Split the run in two and find that each half wants a different gain.
    Part E · Built up point by point

    Try a gain, measure the error, repeat

    For each gain, run the filter over the whole 60 s and measure three things: the error from lag alone (filter the truth), from noise alone (filter the noise), and the total.

    gain αlag part [m]noise part [m]total RMS [m]

    Press the right arrow to reveal one row at a time.

    Lag falls and noise rises as the gain goes up. After the last row the full curves appear: the total has a valley, and its floor is the best gain.

    Choosing the gain

    The best single gain for this run

    Run the filter at every gain from 0.02 to 1, on 100 noise draws each, and measure the RMS error over the whole run.

    • Lag falls as α rises.
    • Noise rises as α rises.
    • The total bottoms out at α = 0.78, with 1.74 m.

    At the best gain the error is mostly noise (1.61 m) with some lag (0.70 m). The two parts add like independent errors: the total squared is close to the sum of their squares.

    RMS error versus gain, split into lag and noise parts, with the minimum marked
    Watch the trade-off

    Sweeping the gain

    Animation: as the gain sweeps from small to large, the estimate goes from lagging to noisy while the error curve traces a valley

    Left: the estimate on the first 14 s. Right: where that gain sits on the error curve. The animation ends at the best gain.

    Why the name

    What “low-pass” means

    Think of a signal as a mix of slow changes and fast wiggles.

    • The sled’s motion is slow: it changes over seconds.
    • White noise is spread evenly over every frequency, including the fastest the 5 Hz sensor can show.

    The filter lets slow changes (low frequencies) pass and shrinks fast ones. Smaller α cuts more, starting at lower frequencies.

    The catch: it also delays what it passes. That delay is the lag we measured.

    Frequency response of the low-pass filter for several gains
    The deeper lesson

    The right gain depends on the situation

    Split the run in two and find the best gain for each part:

    • While parked: best α = 0.20, error 0.93 m.
    • While moving: best α = 0.79, error 1.75 m.

    And while parked, the running average from Part B, whose gain shrinks as 1/k, does better than any fixed gain: 0.77 m.

    A good gain should depend on what the vehicle is doing and how confident we already are. That is exactly what the Kalman filter will compute.
    RMS error versus gain computed separately for the parked and moving parts of the run
    Part E · Recap and explore

    What we just saw, and what to try

    What we just saw

    • Sweeping the gain traces a valley. For this run the floor is at α = 0.78, giving 1.74 m.
    • That is only 13% better than the raw sensor, because one gain has to cover both the parked and the moving parts.
    • Parked, the best gain is small and the shrinking 1/k gain is better still. Moving, the best gain is large. A good gain must adapt.

    Explore in MATLAB

    1. Experiment 9. In the Playground, drag α to minimize the this-run RMS. Is your best value the same as the 100-run best? Why might it differ?
    2. Experiment 10. Open The trade-off › Rest vs moving. Read off the best gain for each half and the running-average line.
    Part E · Check your understanding

    Before moving on

    1. At some gain the lag part is 3.0 m and the noise part is 4.0 m. Roughly what is the total RMS error?

    About 5.0 m. Independent errors add in squares: √(3² + 4²).

    2. The same sensor is put on a vehicle that moves ten times slower. Does the best gain go up or down?

    Down. Lag is ten times smaller at every gain while the noise is unchanged, so the valley floor moves toward smaller gains.

    3. Why can no single fixed gain match the running average on the parked sled?

    A fixed gain lets a fixed share of the noise through for ever. The running average’s gain keeps shrinking, so its error keeps falling as σ/√k.

    Module 2 · Part F of F

    Build it, score it, and what still goes wrong

    Time to write the filter yourself, put it on the scoreboard, and face the assumption that causes all of its lag.

    • Three TODOs in MATLAB.
    • The second bar on the scoreboard.
    • The one bad assumption that Module 3 removes.
    Your turn

    In MATLAB: build the filter

    Open m02_student.m and press Run. It works as it is, with α stuck at 1. Then fill in three blocks:

    1. TODO 1. The low-pass update, as a one-line function of the old estimate, the new reading and α.
    2. TODO 2. The running average from Module 1, computed as an update with gain 1/k.
    3. TODO 3. The noise and lag formulas, as two small functions of α.

    The Command Window also prints the step tables from Parts A, B and C, so you can check your hand calculations, and the Step by step tab replays the first readings one at a time.

    %% TODO 1 (student): the low-pass update
    % Goal:  lowPassStep(x_prev, z, alpha) returns
    %        the old estimate x_prev moved a
    %        fraction alpha of the way toward z.
    % >>> YOUR CODE STARTS HERE
    lowPassStep = @(x_prev, z, alpha) z;
    % <<< YOUR CODE ENDS HERE
    KinematicsTruth, sensor and estimate
    ErrorsError over the run; error at a hand-picked gain
    The trade-offError vs gain; rest vs moving; moving average
    Inside the filterMemory, the 1/k gain, theory check, “low-pass”
    Step by stepThe first readings, one press at a time
    Playground, ScoreboardDrag the gain; the course-long chart
    Results

    What you should see

    With the best gain, α = 0.78, on the same readings as Module 1:

    • Raw sensor RMS error: 1.91 m.
    • Low-pass RMS error: 1.72 m.

    Compare the error with the velocity below it: the green error leans negative whenever the sled is fast. That lean is lag, even at the best gain.

    Error over the run for the raw sensor and the best low-pass filter, above the true velocity
    The scoreboard

    2.0 m → 1.74 m

    Scoreboard with the raw sensor and the low-pass filter

    The best low-pass filter beats the raw sensor by about 13%.

    That is real, but small. Even at its best gain, this filter spends most of its effort fighting its own lag.

    A filter that knows nothing about motion has to choose between being smooth and being on time. It cannot be both.
    Check your understanding

    Three questions

    1. Your estimate is 100 m, the new reading is 110 m, and α = 0.2. What is the new estimate?

    102 m. The estimate moves 20% of the way toward the reading: 100 + 0.2 × (110 − 100).

    2. The sled’s speed doubles. What happens to the lag of a low-pass filter with a fixed gain?

    It doubles. The steady lag is vΔt(1 − α)/α, which is proportional to speed. The filtered noise does not change, so the best gain moves toward 1.

    3. Why does the running average beat every fixed gain while the sled is parked?

    Its gain shrinks as 1/k, so it trusts each new reading less as evidence accumulates and keeps cutting the noise. A fixed gain keeps trusting new readings just as much forever, so it never gets below its fixed noise level. Shrinking the gain is only safe because the sled is not moving.

    What still goes wrong

    The filter assumes the sled stays where it was

    Look at the update again. The “prediction” is just the previous estimate:

    x^k=x^k−1⏟“it hasn’t moved”+α(zk−x^k−1)

    For a sled moving at 16 m/s, that prediction is wrong by 3.2 m before the new reading even arrives. All the lag comes from this one bad assumption.

    Next, Module 3: predict where the sled will be using its velocity, then correct with the reading. We will estimate a velocity we never measure, and the lag will almost disappear.

    Lag and noise are not a law of nature. They are what happens when the filter has no model of how the sled moves.