DSPRelated.com
Forums

[HELP] Kalman Filter

Started by mak0202 October 20, 2010
Hi,
I'm working on a tracking system able to estimate the position of a walking
person moving in a 2D scenario.
I only measure the x and y coordinates of the person, and I would like to
improve the tracking algorithm using a Kalman Filter in Matlab.
My question is:
how can I correctly model the real process? 
For example, I don't understand how to set the process noise covariance
matrix Q, since I probably didn't understand its real meaning.
Have I to consider the acceleration as the process noise? Or should I
include the acceleration into the state to be estimated?

Till now, I have (not Matlab code):

state X = [x, y, vx, vy, ax, ay]

matrix A = [1 0 dt 0 0 0 ]
           [0 1 0 dt 0 0 ]
           [0 0 1 0 dt 0 ] 
           [0 0 0 1 0 dt ]
           [0 0 0 0 1 0  ]
           [0 0 0 0 0 1  ]

matrix H = [1 0 0 0 0 0 ]
           [0 1 0 0 0 0 ]

Now, I can't see what would be the best approach for defining the Q
matrix.
Can you help me?

Thanks
Marco


On 10/20/2010 12:06 PM, mak0202 wrote:
> Hi, > I'm working on a tracking system able to estimate the position of a walking > person moving in a 2D scenario. > I only measure the x and y coordinates of the person, and I would like to > improve the tracking algorithm using a Kalman Filter in Matlab. > My question is: > how can I correctly model the real process? > For example, I don't understand how to set the process noise covariance > matrix Q, since I probably didn't understand its real meaning. > Have I to consider the acceleration as the process noise? Or should I > include the acceleration into the state to be estimated? > > Till now, I have (not Matlab code): > > state X = [x, y, vx, vy, ax, ay] > > matrix A = [1 0 dt 0 0 0 ] > [0 1 0 dt 0 0 ] > [0 0 1 0 dt 0 ] > [0 0 0 1 0 dt ] > [0 0 0 0 1 0 ] > [0 0 0 0 0 1 ] > > matrix H = [1 0 0 0 0 0 ] > [0 1 0 0 0 0 ] > > Now, I can't see what would be the best approach for defining the Q > matrix. > Can you help me?
Your model and description is consistent with a guy walking around, for whom you have some means of measuring position but neither velocity nor acceleration. Is that correct? If so, then the "process noise" would be the expected accelerations that your subject would undergo -- i.e. it would be your expectation for when the guy says "hmm, I think I'll turn and go _that_ way". You filter will end up being a two-axis second-order lowpass, to which you can write "Kalman" on a post-it and stick it on. But it may not improve things as much as you want unless you also have some other information coming in. And if you do have other information coming in, it's not showing up in the model. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html
>Your model and description is consistent with a guy walking around, for >whom you have some means of measuring position but neither velocity nor >acceleration. > >Is that correct?
Yes, I can only measure the x and y position.
> >If so, then the "process noise" would be the expected accelerations that >your subject would undergo -- i.e. it would be your expectation for when >the guy says "hmm, I think I'll turn and go _that_ way".
Yes, I think this is the only way. But then, what could be the best choice for matrix Q?
> >You filter will end up being a two-axis second-order lowpass, to which >you can write "Kalman" on a post-it and stick it on. But it may not >improve things as much as you want unless you also have some other >information coming in. And if you do have other information coming in, >it's not showing up in the model.
Ok, so what kind of other information could be useful? Do you mean I need also velocity measurements? Or what else? I appreciate your help
> >-- > >Tim Wescott >Wescott Design Services >http://www.wescottdesign.com > >Do you need to implement control loops in software? >"Applied Control Theory for Embedded Systems" was written for you. >See details at http://www.wescottdesign.com/actfes/actfes.html >
On Thu, 21 Oct 2010 07:27:44 -0500, "mak0202"
<mak_0202@n_o_s_p_a_m.hotmail.com> wrote:

> >>Your model and description is consistent with a guy walking around, for >>whom you have some means of measuring position but neither velocity nor >>acceleration. >> >>Is that correct? > >Yes, I can only measure the x and y position. > > >> >>If so, then the "process noise" would be the expected accelerations that >>your subject would undergo -- i.e. it would be your expectation for when >>the guy says "hmm, I think I'll turn and go _that_ way". > >Yes, I think this is the only way. But then, what could be the best choice >for matrix Q? > >> >>You filter will end up being a two-axis second-order lowpass, to which >>you can write "Kalman" on a post-it and stick it on. But it may not >>improve things as much as you want unless you also have some other >>information coming in. And if you do have other information coming in, >>it's not showing up in the model. > >Ok, so what kind of other information could be useful? Do you mean I need >also velocity measurements? Or what else? > >I appreciate your help
Take a look at alpha-beta filters (or alpha-beta-gamma filters). It is not uncommon to find a-b/a-b-g filters used for 2D contact tracking in, for example, radar systems. The gains are fixed, unlike a Kalman filter where the gains are adjusted dynamically, but it is computationally "lighter" than a Kalman and may be easier to implement. The trade-off (there always is one) is that the results won't necessarily be optimal but they may be good enough. http://en.wikipedia.org/wiki/Alpha_beta_filter -- Rich Webb Norfolk, VA
On 10/21/2010 05:27 AM, mak0202 wrote:
>> Your model and description is consistent with a guy walking around, for >> whom you have some means of measuring position but neither velocity nor >> acceleration. >> >> Is that correct? > > Yes, I can only measure the x and y position. > > >> >> If so, then the "process noise" would be the expected accelerations that >> your subject would undergo -- i.e. it would be your expectation for when >> the guy says "hmm, I think I'll turn and go _that_ way". > > Yes, I think this is the only way. But then, what could be the best choice > for matrix Q?
I can't answer that. Is the guy in a good mood and dancing around? Stomping in a straight line 'cause he's angry? Sitting in one place because he's depressed or just got laid (if it's both he needs a new girlfriend)? Wandering aimlessly because he's drunk? To be 'optimal' in the least-squared sense, the Kalman filter demands that Q be known -- and you're the best one to know it, and if it can be known at all. I don't think you can get there from here -- Rich Webb mentions alpha-beta filters, and I don't think that's at all a bad approach here unless you need really fast acquisition. With an alpha-beta filter you're at least not pretending that you can predict the guy's behavior, you're just making a filter that'll sorta-kinda do what you want. Note 1: you can decide on a Q and make a "time invariant Kalman", which is a filter whose gains are the asymptote of the gains in a "full on" Kalman. You'll find that the _structure_ of the filter is (or can be) exactly the same as the alpha-beta or alpha-beta-gamma filter; the only difference will be how you arrived at the gains and the names that you give them. Note 2: If the system is semi-automatic you can make a number of alpha-beta filters, and let the user select which one. Then you have to find some meaningful names to give them. I've done this before for video tracking systems, where the needs for tracking cars on a crowded freeway, for instance, is markedly different than the needs for tracking an aerobatic airplane.
>> You filter will end up being a two-axis second-order lowpass, to which >> you can write "Kalman" on a post-it and stick it on. But it may not >> improve things as much as you want unless you also have some other >> information coming in. And if you do have other information coming in, >> it's not showing up in the model. > > Ok, so what kind of other information could be useful? Do you mean I need > also velocity measurements? Or what else?
Just about any _independent_ measurements of motion -- velocity, acceleration, etc. If you could hang an IMU on the guy's neck and transmit that data, then you'd have the classic navigational sensor fusion task. It's still rocket science, but it's _doable_ rocket science. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Do you need to implement control loops in software? "Applied Control Theory for Embedded Systems" was written for you. See details at http://www.wescottdesign.com/actfes/actfes.html