Reference implementations
Example models
Four reference estimators — a coulomb counter, an EKF, a feedforward network and an LSTM — each as a MATLAB and a Python package. Read the schematic and the annotated source, download the package, or run it on a public drive cycle with one click to see what a result looks like.
Example 1 — coulomb counter
Coulomb counterComplexity 1 · TrivialIntegrate current, divide by capacity. Twenty lines, the best way to learn the interface.
The simplest possible estimator: charge in and out of the cell is counted by integrating current at the 1 Hz sample rate and dividing by a fixed nominal capacity. The previous SOC is carried between calls in z.
It assumes the battery always starts full, ignores temperature-dependent capacity, and has no way to correct itself — so any current-sensor offset accumulates without bound. That is exactly why the robustness test cases exist.
Coulomb counter
Open-loop current integration
Governing equation
C_n = 4.6 Ah, Δt = 1 s
State carried in z
Previous SOC only.
Uses
Where it shines
- Trivial to implement and verify
- Zero latency, negligible compute
- Exact if capacity, initial SOC and current are exact
Where it struggles
- Drifts with any current-sensor offset
- Fails the initial-SOC test outright (assumes 100 %)
- Ignores temperature-dependent usable capacity
1% SOC Estimation Example V22% Online Coulomb Counting SOC Estimator - McMaster University 20243function [Y_est, z] = Model(X, z)4% Input X: Measured current, voltage, and temperature values5% X: 3 columns, 1 row67% Current is negative-discharging, positive-charging8Current = X(1); % in [Amps]910% Voltage is unused in this Coulomb Counter11% Voltage = X(2); % in [Volts]1213% Temperature is unused in this Coulomb Counter14% Temperature = X(3); % in [Celsius]1516Capacity = 4.6; % in [Ah], nominal capacity of the cell1718% Coulomb Counting SOC Estimator: SOC = integral of current19if nargin == 1 % start of measurement (z = [])20SOC = 1; % assume battery always starts fully charged21z = SOC; % send back previous SOC as memory z22else23previous_SOC = z; % load z as previous SOC24SOC = previous_SOC + Current*(1/3600)/Capacity; % integrate current25z = SOC; % send back previous SOC as memory z26end2728% Output Y: Estimated SOC (1 row, 1 column)29Y_est = SOC';30end
See it evaluated
Queues a dry run of the shipped MATLAB package on one public cycle — the same check you get for your own model. Counts toward your 5 test runs per hour.
Adapting an example
- Keep the signature — MATLAB
[Y, z] = Model(X, z)with anargin < 2initialisation block, or Pythondef Model(X, z=None)returning(Y, z). - Put every parameter your model needs either inline or in a
.matloaded once at initialisation — never in the per-sample path. - Return SOC on 0–1 and store all memory in
z; the evaluator keeps nothing else between calls. - Use Test your package first on the Submit page, then submit.