Particle filters represent probability distributions using thousands of weighted hypotheses (“particles”), making them ideal for non-linear, non-Gaussian problems where Kalman filters fail. Through a propagate-correct-resample cycle, particles converge on the true state, naturally handling map constraints like walls and multi-modal ambiguity in indoor localization scenarios.
Learning Objectives
After completing this chapter, you will be able to:
Explain particle filter principles and distinguish scenarios where they outperform Kalman filters
Implement the propagate-correct-resample cycle for a 2D localization problem
Apply particle filters to indoor localization using Wi-Fi/BLE measurements
Evaluate the trade-offs between particle count, accuracy, and computational cost
Compare Kalman and particle filters and justify the appropriate choice for a given application
Interactive: Particle Filter Resampling Animation
Key Concepts
Particle filter (Sequential Monte Carlo): A non-parametric Bayesian estimation algorithm that represents the probability distribution of a state using a set of weighted random samples (particles) rather than a Gaussian approximation.
Particle: A single hypothesis about the current state of a system, with an associated weight reflecting how well it explains recent sensor observations.
Resampling: The process of eliminating low-weight particles and duplicating high-weight particles to prevent sample impoverishment, keeping the particle set focused on plausible state regions.
Importance sampling: The technique of drawing particles from a proposal distribution (often the prior) and weighting them by the likelihood of the observation, forming the basis of the particle filter update step.
Sample impoverishment: A particle filter failure mode where after many resampling steps all particles become identical, causing the filter to lose track of uncertainty in the state.
Non-parametric estimation: Estimation that does not assume a specific distribution shape (e.g., Gaussian) for the state, allowing particle filters to represent multi-modal and heavily skewed uncertainty distributions.
21.1 Introduction to Particle Filters
Particle filters are powerful tools for tracking and localization in non-linear, non-Gaussian environments. Unlike Kalman filters, which assume Gaussian noise and linear dynamics, particle filters can handle arbitrary probability distributions and complex constraints like walls and obstacles.
21.1.1 The Core Idea: A Swarm of Hypotheses
Instead of maintaining a single estimate (like Kalman filters), particle filters represent the probability distribution using a “swarm” of particles – each particle is a hypothesis about the true state.
For Beginners: Understanding Particle Filters
Imagine you’re blindfolded in a shopping mall trying to figure out where you are:
The Swarm Approach: Your brain generates 1000 guesses (particles) about your location, scattered across the entire floor plan.
Step 1 - Move (Propagate): You walk 10 steps forward. Each of your 1000 hypothetical locations also “walks” 10 steps. Some guesses might now be inside walls (impossible).
Step 2 - Listen (Correct): You hear a fountain. Hypotheses near the fountain get “rewarded” (high weight), while hypotheses far from water get “penalized” (low weight).
Step 3 - Regenerate (Resample): You create 1000 new hypotheses, favoring the high-weight ones. Your swarm concentrates near likely locations.
After 30 seconds of walking: 95% of your particles cluster within 2 meters of your true location!
How many particles do you really need? Particle count trades accuracy vs computational cost.
For a 2D position problem (x, y) in a 50m × 50m area: - Uniform grid with 1m resolution: \(50 \times 50 = 2500\) cells - Coverage rule: Need ~10 particles per likely cell for good PDF approximation - If position uncertainty is 10m × 10m (100 cells), need \(100 \times 10 = 1000\) particles minimum
Computational cost (per update cycle):
500 particles: ~4ms on ESP32 (240 MHz)
2000 particles: ~16ms on ESP32
10000 particles: ~80ms on ESP32
For 10 Hz real-time: Max 100ms per cycle → Max ~12,000 particles on ESP32. For higher rates, reduce particle count or use fewer state variables.
Diminishing returns: Going from 500→1000 particles cuts error by ~30%. Going from 1000→2000 cuts error by only ~15%. Above 2000, gains are marginal unless tracking high-dimensional state.
21.5.2 Resampling Strategies
Low Variance Resampling (recommended):
Deterministic selection with single random offset
Lower variance than multinomial
Guarantees representative sample
Effective Sample Size:
\[N_{eff} = \frac{1}{\sum_i (w_i)^2}\]
Resample when \(N_{eff} < N/2\) (too many low-weight particles)
Interactive: Effective Sample Size Explorer
See how particle weight concentration affects the effective sample size (\(N_{eff}\)). When one particle dominates, \(N_{eff}\) drops, signaling the need to resample.
Wall collision detection: Set weight = 0 for particles inside walls
Semantic constraints: Elevator particles can only move vertically
Floor transitions: Only allow through stairs, elevators, escalators
Occupancy grids: Precompute traversable areas
21.6 Comparison with Other Filters
Filter
Linearity
Noise
Modality
Computation
Best For
Kalman
Linear
Gaussian
Unimodal
O(n^3)
GPS tracking
EKF
Weakly nonlinear
Gaussian
Unimodal
O(n^3)
GPS-IMU fusion
Particle
Any
Any
Any
O(N particles)
Indoor localization
21.6.1 Real-World Deployment Trade-offs
Choosing between these filters in production is rarely a pure accuracy decision. Compute budget, power consumption, and implementation complexity dominate the choice.
Case Study: Apple AirTag vs Tile Tracker localization
Apple AirTag uses a particle filter approach for its Find My network localization. When an AirTag is “lost,” every passing iPhone acts as a measurement source, reporting BLE RSSI. The cloud-side particle filter fuses these intermittent, asynchronous measurements from thousands of anonymous iPhones to estimate the AirTag’s position. A Kalman filter would fail here because: (1) measurements arrive at unpredictable intervals from random directions (non-uniform noise), (2) the AirTag could be in a pocket, a car, or outdoors (multi-modal signal propagation), and (3) urban environments create multipath reflections that violate Gaussian assumptions.
Tile, by contrast, uses a simpler trilateration approach with fewer participating devices. The accuracy difference (AirTag: ~3m median in urban areas vs Tile: ~15m) is largely attributable to Apple’s particle filter approach leveraging a billion-device measurement network.
Embedded constraint example: A Nordic nRF52840 MCU (256 KB RAM, 64 MHz Cortex-M4) can run a 500-particle filter for 2D indoor localization in approximately 8ms per update cycle. This consumes roughly 40 KB of RAM (500 particles x 4 state variables x 4 bytes x 5 for overhead). Increasing to 2,000 particles pushes computation to 35ms and memory to 160 KB – still feasible but leaving limited headroom for the BLE stack. On an ESP32 with 520 KB RAM and dual cores, 5,000 particles are practical, with one core dedicated to the filter and the other handling communications.
Interactive Quiz: Match Concepts
Interactive Quiz: Sequence the Steps
Common Pitfalls
1. Using too few particles for the problem dimensionality
A particle filter for a 2D indoor positioning problem may work well with 1,000 particles but require 100,000 particles in a 3D problem with non-linear sensor models. The required particle count scales exponentially with state space dimensionality — this ‘curse of dimensionality’ limits particle filters to moderate state dimensions.
2. Not implementing systematic resampling
Naive multinomial resampling produces higher variance than systematic resampling and can cause particle impoverishment faster. Use systematic or stratified resampling to maintain particle diversity more efficiently.
3. Running the particle filter at full update rate on resource-constrained devices
A particle filter with 1,000 particles running at 100 Hz on a microcontroller will exceed available CPU capacity. Use the particle filter at fog/cloud tier and deploy a lightweight prediction-only filter at the edge for real-time state estimates between full filter updates.
Label the Diagram
Code Challenge
21.7 Summary
Particle filters provide flexible state estimation for complex IoT scenarios:
Swarm of hypotheses: Represent uncertainty with many particles
Propagate-Correct-Resample: The fundamental algorithm cycle
Map constraints: Natural handling of walls and obstacles
Multi-modal: Can track multiple possible locations simultaneously
Trade-off: More computation than Kalman, but handles non-linearity
Quiz: Particle Filters
For Kids: Meet the Sensor Squad!
Particle filters are like sending out a thousand tiny explorers to find where you really are!
21.7.1 The Sensor Squad Adventure: The Lost Toy Hunt
Oh no! Bella the Battery lost her favorite toy somewhere in the Smart School! The school was BIG – three floors with hallways, classrooms, and a cafeteria. How could the Sensor Squad find it?
Max the Microcontroller had a brilliant idea: “Let us send out 1000 imaginary mini-scouts to search!”
Step 1 – Scatter the Scouts: Max scattered 1000 tiny imaginary scouts ALL over the school – in every hallway, every classroom, every floor. Each scout was a GUESS about where the toy might be.
Step 2 – Move the Scouts: Bella remembered, “I walked about 20 steps north after lunch.” So Max told all 1000 scouts: “Move 20 steps north!” But some scouts bumped into WALLS. “If you are inside a wall, you are in an impossible place – you are OUT!” said Max. 200 scouts disappeared.
Step 3 – Listen for Clues: Sammy the Sensor detected the toy’s Bluetooth signal. “It is a STRONG signal, so the toy must be nearby!” Scouts that were close to where the signal was strongest got GOLD STARS (high weight). Scouts far away got no stars.
Step 4 – Pick the Winners: Lila the LED helped with the next step: “Scouts with lots of gold stars get to CLONE themselves. Scouts with no stars are removed.” Now most of the 1000 scouts were clustered near the cafeteria on the 2nd floor!
After three more rounds of clues, 950 scouts were in the SAME corner of the cafeteria. “The toy must be THERE!” cheered Bella. And it was – sitting on a lunch tray!
“Each scout was a particle, and together they found the answer!” explained Max. “Even though no single scout knew where the toy was, the SWARM figured it out!”
21.7.2 Key Words for Kids
Word
What It Means
Particle
A tiny guess about where something might be
Propagate
Moving all the guesses based on what you know happened
Resample
Making copies of good guesses and removing bad ones
Converge
When all the guesses cluster together near the right answer
Multi-modal
When the answer could be in two or more different places at once
Use particle filters when your problem has non-linear dynamics (walls, obstacles), non-Gaussian noise (Wi-Fi signals), or multi-modal distributions (could be on any floor). Start with 500-1000 particles and use systematic resampling triggered by effective sample size. For linear Gaussian problems, prefer Kalman filters for their lower computational cost and optimality guarantees.
21.8 What’s Next
If you want to…
Read this
Compare with the Kalman filter for linear problems