kalman filter interview questions

I must discuss the Kalman filter with you because what it can do is absolutely incredible.

It is a general and effective tool for combining information in the face of uncertainty, but surprisingly few software engineers and scientists seem to be aware of it. If I sound overly enthusiastic about this technology’s ability to extract accurate information, look at this previously posted video where I show how a Kalman filter can determine the orientation of a free-floating body by analyzing its velocity. Totally neat!.

Anywhere you have ambiguous information about a dynamic system, you can use a Kalman filter to make an educated guess as to what the system will do next. The Kalman filter will frequently be very effective at determining what actually occurred, even if messy reality interferes with the clean motion you assumed. Additionally, it can make use of correlations between bizarre phenomena that you might not have thought to use.

Kalman filters are ideal for systems which are continuously changing. They have the benefit of using little memory (only the previous state needs to be stored in memory), which makes them well suited for embedded systems and real-time problems.

In most Google searches, the math for using the Kalman filter appears to be quite frightening and opaque. That’s unfortunate because, when viewed correctly, the Kalman filter is incredibly straightforward and simple to comprehend. Consequently, it makes for a fantastic article topic, and I will try to clarify it by using numerous crisp, lovely images and colors. The prerequisites are straightforward; all you need is a fundamental knowledge of matrices and probability.

If you want to skip ahead to the flashy images and math, I’ll start with a loose example of the kind of problem a Kalman filter can solve.

Consider a toy robot that you built that can roam the woods. In order for the robot to navigate, it needs to know exactly where it is.

We’ll call this state (vecx_k) for our robot, which is just a position and velocity:

Keep in mind that the state is merely a list of numbers describing the fundamental configuration of your system; anything could be listed there. In our example, it is position and velocity, but it could also be information about the volume of fluid in a tank, the engine temperature, the user’s finger position on a touchpad, or any other number of things you need to monitor.

Additionally, our robot has a GPS sensor, which is useful and accurate to about 10 meters, but it needs to know its location with greater accuracy. In these woods, there are many gullies and cliffs, and if the robot is off by more than a few feet, it could plunge off one. So GPS by itself is not good enough.

We may also understand how the robot moves because it understands the instructions given to the wheel motors and anticipates its next location if nothing prevents it from moving in the direction it is currently traveling in. The robot may be buffeted by the wind, the wheels may slip slightly, or it may roll over uneven ground; as a result, the amount the wheels have turned may not accurately represent how far the robot has actually traveled, and the prediction won’t be perfect.

The GPS sensor provides us with some state information, but only indirectly and with some ambiguity or inaccuracy. Our prediction provides some information about the robot’s movement, but only indirectly and with some degree of ambiguity or error.

But can we get a better answer than either estimate would provide us by itself if we use all the information available to us? Of course the answer is yes, and that’s what a Kalman filter is for.

Let’s look at the landscape we’re trying to interpret. We’ll keep going with a straightforward state that only has position and velocity. $$ vec{x} = begin{bmatrix} p v end{bmatrix}$$.

There are many different possible combinations of position and velocity that could be true, but some of them are more likely than others. We don’t know what the actual position and velocity are.

The Kalman filter considers both variables to be random and Gaussian distributed (in our case, position and velocity). Each variable has a mean value (mu), which is the random distribution’s center (and represents its most likely state), and a variance (sigma2), which represents the degree of uncertainty:

Position and velocity in the image above are uncorrelated, so what one variable is doing doesn’t tell you about what the other might be doing.

The following illustration demonstrates something more intriguing: Position and velocity are related. The velocity you have affects your chances of seeing a specific position:

For instance, if we are estimating a new position based on an old one, this type of circumstance might occur. We probably moved farther if our velocity was high, so our position will be farther away. If we’re moving slowly, we didn’t get as far.

Keeping track of this kind of relationship is crucial because it provides us with additional details: One measurement suggests potential values for the others. We want to extract as much information as we can from our unsure measurements, which is why we use the Kalman filter.

This correlation is captured by something called a covariance matrix. In essence, the degree of correlation between the ith state variable and the jth state variable is represented by each element of the matrix (Sigma_ij). (You might be able to infer that the covariance matrix is symmetric, in which case swapping i and j has no effect.) We refer to the elements of covariance matrices as “(Sigma_ij)” since they are frequently referred to as “(mathbfSigma)”.

We’ll refer to our best estimate at time (k) as (mathbfhatx_k) (the mean, also known as (mu)), and its covariance matrix as (mathbfP_k) because we’re modeling our knowledge of the state as a Gaussian blob. $$ begin “equation” labeled “eq:statevars” begin “aligned” mathbf “hat” “x” “_k” &= “bmatrix” text “position” text “velocity” end “bmatrix” mathbf “P” “_k” &= “bmatrix” Sigma_pp & Sigma_pv & Sigma_vp & Sigma_vv end “bmatrix” end “

(Of course, we are only using position and velocity here, but it’s helpful to keep in mind that the state can contain as many variables and as many different representations as you like.)

Next, we require a method for analyzing the present state (at time k-1) and forecasting the future state at time k. Though we are unaware of the “real” state, our prediction function is unconcerned about this. It simply functions on each of them and provides us with a new distribution:

gauss_7We can represent this prediction step with a matrix, (mathbf{F_k}):

It relocates every point from our initial estimate to a new location that is predicted, which is where the system would go if the initial estimate was accurate.

Let’s apply this. We’ll use a very simple kinematic formula to explain how to use a matrix to predict the position and velocity at a future time: $$ beginsplit colordeeppinkp_k &= colorroyalbluep_k-1 + Delta t &colorroyalbluev_k-1 colordeeppinkv_k &= &colorroyalbluev_k-1 end

We currently have a prediction matrix that tells us what state we will be in next, but we are still unsure of how to update the covariance matrix.

This is where we need another formula. What happens to a distribution’s covariance matrix (Sigma) if we multiply each point in the distribution by a matrix (color-firebrick-mathbf-A)?

Well, it’s easy. I’ll just give you the identity: $$ beginequation beginsplit Cov(color-firebrick-mathbf-A) &= Sigma Cov(color-firebrick-mathbf-A) &= color-firebf-AT endsplit labelcovident endequation

In order to combine (eqrefcovident) with equation (eqrefstatevars), the following steps must be taken: $$ beginequation beginsplit colordeeppinkmathbfhatx_k &= mathbfF_k colorroyalbluemathbfhatx__k-1 colordeeppinkmathbfP_k &= math

We haven’t captured everything, though. There could be some changes that aren’t connected to the state itself; the system might be impacted by the outside environment.

For instance, if the state simulates a train’s motion, the driver may depress the throttle, causing the train to speed up. The navigation software may also instruct the robot in our example to stop or turn its wheels. If we had access to this new information regarding what is occurring in the world, we could put it into a vector called (colordarkorangevecmathbfu_k), manipulate it, and then add it to our prediction as a correction.

Let’s assume that, as a result of the throttle setting or control commands, we are aware of the anticipated acceleration (color: darkorangea). We obtain the following equation in matrix form: $$ beginequation beginsplit colordeeppinkmathbfhatx_k &= mathbfF_k colorroyalbluemathbfhatx_k-1 + beginbmatrix fracDelta t

The control matrix is denoted by (mathbfB_k), and the control vector is denoted by (colordarkorangevecmathbfu_k). (You could omit these for very straightforward systems with no outside influences.)

Let’s add one more detail. What if our prediction is not a perfect representation of what is actually happening?

If the state develops based on its own characteristics, everything is fine. As long as we are aware of the external forces driving the state’s evolution, everything will be fine.

But what about unknown forces? For instance, if we were tracking a quadcopter, it might be buffeted by wind. The wheels of a wheeled robot we’re tracking could slip, or the robot could be slowed down by road bumps. We are unable to keep track of these factors, and if any of them materialize, our prediction may be inaccurate because we failed to take into account those additional forces.

We can model the uncertainty associated with the “world” (i. e. Adding a new level of uncertainty after each prediction step allows us to account for things we aren’t tracking:

Each state in our initial estimate could have changed to a variety of other states. We’ll say that each point in (colorroyalbluemathbfhatx_k-1) is moved to somewhere inside a Gaussian blob with covariance (colormediumaquamarinemathbfQ_k) because we love Gaussian blobs so much. Another way to put it is that we are treating the untracked influences as noise with covariance.

We can obtain the expanded covariance by adding (color “medium aquamarine” mathbf”Q”_k”), giving us the full expression for the prediction step: $$ begin equation begin split color “deep pink” mathbf”hat”x”_k” &= mathbf”F” color “royal blue” mathbf”hat”x”_k-1″ + mathbf”B” color “darkorange” mathbf”u”_k” color “deep

In other words, the previous best estimate is used to predict the new best estimate, plus known external influences are corrected.

Additionally, the environment contributes some additional uncertainty to the new uncertainty, which is predicted from the previous uncertainty.

All right, so that’s easy enough. With the help of (colordeeppinkmathbfhatx_k) and (colordeeppinkmathbfP_k), we can estimate where our system might be. What happens when we get some data from our sensors?.

We may have a number of sensors that provide data on the state of our system. It doesn’t matter what they’re measuring right now; perhaps one is reading position and the other is reading velocity. In other words, the sensors operate on a state and generate a set of readings that each indirectly inform us about the state.

Be aware that the scale and units of the reading might not match those of the state that we are tracking. You probably already know where this is going: We’ll use a matrix, (mathbfH_k), to model the sensors.

By following the standard procedure, we can determine the distribution of sensor readings we would expect to see: $$ beginequation beginaligned vecmu_textexpected &= mathbfH_k colordeeppinkmathbfhatx_k mathbfSigma_textexpected &= mathbfH_k colordeeppinkmathbfP

Dealing with sensor noise is one application that Kalman filters excel at. In other words, every state in our initial estimate could lead to a variety of sensor readings because our sensors are at least marginally unreliable.

We could infer the state of our system from every reading we observe. But because there is uncertainty, it is more likely in some states than others that the reading we saw occurred:

We’ll call the covariance of this uncertainty (i. e. of the sensor noise) (color{mediumaquamarine}{mathbf{R}_k}). The distribution’s mean, which we’ll refer to as (coloryellowgreenvecmathbfz_k), is the same as the value we observed.

The mean of our transformed prediction and the actual sensor reading we received are now surrounded by two Gaussian blobs.

We need to attempt to balance our prediction of the readings we would see based on the predicted state (pink) with a different prediction based on the sensor readings that we actually observed (green).

The probability that our sensor reading (color-yellow-green-vec-mathbf-z_k) is a (mis-)measurement of ((z_1,z_2)) and the probability that our previous estimate believes that ((z_1,z_2)) is the reading we should see are the two associated probabilities for any possible reading ((z_1,z_2)).

If we want to know the likelihood that two probabilities are true, we can simply multiply them together. So, we take the two Gaussian blobs and multiply them:

What remains is the overlap, which is the area where both blobs are bright and likely. And it’s much more accurate than either of our earlier projections. Given all the available data, the true configuration is most likely to be represented by the mean of this distribution, which is the configuration for which both estimates are most likely.

Maybe you can see where this is going: There’s got to be a formula to get those new parameters from the old ones! It turns out that when you multiply two Gaussian blobs with separate means and covariance matrices, you get a new Gaussian blob with its own mean and covariance matrix!

Let’s find that formula. It’s easiest to look at this first in one dimension. The following equation describes a 1D Gaussian bell curve with variance (sigma 2) and mean (mu): $$ begin equation label gaussformula mathcal N(x, mu,sigma) = frac1 sigma sqrt 2pi e -frac (x – mu)2 2sigma 2 end equation

What happens when you multiply two Gaussian curves together is what we want to know. The (unnormalized) intersection of the two Gaussian populations is shown by the blue curve below:

Equation (eqref) gaussformula can be substituted for equation (eqref) gaussequiv, and then you can perform some algebra (being careful to renormalize, so that the total probability is 1) to get the following result: $$ begin equation label fusionformula begin alignment color royalblue mu’ begin sigma_0 + sigma_1 + sigma_2 end alignment color mediumblue sigma’ end equation

We can reduce the complexity by factoring out a small portion and naming it (color purple mathbf k): $$ begin equation label gainformula color purple mathbf k = frac sigma 0 2 sigma 0 2 + sigma 1 2 end equation $$ $$ begin equation begin split color royal blue mu’ &= mu_0 + &color purple mathbf k &= (mu_1 – mu_0) color medium blue

Keep in mind how you can add something to your previous estimate to create a new estimate. And look at how simple that formula is!.

Let’s rewrite equations (eqref) gainformula and (eqref) update in matrix form instead to see what happens. If (Sigma) is the covariance matrix of a Gaussian blob and (vecmu) is its mean along each axis, then: $$ beginequation labelmatrixgain colorpurplemathbfK = Sigma_0 (Sigma_0 + Sigma_1)-1 endequation $$ $$ beginequation beginsplit colorroyalbluevec

The Kalman gain matrix is (color purple mathbf K), and we’ll use it in a moment.

We have two distributions: the predicted measurement with (color fuchsiamu_0, color deeppinkSigma_0) = (color fuchsiamathbfhatx_k, color deeppinkmathbfH_k mathbfP_k mathbfH_kT) and the observed measurement with (color yellowgreenmu_1, color medium aquamarineSigma_1) = (color yellowgreenvecmathbfz_k, To find their overlap, we can simply enter the following information into the equation (eqrefmatrixupdate): $$ beginequation beginaligned mathbfH_k colorroyalbluemathbfhatx_k’ &= colorfuchsiamathbfH_k mathbfhatx_k & + & colorpurplemath $$ beginequation beginsplit colorroyalbluemathbfhatx_k’ &= colorfuchsiamathbfhatx_k & + & colorpurplemathbfK’ (coloryellowgreenvecmathbfz_k – colorfuchsiamathbfH

That’s it! (color royal blue mathbfhatx_k’) is now our new best estimate, and we can continue to use it (along with (color royal blue mathbfP_k’)) in future rounds of prediction or updating as often as we’d like.

You only need to use the equations (eqrefkalpredictfull), (eqrefkalupdatefull), and (eqrefkalgainfull) from the math discussed above. (Alternatively, you could derive everything again using the equations (eqref)covident and (eqref)matrixupdate) if you forget those. ).

This will allow you to model any linear system accurately. We employ the extended Kalman filter for nonlinear systems, which simply linearizes the forecasts and measurements about their mean (I might write about the EKF again in the future.)

If I’ve done my job correctly, I hope that someone else will find these things to be cool and think of a novel application for them.

This excellent document, which employs a similar strategy involving overlapping Gaussians, deserves credit and a mention. More in-depth derivations can be found there, for the curious.

Why Use Kalman Filters? | Understanding Kalman Filters, Part 1

We lack a concept of division for matrices, which is why the equation for K is so complex despite being simple earlier in the formula. Because of this, we choose to first determine the total error and then multiply the error in our prediction by the inverse of total error.

Larry: That’s awesome; does that mean it’s some sort of astrologer? Me: Not quite. It is an iterative mathematical procedure that rapidly calculates the values of the object that we are interested in using a set of equations and successive data inputs. Basically it is all quick mathematics!.

In this last step, we update our x and P in accordance with the Kalman Gain’s calculations. Note: Since we are setting x and P for the following prediction step, we need to determine their values, so on the LHS, we have x and P rather than x′ and P′.

Larry: Tell me about the connection between a Gaussian and a Kalman filter. Me: Hmm, a Gaussian in a Kalman filter represents the predicted value with noise/error/uncertainty in our prediction, which is commonly referred to as the variance. The predicted value is centered on the mean, and the Gaussian’s width indicates how uncertain our value is. In essence, it conveys how confident we are that a particular value is accurate. More the width of the Gaussian denotes more uncertainty.

The value of the K ranges from 0 to 1. If our measurement error is significant, K will be closer to 0, which denotes that our predicted value and actual value are nearly identical. If our prediction error is significant, K will be closer to 1, indicating that our measured value is more accurate than our actual value.

The predicted value of X and the covariance matrix P could then be calculated using this information. Steps for updating: z = H * x + w, where w is the noise in the sensor measurements Therefore, the measurement function for lidar is as follows: z = p’It can also be represented as a matrix:

Since writing a Kalman filter is not the main focus at this time, I didn’t initially initialize the matrices. First, we should know how the two main function works. then come the initialization and other stuff. Some drawbacks :

A Kalman Filter is an optimal estimation algorithm. When we are uncertain about an object’s position due to various restrictions like accuracy or physical constraints, which we will discuss in a moment, it can help us predict or estimate the position of the object. Application of Kalman filter: Kalman filters are used when –.

The two main steps in the entire process are the update step and the prediction step, as we have previously discussed. In order to determine the precise position of the robot, these two steps are repeatedly looped. The formula for calculating the prediction step: New position p’ is p’ = p + v * dt, where p is the previous position, v is the velocity, and dt is the time-step. Assuming that the new velocity v’ is constant, the previous velocity will remain unchanged. To write this entire thing in a single matrix, enter this equation as v’ = v.

In this step, we update our estimate and our uncertainty using the most recent measurements. By comparing the measurement (z) with our prediction (H*x), H is the measurement function that maps the state to the measurement and aids in calculating the error (y). y= z – H*xThe error is projected into a matrix S by using the measurement function (H) and a matrix R that represents measurement noise to project the system uncertainty (P) into the measurement space. S = H * P * H. This is then translated into the variable K by adding transpose() and R. K, or the Kalman gain, determines whether the measurement taken or the prediction based on the prior data and its uncertainty should be given more weight. K = P*H. transpose() * S. Finally, we use this equation’s Kalman gain to update our estimate (x) and our uncertainty (P). P = (I – K * H) * PHere I is an identity matrix. x = x + (K * y)

You probably won’t get so lucky in a real interview situation if you only choose questions in the areas you are most comfortable with.

Congratulations on your interest in a position as a perception/sensor engineer! Below, you will find one general question and a list of questions that are specific to this position. You must answer the general question, three questions from the list of questions specific to each role, and mark at least one of the questions as requiring code with [Code] in order to complete the project. Although it is not necessary to use code in the other two, we strongly advise you to code, diagram, or illustrate any pertinent information for your answers in the other questions.

Finding lane lines, advanced lane finding, vehicle detection and tracking, extended Kalman filters, unscented Kalman filters, and perception-based deep learning projects are among the self-driving car engineer’s specialties.

Explain a recent project youve worked on. What challenges did you encounter on this project that you did not anticipate, and how did you overcome them?

If you list these on your resume, be sure to thoroughly research the subject and your code before the interview!

By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy.

FAQ

What is Kalman filter used for?

When the variables of interest cannot be measured directly but an indirect measurement is available, Kalman filters are used to estimate the variables as accurately as possible. Additionally, they are used to combine measurements from various sensors in the presence of noise to determine the best estimate of states.

What problem does a Kalman filter solve?

The Kalman filter minimizes the mean square error of the estimated parameters when all noise is Gaussian.

What are the types of Kalman filter?

Numerous Kalman filter types, including the extended Kalman filter (EKF), unscented Kalman filter (UKF), ensemble Kalman filter (EnKF), and constrained Kalman filter (CKF), are introduced in this chapter.

What filter is better than Kalman?

Non-gaussian noise problems can be solved using particle filters, but they typically require more computational power than Kalman filters. This is due to the fact that Particle Filters solve estimation problems using simulation techniques rather than analytical equations.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *