21  Particle Filters & Localization

In 60 Seconds

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

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.

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!

Why This Works for IoT:

  • Wi-Fi/BLE signals aren’t perfect circles (non-Gaussian)
  • Buildings have walls that block paths (non-linear constraints)
  • Multiple possible locations might match sensor readings initially

21.2 The Propagate-Correct-Resample Algorithm

Particle filter process diagram showing the four-step cycle: Sample (generate), Propagate (motion model), Weight (likelihood), and Resample (regenerate)

21.2.1 Step 1: Propagate (Prediction)

Move each particle according to the motion model, adding noise:

\[x_i^{k|k-1} = f(x_i^{k-1}, u_k) + w_k\]

Where:

  • \(f(\cdot)\): Motion model (position = position + velocity x dt)
  • \(u_k\): Control input (e.g., commanded velocity from IMU)
  • \(w_k\): Process noise (adds randomness)

Example: If a person walks 10 steps north, move each particle 10 steps north plus Gaussian noise (+/-0.5 meters) for GPS drift, variable stride, etc.

21.2.2 Step 2: Correct (Update Weights)

Weight each particle by how well it matches sensor observations:

\[w_i^k = w_i^{k-1} \cdot p(z_k | x_i^{k|k-1})\]

Where:

  • \(p(z_k | x_i)\): Likelihood of measurement given particle state
  • Particles matching measurements get high weights
  • Particles in impossible locations (walls) get zero weight

Example: If Wi-Fi AP “AP-FoodCourt” shows -65 dBm:

  • Particles 5m from AP (expected -65 dBm) get high weight
  • Particles 50m away (expected -85 dBm) get low weight
  • Particles inside concrete walls get zero weight

21.2.3 Step 3: Resample (Regenerate)

Create a new generation of particles by sampling with probability proportional to weights:

  • High-weight particles: Duplicated (likely locations get more samples)
  • Low-weight particles: Eliminated (unlikely locations discarded)
  • Result: Particles concentrate around high-probability regions

Resampling methods:

  • Multinomial resampling: Draw N particles randomly with replacement
  • Systematic resampling: Deterministic, lower variance (preferred)
  • Residual resampling: Guarantees high-weight particles survive

Why resample? Without resampling, all particles eventually get near-zero weights (degeneracy problem). Resampling maintains particle diversity.

21.3 When to Use Particle Filters

Particle Filter vs Kalman Filter
Challenge Kalman Filter Particle Filter
Non-linear motion Requires EKF/UKF Handles arbitrary non-linearity
Non-Gaussian noise Assumes Gaussian Works with any distribution
Multi-modal distributions Single peak only Multiple peaks naturally
Map constraints Difficult Particles outside walls = 0
Computational cost Low (matrix ops) Higher (scales with particle count)

When to use particle filters:

  • Indoor localization with Wi-Fi/BLE (signal propagation is non-linear)
  • Robot kidnapping problem (unknown initial position)
  • Tracking with ambiguous measurements (bearing-only tracking)
  • Systems with map constraints (buildings, road networks)

When to avoid:

  • Linear systems with Gaussian noise (Kalman is optimal and faster)
  • Real-time embedded systems with limited CPU
  • High-dimensional state spaces (curse of dimensionality)

21.4 Worked Example: Mall Navigation System

Scenario: Navigate a 3-floor shopping mall using smartphone Wi-Fi/BLE signals and IMU.

Setup:

  • State: [x position, y position, floor level, heading]
  • Sensors: 15 Wi-Fi access points, 3 BLE beacons per floor, IMU
  • Particle count: 1000 particles
  • Update rate: 1 Hz

Initial State (t=0):

  • User enters main entrance
  • 1000 particles uniformly distributed across all 3 floors
  • Each particle has weight = 1/1000

Step 1: User Walks 10 Steps North (t=1-10s):

Propagate: Move each particle 10 steps north (15m total)

  • Add Gaussian noise: sigma = 0.5m per step, sigma_total = sqrt(10) x 0.5 = 1.6m
  • Particles that moved into walls: weight = 0

Step 2: Receive Wi-Fi Measurements (t=10s):

  • “AP-Entrance”: -55 dBm (very strong, must be near entrance)
  • “AP-FoodCourt”: -75 dBm (moderate, probably 30-50m away)

Correct: Calculate weight for each particle based on expected vs observed RSSI:

For each particle i at position (x,y):
    expected_entrance = RSSI_model(distance(particle, entrance_AP))
    expected_foodcourt = RSSI_model(distance(particle, foodcourt_AP))
    likelihood = gaussian_pdf(observed_entrance - expected_entrance)
                 * gaussian_pdf(observed_foodcourt - expected_foodcourt)
    weight[i] = previous_weight[i] * likelihood

Particles near entrance (matching -55 dBm): weight increases 10x Particles near food court (wrong signal): weight decreases 100x

Step 3: Resample:

  • 800 particles now clustered near entrance on floor 1
  • 150 particles near escalator (alternative path)
  • 50 particles scattered (low weight, will likely be eliminated next round)

Convergence (t=60s):

After walking through store, taking elevator, hearing escalator sounds:

  • 95% of particles within 2m of true location
  • Floor correctly identified (100% confidence)
  • Heading accurate to +/-10 degrees

Particle filter evolution over time showing convergence from uniform spread at t=0 through weighted particles at t=1 to clustered particles at t=2 and converged estimate at t=3

21.5 Particle Filter Design Decisions

21.5.1 Number of Particles

Application Particles Accuracy CPU Memory
Simple 2D tracking 100-500 Good Low ~4KB
Indoor localization 500-2000 Very good Medium ~20KB
Multi-floor building 1000-5000 Excellent High ~100KB
Autonomous vehicle 5000-50000 Precise Very high ~1MB

Rule of thumb: Start with 500-1000 particles, increase if output is noisy or convergence is slow.

Explore how particle count, state dimensions, and processor speed affect memory usage and computation time for your particle filter design.

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)

See how particle weight concentration affects the effective sample size (\(N_{eff}\)). When one particle dominates, \(N_{eff}\) drops, signaling the need to resample.

21.5.3 Map Integration

Particle filters excel with map constraints:

  1. Wall collision detection: Set weight = 0 for particles inside walls
  2. Semantic constraints: Elevator particles can only move vertically
  3. Floor transitions: Only allow through stairs, elevators, escalators
  4. 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.

Common Pitfalls

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.

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.

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.

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

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
Concept Relationships

Builds On:

Enables:

Algorithms:

Applications:

Implementation:

Key Takeaway

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 Kalman Filter for IoT
Explore the complementary filter as a lightweight alternative Complementary Filter and IMU Fusion
See particle filters applied in localisation and tracking Data Fusion Applications
Understand fusion system architectures Data Fusion Architectures
Return to the module overview Data Fusion Introduction