# 0.2 Implementation of the kalman filter

 Page 1 / 1
Explanation of the Kalman Filter implementation for digital rocket apogee detection.

Kalman Filter

The Kalman filter is a time domain method of incorporating knowledge of the physical model of the system and of the reliability of the sensors to accurately estimate the state of the system. Implementation of the Kalman filter first requires the creation of an accurate physical model of the system. The two equations which are used to determine the estimate of the current state from that of the previous state are:

${x}_{k}={\mathrm{Ax}}_{k-1}$
${x}_{k}={x}_{k}+K(m-H{x}_{k})$
$x=\left(\begin{array}{c}s\\ v\\ a\end{array}\right)$

Near apogee, the physical equations governing the rocket’s flight are simple, which makes A simple. The only force acting on the rocket is gravity only (because drag forces vary with the square of the velocity they can be neglected near apogee, where the velocity is close to zero).

$s=vt+\frac{1}{2}at^{2}$
$v=at$
$a=-g$
$\begin{pmatrix}1 & \mathrm{\Delta t} & \frac{\mathrm{\Delta t}^{2}}{2}\\ 0 & 1 & \mathrm{\Delta t}\\ 0 & 0 & 1\\ \end{pmatrix}$

Where ∆t is the time between x k and x k+1 .

m is a vector of the measured values from the sensors. Position is measured with the barometer and acceleration by the accelerometer.

$\begin{pmatrix}{s}_{m}\\ {a}_{m}\\ \end{pmatrix}$

H is a matrix which maps x k to m:

$\begin{pmatrix}1 & 0 & 0\\ 0 & 0 & 1\\ \end{pmatrix}$

Finally, K , the Kalman gain matrix, weights the difference between the measured values and the estimated values. K is typically computed in real time as the system changes. However, the formula for K is rather complicated and therefore difficult to implement on a microcontroller in real time. Luckily, because the rocket’s flight can be approximated over the whole flight by the system and because the sensor variances do not change, K can be precomputed via the following recursive process:

$K=PH^{T}(HPH^{T}+R)^{-1}$
$P=(I-KP)P$
$P=APA^{T}+Q$

In a small number of repetitions, K will converge. In these equations, R is the measurement noise covariance matrix which holds the variances for each sensor:

$\begin{pmatrix}{\sigma }_{p}^{2} & 0\\ 0 & {\sigma }_{a}^{2}\\ \end{pmatrix}$

P is called the error covariance matrix, and it is first approximated with a guess, and then recursively defined like the K matrix. Finally, Q is the process noise covariance matrix, and is associated with the amount of noise added to the estimate in each time step. The code for calculating the K matrix is shown below:

.% Calculates the Kalman gain H = [1 0 0; 0 0 1]; % maps x (state variables) to z (sensor data) R = [35.8229 0; 0 .0012]; % measurement noise covariance Q = [0 0 0; 0 0 0; 0 0 1]; % process noise covariance matrix T = .05; % time stepA = [1 T 1/2 * T^2; 0 1 T; 0 0 1]; % maps previous state to next state% these three equations recursively define k (matrix of kalman gains) % and P (error covariance matrix)P = eye(3); % initial guess for p for i = 1:20K = P*H'/(H*P*H' + R); % Kalman gainsP = (eye(3) - K *H)*P; P = A*P*A' + Q;end display(K)display(H) display(P)

The last piece of code demonstrates the actual implementation of the Kalman filter in Matlab.

.% implements Kalman filter on altitude and accelerometer data. Required vectors are alt and accel, which are vectors cointaining the altitude and accelerometer data at times corresponding to the time vector t. t = .05:.05:15;estimate = zeros(3,length(t)); estimate(:,1) = [alt(1); 0; accel(1)]; for i = 2:length(t)estimate(:,i) = A*estimate(:,i-1); estimate(:,i) = estimate(:,i) + K*([alt(i);accel(i)]- H *estimate(:,i));end

#### Questions & Answers

do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
Do somebody tell me a best nano engineering book for beginners?
what is fullerene does it is used to make bukky balls
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
what is the Synthesis, properties,and applications of carbon nano chemistry
Mostly, they use nano carbon for electronics and for materials to be strengthened.
Virgil
is Bucky paper clear?
CYNTHIA
so some one know about replacing silicon atom with phosphorous in semiconductors device?
Yeah, it is a pain to say the least. You basically have to heat the substarte up to around 1000 degrees celcius then pass phosphene gas over top of it, which is explosive and toxic by the way, under very low pressure.
Harper
Do you know which machine is used to that process?
s.
how to fabricate graphene ink ?
for screen printed electrodes ?
SUYASH
What is lattice structure?
of graphene you mean?
Ebrahim
or in general
Ebrahim
in general
s.
Graphene has a hexagonal structure
tahir
On having this app for quite a bit time, Haven't realised there's a chat room in it.
Cied
what is biological synthesis of nanoparticles
what's the easiest and fastest way to the synthesize AgNP?
China
Cied
types of nano material
I start with an easy one. carbon nanotubes woven into a long filament like a string
Porter
many many of nanotubes
Porter
what is the k.e before it land
Yasmin
what is the function of carbon nanotubes?
Cesar
I'm interested in nanotube
Uday
what is nanomaterials​ and their applications of sensors.
what is nano technology
what is system testing?
preparation of nanomaterial
Yes, Nanotechnology has a very fast field of applications and their is always something new to do with it...
what is system testing
what is the application of nanotechnology?
Stotaw
In this morden time nanotechnology used in many field . 1-Electronics-manufacturad IC ,RAM,MRAM,solar panel etc 2-Helth and Medical-Nanomedicine,Drug Dilivery for cancer treatment etc 3- Atomobile -MEMS, Coating on car etc. and may other field for details you can check at Google
Azam
anybody can imagine what will be happen after 100 years from now in nano tech world
Prasenjit
after 100 year this will be not nanotechnology maybe this technology name will be change . maybe aftet 100 year . we work on electron lable practically about its properties and behaviour by the different instruments
Azam
name doesn't matter , whatever it will be change... I'm taking about effect on circumstances of the microscopic world
Prasenjit
how hard could it be to apply nanotechnology against viral infections such HIV or Ebola?
Damian
silver nanoparticles could handle the job?
Damian
not now but maybe in future only AgNP maybe any other nanomaterials
Azam
Hello
Uday
I'm interested in Nanotube
Uday
this technology will not going on for the long time , so I'm thinking about femtotechnology 10^-15
Prasenjit
how did you get the value of 2000N.What calculations are needed to arrive at it
Privacy Information Security Software Version 1.1a
Good
Berger describes sociologists as concerned with
Got questions? Join the online conversation and get instant answers!