# How to add the noise covariance matrix of my measurements to tmy 1D kalman filter?

So I am new to kalman filters. This is my first experience with it.

I have some measurements but sometimes due to external factors those measurements become totally wrong (hence the peak when you run my matlab code). If I understand the principles of kalman filtering correctly, I can compensate this incorrect measurements by setting the measurement covariance matrix R as a variable, where R represents the accuracy of the measurement devide. But so far I am not sure about where I should add or how I should include this measurement covariance matrix in my measurements.

Could anybody help me out?

I have tried as follows: https://pastebin.com/KQEx5T10 But am totally not sure about my results.To me it looks like both of the outputs of my kalman filter are too far away from the actual measurements once the peak happened... I would have expected the output curves to be between the "toothshaped" curve and not above it.

In the mean time, the measurement noise covariance matrix $R$ is adjusted according to the a priori known (either empirically or theoretically) characteristics of the measurement device (the sensors). When these characteristics change during the operation time of the filter, then you would expectedly reflect that in an update of the measurement noise matrix $R$ according to the new settings.
You will include this measurement noise covariance matrix into the Kalman update equations. Which previously using fixed $R$ will now be using variable $R$ matrix, as a matter of fact.
• You need to recalculate the measurment error covariance matrix $R$, only when the measurement noise variance (of a white gaussian noise for example) changes. If that changes for every sampling instant, you should recalculate $R$ in accordance. Normally 1 filter or 15 (parallel) filters do not matter. This is true for each filter. – Fat32 Apr 2 '17 at 20:12