# Unit 3: Kalman Filter - Mistaking Standard Deviation for Variance

**URL:** <https://get-help.theconstruct.ai/t/unit-3-kalman-filter-mistaking-standard-deviation-for-variance/39213>\
**Category:** Kalman Filters\
**Tags:** error\
**Created:** [December 7, 2025, 5:46am UTC](https://get-help.theconstruct.ai/t/unit-3-kalman-filter-mistaking-standard-deviation-for-variance/39213 "2025-12-07T05:46:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TylerChung](https://get-help.theconstruct.ai/letter_avatar_proxy/v4/letter/t/f07891/32.png) [@TylerChung](https://get-help.theconstruct.ai/u/TylerChung)\
**Post date:** [December 7, 2025, 5:46am UTC](https://get-help.theconstruct.ai/t/unit-3-kalman-filter-mistaking-standard-deviation-for-variance/39213/1 "2025-12-07T05:46:27Z")

</div>

As for Unit 3, there seems to be a mix-up in using standard deviation for variance. The snippet below shows the solution “_kalman\_filter\_solution.py_” taking inputs of variance and outputting the new variance.

**Line 27 - 42:**

> ### Add correct\_step function HERE
> 
> def correct\_step(mean1, var1, mean2, var2):  
> ‘’’ This function takes in two means and two squared variance terms,  
> and returns updated gaussian parameters’‘’  
> # Calculate the new gaussian parameters  
> new\_mean = (var1 \* mean2 + var2 \* mean1) / (var1 + var2)  
> new\_var = 1 / (1 / var1 + 1 / var2)  
> return new\_mean, new\_var
> 
> ### Add predict\_step function HERE
> 
> def state\_prediction(mean1, var1, mean2, var2):  
> global new\_mean, new\_var  
> new\_mean = mean1 + mean2  
> new\_var = var1 + var2  
> return new\_mean, new\_var

But as shown in the function call, the standard deviation (sigmoid) is referenced and used as input. This is also labelled in initializing the variance for motion and measurement.

**Line 21 - 23:**

> # initialize motion sigma (the standard deviation of the motions normal distribution)
> 
> motion\_sig = 4.0  
> measurement\_sig = 0.05

**Line 59 - 63**

> ### ADD KALMAN FILTER CYCLE HERE
> 
> mu, sig = state\_prediction(mu, sig, motion, motion\_sig)  
> rospy.loginfo(“predict step: [%s, %s]”, mu, sig)  
> mu, sig = correct\_step(mu, sig, last\_measurement, measurement\_sig)  
> rospy.loginfo(“correct\_step: [%s, %s]”, mu, sig)

The notebook also includes equations for calculating the mean and variance based on the previous variance.

**Just before the start of section 3.5.1**

> Writing those math formulas as Python code is straightforward:  
> new\_mean = (var1 \* mean2 + var2 \* mean1) / (var1 + var2)  
> new\_var = 1 / (1 / var1 + 1 / var2)

**Just before the start of section 3.6.1**

> Written in Python:  
> new\_mean = mean1 + mean2;  
> new\_var = var1 + var2;

The outputs from the rostopic “_/filtered\_pos/data_” yield visually similar results, perhaps due to the robustness of the filter. A plausible solution is as shown:

> ### Add correct\_step function HERE
> 
> def correct\_step(mean1, sig1, mean2, sig2):  
> var1 = sig1 \*\* 2  
> var2 = sig2 \*\* 2  
> new\_mean = (var1 \* mean2 + var2 \* mean1) / (var1 + var2)  
> new\_var = (1 / (1 / var1 + 1 / var2))  
> new\_sig = new\_var \*\* 0.5  
> return new\_mean, new\_sig
> 
> ### Add predict\_step function HERE
> 
> def predict\_step(mean1, sig1, mean2, sig2):  
> var1 = sig1 \*\* 2  
> var2 = sig2 \*\* 2  
> new\_mean = mean1 + mean2  
> new\_var = var1 + var2  
> new\_sig = new\_var \*\* 0.5  
> return new\_mean, new\_sig

Just want to raise this potential issue (if any) to prevent any misunderstandings for future learners.

---

<div class="post-metadata">

**Author:** ![albertoezquerro](https://get-help.theconstruct.ai/user_avatar/get-help.theconstruct.ai/albertoezquerro/32/7031_2.png) [@albertoezquerro](https://get-help.theconstruct.ai/u/albertoezquerro)\
**Post date:** [December 15, 2025, 4:26pm UTC](https://get-help.theconstruct.ai/t/unit-3-kalman-filter-mistaking-standard-deviation-for-variance/39213/2 "2025-12-15T16:26:53Z")

</div>

Hello @TylerChung ,

Many thanks for your feedback on the course. I’ll need to cross-check your comments with the course contents and update the course notebooks where required to avoid confusion.

Thanks again for your collaboration,
