The goal is to include variable measurement noise to my kalman filter. To begin with I kept the noise covariance matrix as follows: $$ R=\begin{bmatrix}1&0&0&0\\ 0&1&0&0\\ 0&0&1&0\\ 0&0&0&1\end{bmatrix}$$
This gave good results, the Kalman filter did a good job following the input data.
Next I tried to calculate the measurement noise covariance myself: https://pastebin.com/7ETMC0Fy
Which gave such results:
Could someone tell me why when I try to calculate my measurement noise covariance matrix myself the result is unsatisfactory? Why doesn't the output of my Kalman filter follow the input data at all?