This might not be trivial nor short so in advance thank you all who read this in attempt to help. I'm building a Kalman filter in matlab and I'm fairly certain the software itself is working correctly because I tested it on some examples I found on the internet. Therefore my suspicion is that I made a mistake (either mathematical or conceptual) in the process of linearization and discretization of my model.
I need this Kalman filter to use it as an estimator of vehicle's mass (which is, obviously, unknown). The mass is modeled as a disturbance variable. This is the model of the system:
$$\dot{\mathbf x} = f\left(\mathbf x, u\right) \tag 1$$ $$ \begin{bmatrix} \dot{\tau}\\ \dot{v} \\ \dot{m} \end{bmatrix}=\begin{bmatrix}\frac{-1}{T}\tau+\frac{K}{T} u \\ \frac{\tau}{mr} \\ 0 \end{bmatrix} \tag 2 $$
where $\large \tau$ is torque, $\large v$ is the velocity (which is measured) and $\large m$ is mass. Other variables ($\large K, T, r$) are constants. $\large u$ is the input to the system.
Since there is a nonlinear term in the second row of the right-side matrix, I decided to linearize this system in order to write it in a typical state-space form. I did this by computing the Jacobian matrix which led me to the state-space form as follows. $$ \dot{\mathbf{x}}=\mathbf{A} \mathbf{x}+\mathbf{B}u \tag 3 $$ $$ \begin{bmatrix} \dot{\tau}\\ \dot{v} \\ \dot{m} \end{bmatrix} = \begin{bmatrix} \frac{-1}{T} & 0 & 0\\ \frac{1}{m_{op}r} & 0 & \frac{-\tau_{op}}{rm_{op}^{2}}\\ 0& 0 & 0 \end{bmatrix} \begin{bmatrix} \ \tau\\ v \\ m \end{bmatrix} + \begin{bmatrix} \frac{K}{T}\\0 \\ 0 \end{bmatrix} u \tag 4 $$
Note that I will be doing linearization separately for each step of the Kalman filter, so the variables with subscript op indicate "operating point". So those are constants, but different constants in each step.
What is left is to transform this linearized state-space model in it's discrete form. I did this using the first order Taylor expansions. $$ A_{d}=I+A \Delta T= \begin{bmatrix} 1-\frac{\Delta T}{T} & 0 &0 \\ \frac{\Delta T}{m_{op} r} & 1 & \frac{-\tau_{op} \Delta T}{m_{op}^{2} r}\\ 0& 0 & 1 \end{bmatrix} \tag 5 $$ $$ B_{d}=B \Delta T= \begin{bmatrix} \frac{K \Delta T}{T}\\0 \\ 0 \end{bmatrix} \tag 6 $$
Where $\large \Delta T$ is the discretization time. The C matrix is the same throughout since we are only measuring the second state (velocity), hence:
$$ C_{d}=C=\begin{bmatrix} 0 & 1 & 0 \end{bmatrix} \tag 7 $$
Finally we have the model in it's discrete form: $$ \mathbf{x}[k]=\begin{bmatrix} 1-\frac{\Delta T}{T} & 0 &0 \\ \frac{\Delta T}{m_{op} r} & 1 & \frac{-\tau_{op} \Delta T}{m_{op}^{2} r}\\ 0& 0 & 1 \end{bmatrix} \mathbf{x}[k-1]+\begin{bmatrix} \frac{K \Delta T}{T}\\0 \\ 0 \end{bmatrix} u[k-1] \tag 8 $$ $$ y[k]=\begin{bmatrix} 0 & 1 & 0 \end{bmatrix} \mathbf{x}[k] \tag 9 $$
So once again I would ask somebody to check if what I did is correct (conceptually and mathematically) because my suspicion is I made a mistake somewhere in these steps. When I plug this discrete state-space model in my code, the estimated vehicle mass slowly fades to 0. I checked the observability matrix, and it's rank is equal to 3 so this should be possible to estimate.