Skip to content

Recursive Kalman Estimator

antonays edited this page Feb 10, 2016 · 1 revision

Given a set of input and output samples, the target is to find the Transfer Function which may generate these samples.

1st step would be to generate a step response of the given samples, and analyze the response to identify the order of the function.

2nd step would be to apply the Recursive Kalman Estimation Algorithm.

In the given examples, 1st and 2nd order kalman estimation programs are written in C code. Same thing can easily be accomplished with an environment like matlab, which allows easy calculations. C code was chosen to apply these programs in an Adaptive Control program for Mechatronics applications using National Instruments MyRio Device and a program written in LabView environment which allows integrating c code as a controller.

Some notes:

  • The C Code block of LabView does not allow C Code pointers, methods and external libraries. So i uploaded my entire development process:
    • C program with pointers.
    • C program without pointers.
    • C program in which the entire code is in one function. The last one is a disgusting monster for a software guy, but nothing can be done.
  • The most commented versions are the 1st and 2nd order with Pointers, there i try to explain my entire solution.
  • The result of this algorithm generates the coefficients of the Resultant Transfer Function, so the next step would be to use this information design a Controller for this Transfer Function to be able to meet Open\Closed loop requirements and control our system in real time.

Kalman Estimation Algorithm


For a system of order n, with N samples:

  • m = n x 2
  • theta [m x 1] = vector that contains the coefficients of the resultant Transfer Function. Initialized randomly with integers within 1-10.
  • P Matrix [m x m] = is defined as Covariance Matrix, initialized as AxI where A is an large integer: 100,1000.. and I is an identity matrix [m x m].
  • y [1 x 1] = is a scalar that contains the output sample of the current iteration.
  • phi [m x 1] = defined as Information Vector, contains at each step, the samples from previous step(s), depending on the order of the system. u[i] = [ y[i-n] ... y[i-1] u[i-n] ... u[i-1] ].
  • L [1 x 1] = is a scalar defined as Forgetting Factor, which applies an exponential weight on past samples - older samples - less significant. L can be a number within 0-1, and in practice: the bigger the better.

The Algorithm iterates N times, on each iteration pulling the input and output sample (u(i) & y(i)) and applying the mathematical steps above, generating theta(i+1) which contains the estimated coefficients of the resultant Transfer Function. also, on each iteration, the P matrix is updated and saved for the next iteration.

Clone this wiki locally