HW2. Sensor Calibration¶
Due date: 2026-01-29 23:59.
Recommended Resources:
- SF: Sensing and Filtering, Steven M. LaValle, PDF
- Recorded Lectures and Slides
1D Sensor Calibration: Thermometer¶
In this part of the assignment, you will explore how sensor calibration can be expressed mathematically using linear algebra, the pseudoinverse, and the Singular Value Decomposition (SVD).
Problem Setup¶
Assume you have a simple thermometer that reports temperature in degrees Celsius. You measure the temperature on three consecutive days using:
- a new thermometer you just bought, and
- an old thermometer that you trust and treat as ground truth.
Let:
- the measurements reported by the new (uncalibrated) thermometer be:
r_1, r_2, r_3.
\\\
- the true temperatures (reported by the trusted thermometer) be:
s_1, s_2, s_3.
\\\
You notice that the new thermometer consistently reports different values, so you assume it has a linear calibration error. You model this error using a scale-and-offset model:
\begin{aligned}
s_1 &= a r_1 + b, \\
s_2 &= a r_2 + b, \\
s_3 &= a r_3 + b.
\\\
\end{aligned}
In the above equations, the following calibration parameters are introduced:
- ๐ represents the scale error.
- ๐ represents the offset error.
Your goal is to find ๐ and ๐, so that you can effectively use the new thermometer by applying these calibration parameters to any future measurement. In practice, the data may not satisfy the calibration model exactly, so ๐ and ๐ are instead estimated using least squares.
Download Visualization Tool¶
Download and run the following visualization tool for understanding linear calibration using least-squares and SVD:
This tool visualizes the calibration process and the solution to the least-squares minimization problem by animating the following:
- Parameter plane. The calibration parameters live in a 2D plane:
\beta =
\begin{bmatrix}
a \\
b
\end{bmatrix} \in \mathbb{R}^2.
\\\
- Data matrix and mapping to the measurement space. The data matrix defines a linear mapping from the 2D parameter plane into the 3D measurement space:
M \beta \in \mathbb{R}^3.
\\\
- Ground truth vector. The ground truth vector also lives in the 3D measurement space:
s =
\begin{bmatrix}
s_1 \\
s_2 \\
s_3
\end{bmatrix} \in \mathbb{R}^3.
\\\
- Estimated calibration parameters: The goal of the calibration process is to compute the best-fit calibration parameters:
\hat{\beta} =
\begin{bmatrix}
a \\
b
\end{bmatrix}.
\\\
- Least-squares solution: The estimated calibration parameters are the solution to the following least-squares problem:
\hat{\beta} = \arg\min_{\beta} || s - M \beta ||.
\\\
- Fitted point. The fitted point represents the best least-squares fit to the ground truth vector in the measurement space:
\hat{s} = M \hat\beta \in \mathbb{R}^3.
\\\
- Residual vector. The residual vector captures the remaining error after the calibration. It is defined as the difference between the ground truth vector and the fitted point. Geometrically, it represents the distance between the transformed parameter plane and the ground truth vector.
s - M \hat\beta.
\\\
- Geometrical interpretation. Geometrically, the fitted point is the orthogonal projection of the ground truth vector onto the transformed parameter plane. The calibration parameters ๐ and ๐ are, therefore, the coordinates of the point on this plane that produces the closest possible match to the ground truth measurements. Understanding the geometry of the calibration model is essential. You should also be able to reason about it analytically.
3D Sensor Calibration: Accelerometer¶
In this part of the assignment, you will extend the ideas from 1D thermometer calibration to the 3D calibration of an accelerometer.
An accelerometer measures acceleration along three orthogonal axes (๐ฅ, ๐ฆ, ๐ง). Due to manufacturing imperfections, the raw measurements typically contain scale errors, axis misalignment, and offset (bias) errors. Calibration is required to correct these errors before the sensor can be used reliably.
This calibration problem is a direct generalization of the 1D case. Instead of estimating two scalar parameters, you will now estimate a matrix of calibration parameters and an offset vector.
Sensor Data¶
Start by downloading raw acceleration measurements recorded by an uncalibrated accelerometer:
Each row corresponds to one accelerometer measurement and contains three values, representing the raw acceleration measured along the ๐ฅ, ๐ฆ, and ๐ง axes:
\begin{aligned}
&\dots \\\
r_{xi},\; &r_{yi},\; r_{zi}\\\
&\dots
\end{aligned}
\\\
Next, download the file containing acceleration measurements obtained from a trusted reference system:
This file contains measurements in the same format:
\begin{aligned}
&\dots \\\
s_{xi},\; &s_{yi},\; s_{zi}\\\
&\dots
\end{aligned}
\\\
Both files contain thousands of measurements, making the calibration problem highly overdetermined.
Calibration Model¶
We assume a linear calibration model that accounts for scale, cross-axis coupling, and offset errors. The calibration parameters consist of:
- a 3ร3 calibration matrix, ๐จ,
- a 3ร1 offset vector, ๐.
A =
\begin{bmatrix}
a_{11} & a_{12} & a_{13} \\
a_{21} & a_{22} & a_{23} \\
a_{31} & a_{32} & a_{33}
\end{bmatrix}
\qquad
b =
\begin{bmatrix}
b_1 \\
b_2 \\
b_3
\end{bmatrix}
\\\
The calibration model is:
s_i = A r_i + b,
\qquad
s_i =
\begin{bmatrix}
s_{xi} \\
s_{yi} \\
s_{zi}
\end{bmatrix},
\qquad
r_i =
\begin{bmatrix}
r_{xi} \\
r_{yi} \\
r_{zi}
\end{bmatrix}.
\\\
You can also re-write it component-wise for each pair of measurements ๐ แตข and ๐แตข:
\begin{aligned}
& \dots\\
s_{xi} &= a_{11} r_{xi} + a_{12} r_{yi} + a_{13} r_{zi} + b_1 \\
s_{yi} &= a_{21} r_{xi} + a_{22} r_{yi} + a_{23} r_{zi} + b_2 \\
s_{zi} &= a_{31} r_{xi} + a_{32} r_{yi} + a_{33} r_{zi} + b_3\\
& \dots\\
\end{aligned}
\\\
Your goal is to estimate the calibration parameters ๐จ and ๐ using least-squares.
Data Matrix Formulation¶
Your task is to refactor all calibration equations into a single linear system of the form:
s = M \beta
\\\
where:
- the vector ๐ contains all ground-truth acceleration values stacked into a single column vector,
- the vector ๐ฝ contains all the unknown calibration parameters,
- the matrix ๐ is a large data matrix constructed from the raw accelerometer measurements.
Because the number of measurements is much larger than the number of unknown parameters, this system is highly overdetermined and must be solved using the pseudoinverse.
Authors¶
Anna LaValle.
Give feedback on this content
Comments about these exercises