Understanding the Particle Filter for SoC Estimation
This interactive visualization demonstrates how a Particle Filter can be used to estimate the State of Charge (SoC) of a battery.
Unlike simpler methods, a Particle Filter is a non-parametric approach that can handle non-linear system dynamics and non-Gaussian noise,
making it suitable for complex battery models.
The core idea is to represent the probability distribution of the battery's SoC using a set of weighted "particles". Each particle
represents a possible state (SoC value) of the battery. The weight of a particle indicates how likely that state is.
The Particle Filter operates in a cycle of three main steps:
-
Prediction (or Propagation): Based on the known input (the applied current) and a model of the battery's dynamics,
each particle's SoC is updated to predict its state at the next time step. Process noise is added to these predictions to account for
uncertainties in the model and unmodeled disturbances.
The general prediction step can be represented as:
\[x_t^i = f(x_{t-1}^i, u_t) + v_t\]
In this battery SoC example, the prediction for each particle's SoC (\(SoC_t^i\)) is based on the previous SoC (\(SoC_{t-1}^i\)), the applied current (\(I_t\)), and the battery capacity (\(C_{batt}\)), with added process noise (\(v_t\)):
\[SoC_t^i = SoC_{t-1}^i - \frac{I_t \cdot \Delta t}{C_{batt}} + v_t\]
where \(\Delta t\) is the time step.
-
Update (or Weighting): A measurement (the battery voltage, \(z_t\)) is received. For each particle, the likelihood of
observing this measurement, given the particle's predicted SoC and a model of the measurement noise, is calculated. The particle's
weight (\(w_t^i\)) is then updated proportionally to this likelihood. Particles whose predicted SoC is consistent with the measurement will
have higher weights.
The weight update is given by:
\[w_t^i = w_{t-1}^i \cdot p(z_t | x_t^i)\]
The likelihood \(p(z_t | x_t^i)\) is typically calculated using a probability density function (PDF) of the measurement noise. Assuming Gaussian measurement noise with standard deviation \(\sigma_m\), the likelihood is:
\[p(z_t | x_t^i) = \frac{1}{\sqrt{2\pi\sigma_m^2}} \exp\left(-\frac{(z_t - h(x_t^i, u_t))^2}{2\sigma_m^2}\right)\]
where \(h(x_t^i, u_t)\) is the expected voltage calculated from the particle's SoC (\(x_t^i\)) and the applied current (\(u_t\)), considering the internal resistance.
-
Resampling: A new set of particles is generated by sampling from the current set with replacement, based on their weights.
Particles with higher weights are more likely to be selected, while particles with very low weights are likely to be discarded. This step
focuses the particles on the more probable regions of the state space and prevents the degeneracy problem (where most particles have negligible weights).
The resampling step effectively replaces particles with low weights with duplicates of particles with high weights. The probability of selecting a particle \(i\) is proportional to its weight \(w_t^i\). After resampling, the new set of particles \(\{\tilde{x}_t^j\}_{j=1}^N\) is obtained, and their weights are typically reset to \(1/N\).
After resampling, the estimated SoC is typically calculated as the weighted average of the particles' SoC values (or simply the average if resampling
assigns equal weights). The process then repeats for the next time step.
Using the Visualization:
- Run Continuous: Starts the simulation, running the full Predict-Update-Resample cycle at each time step.
- Pause/Resume: Pauses or resumes the continuous simulation.
- Reset: Resets the simulation to the initial state (100% SoC, particles initialized around 80-100%).
- Step Mode: Switches to step-by-step execution, enabling the individual step buttons.
- Step Predict: Executes only the Prediction step.
- Step Update: Executes only the Update step (requires a preceding Predict step).
- Step Resample: Executes only the Resampling step (requires a preceding Update step).
- Step Full Cycle: Executes the full Predict-Update-Resample cycle once.
- Sliders: Adjust parameters like the number of particles, noise levels, applied current, battery capacity, and internal resistance. Changing 'Number of Particles' or 'Nominal Capacity' requires a simulation reset.
Observe how the distribution of particles (shown in the histogram) changes with each step and how the estimated SoC (red line in the time series plot)
tracks the true SoC (blue line), especially in the presence of measurement noise (green line in the voltage plot).