@tvey, I can't even get these guys to calculate the C value in OkiePC's example correctly. I doubt they will go through the effort.
Also, I have been on many engineering forums where Kalman filters were discussed. Engineers do not know the values to use for process and measurement noise so they fudge it which is not that much different from the people on this forum fudging the value of C.
Your Kalman filter is still basically a simple low pass filter.In your example the Kalman gain will soon reach a steady state value dependent of the initial values of q and r so why not just enter the k value directly? I don't see where your k gain changes as a function of the measurement noise.
I wanted something like this for our motion controllers. It would be handy to have a filter with minimal phase lag for filtering encoder counts. Knowing that people will just fudge parameters until they get the desired results, I implemented a alpha-beta-gamma and alpha-beta-gamma-delta filter. The basic form is alpha-beta filter.
https://en.wikipedia.org/wiki/Alpha_beta_filter
This family of filters is basically a steady state Kalman filter that makes no pretense of knowing the measurement or process noise. The customer just picks a bandwidth until he gets the desired response. The huge advantage of the alpha-beta class of filters is that they don't suffer from phase lag as much as normal low pass filters because there is a prediction phase where x is updated(estimated) and then corrected using the k gains.
This is a 3rd order alpha-beta-gamma filter. I simulate noise and feed back resolution quantizing.
ABG (deltamotion.com)
This is basically the same thing on a 4th order alpha-beta-gamma-delta filter
ABGD (deltamotion.com)
I used the same noise generated in the 4th order example as used in the 3rd order example. Notice that the 4th order filter is more accurate.
The key is that having higher order filters allow for better prediction and therefore less phase lag. You can see there is little
BTW, the examples were don't because we were controlling a crane like device that only had feedback every 10 ms from a MRU ( motion reference unit ) where as we needed feedback every 1 ms so we had to estimate the state every millisecond better the 10 millisecond readings.
We haven't found any MRUs that can do a better job of filtering that us so far.
alpha-beta-gamma filter in action. The feedback is coarse, only 2000 counts per revolution and the update rate is every 250 microseconds. The ability to calculate speed is hindered by the low resolution but I can even estimate an acceleration. Using the encoder counts directly is pointless. I show the difference between the alpha-beta-gamma filter and a four pole Butterworth filter. This example is extreme because rarely do motors move in such a random way.
https://deltamotion.com/peter/Videos/AlphaBetaGamma.mp4
I have posted these links before and still, no one has made an AOI or a Siemens FB from the code after all these years.