# Can the Kalman filter estimate a factor of the model? Product of two state variables

I've written down a discrete state-space model for a simple pendulum, with the state variables angle, angular velocity and angular acceleration.

This can be easily plugged into a simple Kalman filter to estimate the state. However, if the length l of the string was constant but unknown, is there any way of using a Kalman filter to estimate l alongside of the rest of the state?

I can't figure out how to linearise the term angle / l. Would an EKF help here?

g = 9.81;
l = 3;
dt = 30e-3; % 30 ms

A = [   1  dt   0;   % angle_{k+1}   = angle_k   + dt * ang_vel_k
0   1  dt;   % ang_vel_{k+1} = ang_vel_k + dt * ang_acc_k
-g/l  0   0 ]; % ang_acc_{k+1} = -g/l * angle_k

B = [ 5/360*2*pi*dt; 0; 0];
C = [ 1 0 0 ];
D = 0;
sys = ss(A,B,C,D,dt);

• Please excuse the poor title, I seem to lack the right vocabulary.
– Anna
Aug 26, 2021 at 14:08
• Did you solve this problem? I have to design ekf for same systems. Sep 9, 2021 at 13:33
– Peter K.
Sep 9, 2021 at 13:53

Yes, an extended Kalman (or unscented Kalman, or other extension of the Kalman filter to deal with nonlinear systems) would help here.

Fixing your differential equation for the pendulum motion would help, too -- basically, the angular acceleration isn't a state; treating it as such will just confuse things.

For the EKF or other nonlinear Kalman, let your state vector be $$\mathbf x = \begin{bmatrix}\theta, \omega, d\end{bmatrix}^T$$, where $$\theta$$ is the angle, $$\omega = \dot \theta$$ is the angular rate, and $$d$$ is length ('l' looks too much like '1'). Note that there's no angular acceleration here, but there is that length. Ignoring noise, your equations of motion are (including the length):

$$\dot {\mathbf x} = f\left( \mathbf x \right) = \begin {bmatrix} \omega \\ -\frac{g}{l} \theta \\ 0 \end{bmatrix}$$

(Note that the above uses $$\dot \omega = -\frac{g}{d} \theta$$; i.e. it uses the small-angle approximation for the $$\sin$$ function. You've already crossed the nonlinear-systems Rubicon, so if you wanted to, you could use $$\dot \omega = -\frac{g}{l} \sin \theta$$, since you're going nonlinear anyway -- doing so depends on whether or not you anticipate the angular excursion to be great enough that the small-angle approximation for $$\sin \theta$$ holds.

For the EKF, you "simply" need to calculate the vector derivative of $$\mathbf x$$ to use for your continuous-time $$\mathbf A$$: $$\mathbf A = \frac{\partial}{\partial \mathbf x} f\left( \mathbf x \right)$$. Then discretize that, and use it in your EKF.

• Really great tip. +1. By the way, it would be nice to define all elements of the state vector for those $\theta$ won't be clear to.
– Royi
Aug 26, 2021 at 17:44
• Thanks a lot @TimWescott! I'll give that a go and see how it goes. What do you mean when saying that angular acceleration isn't a state? Am I understanding correctly that it contains only redundant information, that could be found from the angle and angular velocity anyway?
– Anna
Aug 26, 2021 at 17:58
• Pretty much. A state depends on its prior value (or, in the case of discrete-time systems, sometimes prior values of other states). If you can calculate a property of the system (like the acceleration of the pendulum) entirely from current states and current inputs, then that property isn't a state, per se. Aug 26, 2021 at 18:07
• @Royi -- thanks. Edits made. Aug 26, 2021 at 18:31