Given measurement of voltage and current, which contain gaussian noise with known variance and a constant unknown offset $a_0$, I have attempted to estimate the resistance $R=\frac{V}{I}$. The assumption is that current and voltage are both sinusoidal with the same frequency and phase shift. I discretized the following state model assuming a constant frequency: \begin{equation} \dot{x}(t)=\begin{bmatrix} 0 & 1 & 0 \\ -\omega^2 & 0 & 0 \\ 0 & 0 & 0 \end{bmatrix}x(t) \end{equation}
My first approach is the filtering of voltage and current through two seperate kalman filters given the following state and measurement model: \begin{equation} x_{k} =\begin{bmatrix} \cos\omega T_s & \frac{\sin\omega T_s}{\omega} & 0 \\ -\omega\sin\omega T_s & \cos\omega T_s &0 \\ 0 & 0 &1 \end{bmatrix}x_{k-1} \end{equation}
where $$x=\begin{bmatrix} A\sin(\omega t+\varphi) \\ A \omega\cos(\omega t+\varphi) \\ a_0 \end{bmatrix}$$ and $$y_{k}=\begin{bmatrix} 1 & 0 & 1 \end{bmatrix}x_k.$$ So based on this formulation, I would have two identical Kalman filters, from which I can estimate the resistance through division of the output of both filters without any problem.
My goal now is to estimate everything within one kalman filter including the resistance $R$. Since I am assuming that both signals are sinusoidal with same frequency and phase shift, the resistance would actually be the ratio of both amplitudes, and It would be constant in the period where the amplitude doesn't change. The thing is, the amplitude changes after a certain time interval, so the resistance would be piecewise constant.
I have used the following state space model and measurement model for the estimation:
\begin{equation} x_{k} =\begin{bmatrix} \cos\omega T_s & \frac{\sin\omega T_s}{\omega} & 0 & 0 \\ -\omega\sin\omega T_s & \cos\omega T_s &0& 0 \\ 0 & 0 &1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}x_{k-1} \end{equation} where $$x=\begin{bmatrix} A_I\sin(\omega t+\varphi) \\ A_I \omega \cos(\omega t+\varphi) \\ a_0 \\ R\end{bmatrix}$$ $$y_{k}=\begin{bmatrix} 1 & 0 & 1 & 0\\ 0 & 0 & R_{pred,k} & I_{pred,k} \end{bmatrix}x_k$$ and $$y=\begin{bmatrix} I_{meas,k} \\ V_{meas,k} \end{bmatrix},$$ where $R_{pred,k}$ and $I_{pred,k}$ are the respective resistance and current after the prediction step of the filter at time point $k$.
My choice of $P$,$Q$ and $R$ are as follows: \begin{equation} P =\begin{bmatrix} 0 & 0& 0 & 0 \\ 0 & 0 &0& 0 \\ 0 & 0 &0 & 0 \\ 0 & 0 & 0 & 0.1 \end{bmatrix} \end{equation}
\begin{equation} Q =\begin{bmatrix} 0 & 0& 0 & 0 \\ 0 & 0 &0& 0 \\ 0 & 0 &0 & 0 \\ 0 & 0 & 0 & 0.1 \end{bmatrix} \end{equation}
\begin{equation} R =\begin{bmatrix} \sigma_I& 0 \\ 0 & \sigma_v \end{bmatrix} \end{equation}
The estimation works initially fine, where the resistance hasn't yet changed, but when it does, the kalman filter doesn't respond correctly. It either doesn't respond as fast as needed or just diverge from the real measurement.
I have implemented the extended kalman filter to tackle the nonlinearity in the measurement model, but it didn't work. the measurement remain constant at a completely random value with no change, regardless of the change in resistance.