How to Determine Correct Values for Q and R in Designing a Kalman Filter?

Click For Summary
Determining the correct values for the Q and R matrices in a Kalman filter involves understanding the noise characteristics of the system. The Q matrix represents the covariance of the process noise, while the R matrix represents the measurement noise, with diagonal elements typically corresponding to the variance of each sensor's noise. Estimating these matrices can be challenging; however, it is common to assume they are diagonal, indicating no correlation between different noise sources. For practical estimation, conducting controlled stationary measurements can help derive Q and R from data, using algorithms like Estimation Maximization or Autocovariance Least Squares. Ultimately, with sufficient data, good estimates for the diagonal elements of Q and R can be achieved, even if the overall results may vary.
Hemib
Messages
14
Reaction score
0
Hey,

I designed a kalman filter for my project. But how can I determine the correct values for Q and R?

Thx!
 
Physics news on Phys.org
Hi. The Q and R matrices characterize the noises in the model. It can be sometimes quite tricky to get good estimate values for these.

Just for context, the discrete linear state-space model that is the basis of the Kalman filter probably looks like this, no ?
x(k+1)=A x(k) + B w(k)
z(k) = C x(k) + v(k)
x is the state vector, z is the measurement vector. Q and R are related to noises w and v, which are in theory vector random variables.
w = [ w1 w2 ... wn ]'
v = [ v1 v2 ... vp ]'
The Q and R matrices are the variance matrices of these vectors, respectively:
Q=Cov(w,w)
R=Cov(v,v)
And in particular the diagonal elements of Q are {Var(w1) , ..., Var(wn)} and the diagonal elements of R are {Var(v1) , ..., Var(vp)}.

So the diagonal elements of the R matrix are usually easy to approximate because they are the noise levels - in scale of variance - of each sensor.

The w noise represents disturbances and modeling errors and this might not be so obvious, but depending on the problem some assumption could be made.

It depends on the problem, but it is also quite common to take both matrices diagonal, that is to assume that there are no correlation between the random variables w and respectively v, i.e. Cov(wi,wj)=0 and Cov(vi,vj)=0, for any i different than j. But it may also not be the case; for example say there are 3 sensors measuring the same output and they are partially correlated because some noise source is affecting them all in the same way. In this case the R matrix should have non-zero non-diagonal elements. So there are a number of assumptions that can be made as educated guesses.

If for your system is possible/practical to take a controlled stationary measurement, such that that the main states x=0 for all the measurement, and only the noise is picked up, then it is also possible to estimate Q and R from data.

Such a stationary / noisy dynamic would be :
x(1) = A0 + Bw(1); z(1) = CBw(1)+ v(1)
x(2) = ABw(1) + Bw(2) z(2) = C(ABw(1)+Bw(2)) + v(2)
...

And the measurement sequence Z(N) = {z(1), ..., z(N) } can then be used to estimate values for Q and R.

I assumed all along that the noise properties are not time-varying, but constant. So Q(t1)=Q(t2)=Q and the same for R.

There are different algorithms that can be used to do this estimation. You feed the sequence Z and the model to the algorithm, and it will spit out Q and R. I've recently tried to look into such algorithms, I used something called Estimation Maximization and then Autocovariance Least Squares. I think the last one is more reliable, and there is also a GNU Octave/MATLAB toolbox available here: http://jbrwww.che.wisc.edu/software/als/.

For my problem I did not manage in fact to get good results, but arguably, if the Q and R are indeed constant and you can take a long enough measurement session Z(N), at least the diagonal elements of both Q and R are fairly good estimated.
 
Last edited:
There are probably loads of proofs of this online, but I do not want to cheat. Here is my attempt: Convexity says that $$f(\lambda a + (1-\lambda)b) \leq \lambda f(a) + (1-\lambda) f(b)$$ $$f(b + \lambda(a-b)) \leq f(b) + \lambda (f(a) - f(b))$$ We know from the intermediate value theorem that there exists a ##c \in (b,a)## such that $$\frac{f(a) - f(b)}{a-b} = f'(c).$$ Hence $$f(b + \lambda(a-b)) \leq f(b) + \lambda (a - b) f'(c))$$ $$\frac{f(b + \lambda(a-b)) - f(b)}{\lambda(a-b)}...

Similar threads

Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
4K