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.