Understanding the Extended Kalman Filter

In summary: I missing something?In summary, the conversation is about the Extended Kalman Filter (EKF) and the difficulty in understanding and implementing it. The conversation includes references to a book on the subject, as well as a suggestion to contact a professor for further help. The conversation also includes a derivation of the EKF and a specific request for help in calculating certain terms related to tracking a noisy sinusoid.
  • #1
Ultimâ
35
0
Hi there,

I'm wasn't sure whether I should post this question in the maths section or here, but since this technique is used a lot in aerospace I thought I'd try here first.

I've grasped the idea of an ordinary Kalman Filter and created a program that tracks a noisy signal. However when it comes to modifying the program to an EKF I'm at a total loss. I've spent weeks reading up on this and searching for examples, but I'm still unable to figure how to calculate the modified equations (especially the Jacobian terms). So I have decided to ask if anyone on these forums have any expertise in this area and could possibly help me out.

Can anyone suggest how I calculate the Jacobians A_k (sometimes described as F_k) and H_k for a simple case of tracking an x-coordinate over time? I'm assuming the noise has no gain.

Thanks,
Charles
 
Astronomy news on Phys.org
  • #3
Ultima, I'm going to move this thread to General Math in the hopes you get a response.

I have seen the Kalman filter used, but I certainly don't have a good enough grasp on it to explain the nuts and bolts.
 
  • #4
Eh... maybe Celestial Mechanics.

Sorry for the lack of response, Ultima. It's a tricky subject.
 
  • #5
Hey Ultima,

I took some graduate level courses in Statistical Orbit Determination in college unfortunately we only worked with generic Kalman filtering (and that was over 4 years ago :P ). Extended Kalman filtering was covered in another course I never had the fortune of taking. However, my former professor, George Born at the University of Colorado Boulder, co-authored a book "Statistical Orbit Determination" which covers some applications of EKF and he also wrote a paper on variations a while back:


http://www.space-flight.org/AAS_meetings/1996_winter/abstracts/96-108.html

So in short while I can't help you directly perhaps you could try contacting Prof. Born via e-mail:

http://aerospace.colorado.edu/frameset.php/facstaff/facultyHTMLfiles/born.html


He might be willing to answer your questions directly or perhaps provide you with a place to look for examples of the EKF implemented by others. Papers or perhaps other books or programs written which would be accessible online.

Hope that helps!
 
Last edited by a moderator:
  • #6
I was beginning to lose hope.

Enigma, thanks for your help in finding the best place for this thread.

Goavs4, I've now put in a request with the British Library and should have the book in a week or so. I may send Prof. Born an email and see if he can suggest any good references (don't like to inconvenience people though).

From all that I've read it would appear that the step from the Kalman filter to the EKF is fairly straightforward...I think I must be just missing some fundamental issue that might be rectified through a good example, but sadly, simple examples of the EKF seem a bit like the needle in the haystack senario.

Thanks for you input Goavs4 =)
 
  • #7
Consider the process:
[tex]x_{k+1} = f(x_{k},k) + w_k[/tex]
with noisy measurements:
[tex]z_k = h(x_{k},k) + v_k[/tex]
Where f and h are nonlinear functions of the state x and [tex]w_k[/tex] and [tex] v_k[/tex] are gaussian noises.
If we know an unbiased estimation [tex]\hat x_{k|k}[/tex] of the state at the instant k we can develop [tex]f(x_{k},k)[/tex] in a Taylor series around [tex]\hat x_{k|k}[/tex].
[tex]x_{k+1} = f(\hat x_{k|k},k) + f_x(\hat x_{k|k},k)e_{k|k} + \frac{1}{2}f_{xx}(\hat x_{k|k},k)e_{k|k} (x) e_{k|k} + ...[/tex]
Where:
[tex]e_{k|j} = x_k - \hat x_{k|j}[/tex]
[tex]f_x = \frac {\partial f}{\partial x^T}[/tex]
[tex]f_{xx} = \frac {\partial ^2 f}{\partial x^T \partial x^T}[/tex]
and (x) is the Kronecker matrix product.
If the errors are small, we can add the terms of second and higher orders to the noise and write:
[tex]x_{k+1} = f(\hat x_{k|k},k) + f_x(\hat x_{k|k},k)e_{k|k} + w'_k[/tex]
Before the arrival of the measurement [tex]z_{k+1}[/tex] the best estimate of [tex]x_{k+1}[/tex] is its mathematical expectation:
[tex]\hat x_{k+1|k} = E[x_{k+1}] = f(\hat x_{k|k},k) [/tex]
We can now develop [tex]h(x_k,k)[/tex] in series around the new estimate:
[tex]z_{k+1} = h(\hat x_{k+1|k},k+1) + h_x(\hat x_{k+1|k+1},k)e_{k+1|k} + \frac{1}{2}h_{xx}(\hat x_{k+1|k},k+1)e_{k+1|k} (x) e_{k+1|k} + ...[/tex]
again, supposing [tex] e_{k+1|k}[/tex] is small we can write:
[tex]z_{k+1} = h(\hat x_{k+1|k},k) + h_x(\hat x_{k+1|k},k)e_{k+1|k} + v'_{k+1}[/tex]
After the arrival of the measurement [tex]z_{k+1}[/tex] the best estimate of [tex]x_{k+1}[/tex] is:
[tex]\hat x_{k+1|k+1} = \hat x_{k+1|k} + K_{k+1}[z_{k+1} - h(\hat x_{k+1|k},k+1)][/tex]
Where
[tex]K_{k+1} = P_{k+1|k}.h_x^T[h_x.P_{k+1|k}.h_x^T + R_{k+1}]^{-1}[/tex]
[tex]P_{k+1|k} = E[e_{k+1|k} . e^T_{k+1|k} = f_x.P_{k|k}.f_x^T + Q_k[/tex]
The new error covariance matrix is:
[tex]P_{k+1|k+1} = E[e_{k+1|k+1} . e^T_{k+1|k+1} = [I - K_{k+1}.h_x].P_{k+1|k}.[I - K_{k+1}.h_x]^T + K_{k+1}.R_{k+1}.K^T_{k+1}[/tex]
Where [tex]Q_k[/tex] and [tex]R_k[/tex] are the covariances of the process and measurement noises respectively.
 
  • #8
enigma said:
Eh... maybe Celestial Mechanics.

Sorry for the lack of response, Ultima. It's a tricky subject.
I would put it in Electrical Engineering or in Engineering Systems and Design.
 
  • #9
Thanks SGT for that derivation. I was also amazed to learn that this forum supports Latex, which will help me express myself far better now and in the future. It really does put a smile on my face when I find I've had a reply.

Anyway, specifically I'm asking for help with calculating

[tex]f_x[/tex], [tex]h_x[/tex] and [tex]h(\hat{x}_{k+1|k}, k+1)[/tex] (from 2 posts above for any new comers).

So if we are tracking a noisy sinusoid (for example), let's say the first part of the data stream for for the observation of the input ([tex]z[/tex]) is:

0.044, 0.088, 0.143, 0.188, 0.261, 0.355, 0.352, 0.287

and the corresponding estimate of the input ([tex]\hat{x}[/tex]) is:

0.004, 0.017, 0.043, 0.077, 0.123, 0.184, 0.229, 0.244

how would the three above terms be calculated? Are the first two simply looking at the rate of change of [tex]z[/tex] and [tex]\hat{x}[/tex] and the last term ([tex]h(\hat{x}_{k+1|k}, k+1)[/tex]) simply equal to [tex]\hat{x}[/tex] for this example?
 
Last edited:
  • #10
Ultimâ said:
Thanks SGT for that derivation. I was also amazed to learn that this forum supports Latex, which will help me express myself far better now and in the future. It really does put a smile on my face when I find I've had a reply.

Anyway, specifically I'm asking for help with calculating

[tex]f_x[/tex], [tex]h_x[/tex] and [tex]h(\hat{x}_{k+1|k}, k+1)[/tex].

So if we are tracking a noisy sinusoid (for example), let's say the first part of the data stream for for the observation of the input ([tex]z[/tex]) is:

0.044, 0.088, 0.143, 0.188, 0.261, 0.355, 0.352, 0.287

and the corresponding estimate of the input ([tex]\hat{x}[/tex]) is:

0.004, 0.017, 0.043, 0.077, 0.123, 0.184, 0.229, 0.244

how would the three above terms be calculated? Are the first two simply looking at the rate of change of [tex]z[/tex] and [tex]\hat{x}[/tex] and the last term ([tex]h(\hat{x}_{k+1|k}, k+1)[/tex]) simply equal to [tex]\hat{x}[/tex] for this example?

Could you elaborate a little more? What is your state vector [tex]x[/tex]? Are its components position and velocity? And what are your observations [tex]z[/tex]? Is [tex]z [/tex] the measurement of the position?
What are the functions [tex]f(x_k,k)[/tex] and [tex]h(x_k,k)[/tex] ?
 
Last edited by a moderator:
  • #11
Right, we're just dealing with an x-position with respect to k, [tex]x[/tex] and [tex]z[/tex] can be treated as scalers. So for the first k, the observation is 0.004, [tex]z=h(x_k,k)+v_k=Hx_k[/tex]+ [tex]v_k[/tex], in this case the observation is of the state directly, so H is unity) and the state is [tex]x_{k+1}+w_k=f(x_k,k)=Ax_k+w_k[/tex]
 
Last edited:
  • #12
For such a simple system you don't need an EKF. A linear Kalman Filter will do. Your state is simply:
[tex]\vec x = \left [
\begin{array}{cc}
x \\
\dot x
\end{array}
\right ]
[/tex]
Your state equation is linear:
[tex]\vec x_{k+1} = A.\vec x_k + w_k[/tex]
where
[tex]A = \left [
\begin{array}{cc}
1 & T \\
0 & 1
\end{array}
\right ]
[/tex]
and T is the time interval between observations.
For the initial position [tex]x_0[/tex] you take the first observation [tex]z_0[/tex] and for the initial velocity you take the difference of the first two measurements divided by T.
[tex]\vec x_0 = \left [
\begin{array}{cc}
0.044 \\
\frac {0.044}{T}
\end{array}
\right ]
[/tex]
For the initial value of the error covariance matrix you can use :
[tex]P_{0|0} = \left [
\begin{array}{cc}
100\sigma_x^2 & 0 \\
0 & 100\sigma_v^2
\end{array}
\right ]
[/tex]
The matrix R is simply the scalar [tex]\sigma_z^2[/tex]
 
Last edited by a moderator:
  • #13
Although, I'll probably find this bit of information (working with vectors in KF) beneficial in the long term, in my first post I mention that I've implemented a scaler version of the Kalman Filter that works fine (In my model I assume [tex]x_0[/tex]=0 and [tex]P_0[/tex]=1). The idea was to amend this so it acted as an extended kalman filter. I realize that the KF is better for such a simple system, but my aim is to understand the EKF. When I tried to apply the EKF, I found I was unsure how to calculate the three variables mentioned in post #9.
 
  • #14
You cannot use an EKF with a linear system. And a scalar linear Kalman filter is inefficient. Since the KF can provide you with velocity information, why not use it? The abandon of this information will provide you with a smoothed estimation. You said your data belonged to a sinusoid. If you don't use the velocity information you will end with the mean value of the sinusoid: zero.
 
  • #15
My KF model comes from the example in the following paper
http://www.cs.unc.edu/~welch/media/pdf/kalman_intro.pdf

I then changed the input signal from a constant voltage to a sinewave. The programmed filter tracks it reasonably well provided R and Q are choosen wisely.

Velocity isn't used in the example so I didn't incorporate it in my initial program model.

My understanding of the EKF is that, yes it is designed to handle non-linear systems, but this is through linearising the model at its current position, which suggests that it can be applied to linear models, but will not be as accurate as the normal kf.

So we are effectively tracking the position, with only the observation of a single x-coordinate available to us. I'd expect the ekf should produce better results for such a situation...
 
Last edited:
  • #16
The example from the paper deals with the estimation of a constant, so there is no velocity involved. If you want to estimate the position of a mobile you must either know its velocity or to estimate it through the filter.
You cannot use an EKF with a linear system, because the functions [tex]f[/tex] and [tex]h[/tex] are linear functions of the state [tex]x[/tex], so their derivatives [tex]f_x[/tex] and [tex]h_x[/tex] are simply constants.
 
Last edited by a moderator:
  • #17
This makes sense, [tex]f_x[/tex] and [tex]h_x[/tex] seemed to become zero when I tried to calculate them and may be the fundamental reason why I am having difficulty understanding the EKF. So what would be the simplest non-linear model to apply an EKF too?
 
  • #18
Ultimâ said:
This makes sense, [tex]f_x[/tex] and [tex]h_x[/tex] seemed to become zero when I tried to calculate them and may be the fundamental reason why I am having difficulty understanding the EKF. So what would be the simplest non-linear model to apply an EKF too?
Suppose you have a stationary point in a plane, with coordinates [tex]x_0[/tex] and [tex]y_0[/tex]. You measure the distance and the azimuth from the origin to the point:
[tex]d = \sqrt{x_0^2 + y_0^2} + \nu_d[/tex]
[tex]az = tan^{-1}\frac{y}{x} + \nu_{az}[/tex]
Now your [tex]h[/tex] is a nonlinear function of the state and you can calculate [tex]h_x[/tex].
The function [tex]f[/tex] is still linear, but if one of the two functions is nonlinear you must use an EKF.
 

1. What is the Extended Kalman Filter (EKF)?

The Extended Kalman Filter is a mathematical algorithm used for estimating the state of a system that is modeled using nonlinear functions. It is an extension of the traditional Kalman Filter, which is designed for linear systems. The EKF is commonly used in fields such as robotics, aerospace, and control theory.

2. How does the EKF work?

The EKF works by using a series of mathematical equations to iteratively estimate the state of a system. It combines two main steps: the prediction step, where the system's state is predicted based on the previous state and a control input, and the update step, where measurements are used to correct the predicted state. This process is repeated continuously to improve the accuracy of the state estimate.

3. What types of systems can the EKF be applied to?

The EKF can be applied to systems that are modeled using nonlinear functions. This includes systems with non-Gaussian noise, non-linear dynamics, and systems with unknown or time-varying parameters. Examples of systems that can be modeled using the EKF include autonomous vehicles, aircraft, and spacecraft.

4. What are the limitations of the EKF?

The EKF has some limitations which can affect its performance. These include the assumption of Gaussian noise and the linearity of the system's dynamics. If these assumptions do not hold, the EKF may produce inaccurate state estimates. Additionally, the EKF can struggle with highly nonlinear systems or systems with significant measurement noise.

5. How is the EKF different from the traditional Kalman Filter?

The main difference between the EKF and the traditional Kalman Filter is that the EKF can handle nonlinear systems, while the traditional Kalman Filter is designed for linear systems. The EKF also uses a linear approximation of the nonlinear system, whereas the traditional Kalman Filter uses the exact linear equations. This makes the EKF more complex but also allows it to be applied to a wider range of systems.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
801
Replies
1
Views
2K
  • General Math
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Mechanical Engineering
Replies
7
Views
21K
  • Mechanical Engineering
Replies
1
Views
4K
  • Mechanical Engineering
Replies
4
Views
6K
Replies
2
Views
3K
Replies
1
Views
3K
  • Electrical Engineering
3
Replies
85
Views
8K
Back
Top