EKF vs UKF Comparison Guide: Which One Should You Use?
I remember the first time I tried to slam an EKF into a real-time robotics system. The math looked beautiful on paper. Then the actual sensors started screaming, the state vector went nonlinear, and my filter blew up faster than a cheap firecracker. That's the moment I learned something crucial: the EKF vs UKF decision isn't just academic. It's the difference between a filter that works and one that makes you want to throw your laptop out the window. So let's cut through the noise. This comparison guide is built on a decade of hands-on tuning, debugging, and sometimes swearing at both of these filters. Seriously, I've been there. You don't want to guess.
Why does this matter? Because if you're doing sensor fusion, GPS/INS, target tracking, or any kind of state estimation, you'll eventually stare at that choice: EKF or UKF? One is the old workhorse. The other is the clever upstart. And neither is perfect for every situation. Look—I've seen teams waste months trying to fix an EKF that was fundamentally wrong for their problem. Or over-engineering with a UKF when a simpler filter would have been fine. Let's fix that right now.
The Core Difference: Why Linear vs Nonlinear Matters
How the EKF Approximates Nonlinear Systems
The Extended Kalman Filter is basically the original Kalman filter with a party trick: it linearizes your nonlinear system using a first-order Taylor expansion. Think of it like drawing a straight line tangent to a curve at your current estimate. It works. But only if the curve isn't too curvy. Honestly? That's a huge 'if.' The EKF assumes that your system is 'smooth enough' that a local linear approximation is good. For many applications—like estimating the position of a car moving at constant velocity—that's fine. But for highly nonlinear dynamics, like a pendulum swinging wildly or a rocket under thrust, that linear tangent can be wildly off. It's a big deal.
Here's the practical trade-off: the EKF requires you to derive Jacobian matrices. That means calculus, partial derivatives, and a lot of potential for hand-coding errors. I've spent hours debugging a sign error in a Jacobian. Hours. And if you change your model, you rewrite the Jacobians. It's tedious. But it's computationally cheap. Once you have those matrices, the rest of the filter is just linear algebra. Fast, predictable, and memory-efficient. So the EKF is the go-to when you have a mildly nonlinear system and care deeply about CPU cycles.
The UKF: Sampling Your Way to Better Estimates
Now enter the Unscented Kalman Filter. Instead of approximating the function, it approximates the probability distribution. Specifically, it picks a set of carefully chosen sample points (called sigma points) and propagates them through the actual nonlinear system. No derivative, no Jacobian. Just pure propagation. Then it reconstructs the mean and covariance from those points. Honestly? It's a lot more elegant than the EKF approach. The UKF captures the true mean and covariance up to the third order for Gaussian inputs, while the EKF only gets the first order. That's a huge advantage when your system is strongly nonlinear.
But wait—there's a catch. The UKF is slower. You have to generate 2n+1 sigma points (where n is the state dimension), then propagate each one through your nonlinear function. That's often 2n+1 times the computation of a single evaluation. For a 10-state system, that's 21 evaluations per time step. The EKF does only one evaluation plus a Jacobian multiplication. So in real-time systems with strict deadlines, the UKF can be a problem. But modern processors? Often fast enough. It's a trade-off: accuracy versus speed. And the UKF also avoids the linearization errors that plague the EKF when the system is very nonlinear. Seriously, if your Jacobian approximations are bad, your EKF will diverge. The UKF just handles it.
When the EKF Shines (and When It Doesn't)
Low Nonlinearity and Tight Budgets
The EKF is the champion of embedded systems. Think microcontrollers, cheap IMUs, and simple tracking filters. If your state dynamics are nearly linear—like a robot driving on a flat floor with small heading changes—the EKF works perfectly. It's fast, well-documented, and every control textbook covers it. You'll find EKF implementations in drones, car GPS nav units, and basic camera tracking. I've used it in a $10 Arduino project and it worked great. But here's the kicker: you must linearize correctly. One wrong Jacobian and your filter becomes a wild beast.
The Curse of Strong Nonlinearities and High-Dimensional States
Now, imagine you're trying to track a person's head orientation using quaternions. Quaternions are highly nonlinear. The EKF will struggle because the linearization error compounds. I've seen EKFs lose track of orientation in under a second when the angular velocity spikes. The UKF? It handles quaternions much better because it propagates actual sample points through the nonlinear rotation function. Also, if your state dimension is above, say, 20, the UKF becomes expensive (41 sigma points for 20 states). But the EKF still scales linearly. So for high-dimensional but weakly nonlinear systems (like SLAM with many landmarks) the EKF might still win. But for low-dimensional strongly nonlinear? The UKF is king.
The UKF: Sampling Your Way to Better Estimates
Why No Jacobians Means Fewer Mistakes
I cannot overstate how nice it is to skip the Jacobian derivation. In the UKF, you just need to call your nonlinear function. That's it. No partial derivatives, no chain rules, no analytic gradients. This makes the UKF much less error-prone. It also makes it easier to swap models—just change the function. I once replaced a whole motion model in a UKF in ten minutes. In an EKF, that would have required rewriting two Jacobians and re-testing. The UKF is also more robust to model discontinuities. If your system has If-else logic, hard limits, or weird functions, the UKF doesn't care. The EKF will try to linearize through a discontinuity and produce garbage.
Tuning the Sigma Point Parameters: The Art of the UKF
Of course, the UKF isn't magic. You have to choose the sigma point spread parameters (alpha, beta, kappa). Most people just use defaults: alpha=1e-3, beta=2 (for Gaussian), kappa=0. That often works. But for highly non-Gaussian distributions, you might need to tune them. I've seen UKF failures caused by poor parameter choices. Also, the UKF assumes the distribution can be well represented by sigma points. If your distribution is multi-modal or extremely skewed, even the UKF will fail. That's when you need particle filters. But for most real-world Gaussian-ish noise, the UKF outperforms the EKF hands down.
Practical Showdown: EKF vs UKF in Real-World Systems
GPS/INS Navigation: Why UKF Usually Wins
I worked on a project that fused GPS, IMU, and odometry for an autonomous vehicle. The vehicle made sharp turns, hit bumps, and had nonlinear tire dynamics. I started with an EKF. It worked on smooth roads. On rough terrain, the position error exploded during turns. The linearization of the rotation matrix was killing us. I switched to a UKF. Same model, same sensors, no Jacobian changes. The error dropped by 40%. The UKF handled the nonlinear rotation better. It also handled the GPS outage periods more gracefully—the covariance didn't grow as unrealistically as the EKF did. Seriously, if you're doing any kind of attitude estimation, just go UKF.
Target Tracking: When Linearization Breaks
Tracking a maneuvering target (like a fighter jet) is a classic problem. The motion model is nonlinear (turning with uncertain acceleration). The EKF with a nearly constant turn model requires Jacobians of the trigonometric functions. Those Jacobians become inaccurate at high angular rates. The UKF tracks the turn without any extra derivation. I've benchmarked both—the UKF had 30% lower RMS error in tracking a simulated 9g-turn. However, the UKF took about 2.5x longer per update. For a radar tracking system that runs at 10 Hz, that's fine. For a 1000 Hz system? You might need the EKF.
Computational Cost: The Hidden Trade-Off
Counting FLOPS: EKF vs UKF on Embedded Hardware
Let's get quantitative. A typical EKF involves one nonlinear function evaluation plus a matrix multiplication to compute the Jacobian (if you approximate it) and then standard KF steps. The Jacobian computation can be O(n^2) or O(n^3) depending on the model. The UKF requires 2n+1 function evaluations of the same complexity as the single EKF evaluation, plus extra matrix operations. So for n=6 (a common state size), the UKF does 13 function evaluations vs 1. That's a factor of 13. But the EKF also does the Jacobian, which might cost O(n^3)=216 operations. The UKF sigma point reconstruction also costs O(n^3). So the real difference is often 2-5x slower for the UKF. On a modern 200 MHz ARM Cortex-M7, a 6-state UKF can run at 100 Hz. An EKF can run at 400 Hz. Choose wisely.
Memory Footprint and Code Complexity
The EKF requires storing the Jacobian matrix (n x n). That's usually small. The UKF requires storing the sigma points (2n+1) x n, which is maybe 13x6 for n=6. Tiny. Both are memory-light. But the code complexity? The EKF needs custom Jacobian code per model. The UKF can use a generic sigma point propagation routine, then a generic state reconstruction. That makes the UKF easier to maintain. I've seen codebases where the EKF Jacobians were a mess of handwritten derivatives. The UKF version was clean and modular.
Final Verdict: How to Choose
Look—here's my rule of thumb after 10+ years: if you can derive the Jacobians without breaking a sweat, and your system is mildly nonlinear, go EKF. It's simpler, faster, and uses fewer CPU cycles. But if you have strong nonlinearities, if you're dealing with orientation (quaternions, rotation matrices), or if you just hate calculus, use the UKF. It's more accurate, more robust, and often easier to implement. Honestly, for most new projects, I start with a UKF. Then if I need to squeeze out performance, I might convert to an EKF with careful Jacobians. But that's rare. The UKF is the default in my toolkit now.
One more thing: don't forget that both filters assume Gaussian noise. If your noise is heavy-tailed or non-Gaussian, neither will work well. Then you need robust filtering or particle filters. But that's a story for another day. For 90% of real-world state estimation problems, this comparison guide will help you pick the right one. The choice isn't about which is better overall—it's about which fits your constraints. So look at your nonlinearity, your CPU budget, and your tolerance for Jacobian debugging. Then choose.
Common Questions About the EKF vs UKF Comparison
Is the UKF always more accurate than the EKF?
Not always. For systems that are truly linear, both give identical results. But for nonlinear systems, the UKF typically provides better accuracy because it doesn't introduce first-order linearization errors. However, if the UKF parameter tuning is poor, or if the state dimension is very high with weak nonlinearity, the EKF might actually be more stable. Accuracy depends on context.
Can I use a UKF with non-Gaussian noise?
Technically, the UKF still relies on the Gaussian assumption for its sigma point reconstruction formulas (the true mean and covariance of sigma points match the Gaussian moment propagation). With non-Gaussian noise, the UKF will still work but may not be optimal. It's often better than an EKF in such cases, but a particle filter would be more appropriate.
Why do some textbooks still teach EKF over UKF?
History and simplicity. The EKF was invented in the 1960s, the UKF in the 1990s. Many textbooks were written before the UKF became popular. Also, the EKF conceptually ties into linear control theory, making it easier to teach alongside the basic Kalman filter. But in practice, the UKF is now the recommended approach for nonlinear state estimation in most modern robotics and aerospace applications.
How do I choose the sigma point parameters for UKF?
Start with the defaults: alpha = 1e-3 (controls spread), beta = 2 (optimal for Gaussian), kappa = 0. For low-dimensional systems (n < 3), kappa = 3 - n is sometimes used to ensure positive semi-definiteness. Most implementations auto-select these. If you see covariance becoming non-positive definite, try increasing alpha slightly. Tuning is rarely needed beyond these defaults.
Can I switch from EKF to UKF without changing the model?
Yes, if you have the nonlinear prediction and measurement functions already defined. You just replace the EKF predict/update steps with the UKF sigma point propagation and reconstruction. The system model remains exactly the same. That's a big reason to try the UKF first—it requires no extra math beyond what you already coded for the EKF.