Battery SOC EKF
AdvancedThe BatterySocEkf block implements an Extended Kalman Filter (EKF) to estimate the State of Charge (SOC) of a battery cell from terminal voltage and load current measurements. Using an equivalent circuit model with one or two RC polarisation branches, it corrects for coulomb-counting integration drift and polarisation voltage lag while estimating current sensor bias and confidence bounds ().
Open-circuit voltage (OCV) characteristics are configured in an Excel-style 2-column spreadsheet editor (SOC (0–1) and OCV (V)) with a live OCV curve preview (OCV = f(SOC)), evaluated via linear interpolation or monotonic cubic Hermite splines (smooth). Measured cell datasheet curves can be imported/exported via CSV or pasted directly from Excel (Ctrl+V). All 21 parameters are organized into four logical sections: _Initial State & Timing_, _Noise Covariances (Q & R)_, _Equivalent-Circuit Cell Model_, and _OCV Lookup Table & Solver_.
Mathematical Model
The continuous state dynamics and terminal voltage measurement equation are:
State covariance extrapolation and iterated measurement correction follow discrete Kalman recursions:
Inputs & Outputs
| Direction | ID | Label | Type | Status |
|---|---|---|---|---|
| → In | in1 |
I | number | Required |
| → In | in2 |
V | number | Required |
| → In | in3 |
Reset | number | Optional |
| → In | in4 |
Dropout | number | Optional |
| ← Out | soc_hat |
SOC | number | Output |
| ← Out | soc_sigma |
σ SOC | number | Output |
| ← Out | v1_hat |
V₁ | number | Output |
| ← Out | v2_hat |
V₂ | number | Output |
| ← Out | bias_hat |
I bias | number | Output |
| ← Out | voc_hat |
OCV | number | Output |
| ← Out | jacobian |
dOCV/dSOC | number | Output |
| ← Out | k_gain_0 |
K_SOC | number | Output |
| ← Out | innovation |
Innov. | number | Output |
| ← Out | innovation_cov |
S | number | Output |
| ← Out | nis |
NIS | number | Output |
Parameters
| Parameters | Label | Type | Default | Description |
|---|---|---|---|---|
sampleTime |
Sample Time | number | 1 |
Filter period in seconds |
socInit |
Initial SOC Estimate | number | 0.5 |
Fraction 0…1 |
v1Init |
Initial V1 Estimate | number | 0 |
|
pSoc |
Initial SOC Variance | number | 0.01 |
How unsure the initial SOC is; 0.01 is σ = 10 % SOC |
pV1 |
Initial RC Voltage Variance | number | 0.000001 |
Per RC branch; small, since a rested cell has V1 ≈ V2 ≈ 0 |
pBias |
Initial Bias Variance | number | 0 |
How unsure the current sensor's offset is; 0 leaves the offset out of the model, 0.01 is σ = 0.1 A |
qSoc |
Process Noise SOC | number | 1e-8 |
Noise density per second, so the filter does not change with the sample time |
qV1 |
Process Noise RC Voltage | number | 0.000001 |
Noise density per second, per RC branch |
qBias |
Process Noise Bias | number | 0 |
How fast the sensor offset may drift, as a density per second; 0 for a constant offset |
rMeas |
Measurement Noise | number | 0.0001 |
Variance of the voltage measurement in V² |
r0 |
R0 (Ω) | number | 0.05 |
Ohmic resistance |
r1 |
R1 (Ω) | number | 0.02 |
Polarisation resistance of the fast branch |
c1 |
C1 (F) | number | 1000 |
Polarisation capacitance of the fast branch |
r2 |
R2 (Ω) | number | 0 |
Resistance of a second, slow RC branch; 0 leaves the branch out |
c2 |
C2 (F) | number | 30000 |
Capacitance of the second RC branch |
capacity |
Capacity (Ah) | number | 3.2 |
|
chargeEfficiency |
Charge Efficiency | number | 1 |
Coulombic efficiency while charging (current < 0); Li-ion cells are typically 0.99–0.999 |
ocvSoc |
OCV Table SOC | table | 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 |
SOC breakpoints, ascending |
ocvVoltage |
OCV Table Voltage | text | 3.00 3.50 3.65 3.72 3.78 3.84 3.90 3.97 4.05 4.14 4.20 |
Open-circuit voltage at each breakpoint in V |
ocvInterpolation |
OCV Interpolation | select | linear |
Linear matches a LookupTable exactly; Smooth (monotone cubic) has no slope jumps at the breakpoints, which steadies the filter's gain |
iterations |
Update Iterations | number | 1 |
1 is the classic EKF; 3 relinearises at the corrected estimate (iterated EKF), which helps where the OCV curve bends sharply |
Usage Examples
Example 1: Resting Cell SOC Initialization
A rested lithium cell at 3.72 V is initialized with an uncertain guess (). As terminal voltage measurements arrive, the EKF converges to the true 30% SOC within 1.5 s, reducing from 10% to under 1%.
Example 2: Dynamic Drive Cycle with Current Sensor Bias
During pulsed electric vehicle discharge cycles, the filter estimates both cell state of charge and a 150 mA DC offset on the current sensor, preventing long-term integration drift.
Remarks & Best Practices
- Interactive OCV Spreadsheet & CSV Import/Export: Use 📂 Import CSV, 💾 Export CSV (
battery_ocv.csv), or direct clipboard paste (Ctrl+Vfrom Excel) to load empirical OCV–SOC characterization tables and inspect the liveOCV = f(SOC)curve immediately. - Uncertainty bounds: The
soc_sigmaoutput provides real-time estimation error bounds, allowing battery management systems to compute 95% confidence intervals (). - Consistency monitoring: The normalized innovation squared (NIS) diagnostic tracks filter health, averaging 1.0 when noise covariance matrices and match true operating conditions.
- Sensor dropout resilience: Setting the optional
Dropoutinput high pauses measurement updates, seamlessly falling back to coulomb counting while propagating covariance growth. - Nonlinear robustness: Using smooth cubic interpolation and multiple update iterations prevents divergent covariance jumps in regions where the OCV curve exhibits steep gradients.
Frequently Asked Questions (FAQ)
Q: Why is an Extended Kalman Filter (EKF) superior to Coulomb counting for battery SOC?
Pure Coulomb counting () irreversibly drifts due to current sensor offsets and unmodeled parasitic reactions. An EKF pairs the Coulomb counting integrator with an Equivalent Circuit Model (ECM, ) and corrects the state estimate at each step using the nonlinear open-circuit voltage relationship . This bounds SOC estimation error within across temperature shifts and aging.
Related Components
- KalmanFilter: Linear Kalman filter for multi-state estimation of linear dynamic systems.
- LookupTable: One-dimensional piecewise linear table lookup for static nonlinearities.
- RandomNumber: Gaussian noise source for simulating voltage and current sensor noise.