Battery SOC EKF
AdvancedBatterySocEkf 模块利用电池管理系统(BMS)中实际测得的电芯电流和端电压两条遥测信号,高精度在线估计电池的荷电状态(State of Charge, SOC)。算法基于含单阶或二阶 RC 环节的等效电路模型运行扩展卡尔曼滤波(EKF)。利用端电压测量校正纯安时积分(库仑计数)的累积漂移,并利用 RC 动力学模型补偿电芯极化电压带来的滞后。
此外,该模块支持在线辨识电流传感器的静态零偏(Offset/Bias)——这是造成安时积分发散的根本原因。模块可输出自身估计标准差(σ),便于 BMS 以置信区间形式(如 SOC ± 2%)输出可靠状态。
开路电压曲线(Open Circuit Voltage, OCV)以表格形式配置,支持分段线性插值(linear)或单调保形三次样条插值(smooth)。滤波器在每个采样周期基于当前状态估计重新对 OCV 曲线进行局部线性化展开,从原理上消除固定工作点线性化带来的系统偏差。
数学模型
其中:
I_m为测量电流(放电为正,单位:A),V为端电压(单位:V)。Q为电芯额定容量(单位:Ah),η为充电库仑效率。- 连续时间方程基于 Van Loan 矩阵积分方法在步长变化时自动保持严格物理等价。
H为当前预测 SOC 处的 OCV 曲线局部一阶导数。- 当 且关闭零偏估计时,自动退化为经典的二状态 EKF。
- 迭代次数为 1 时等价于标准 EKF,大于 1 时开启迭代扩展卡尔曼滤波(IEKF)。
输入与输出
| Direction | ID | Label | 类型 | 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 |
参数
| 参数 | Label | 类型 | 默认值 | 描述 |
|---|---|---|---|---|
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 | text | 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 |
使用示例
静置电芯的 SOC 快速锁定
静置于 3.72 V(真实 SOC 30%)的电芯通过带噪声电压传感器()在 10 Hz 下采集。滤波器自 60% 错误初始值启动,在 1.5 秒内收敛至真实值 2% 以内。
消除电流传感器漂移
0.2 A 的恒定电流偏置会导致传统安时积分发生线性偏离。BatterySocEkf 通过比对电压变化轨迹自动估计偏差量 b,使 SOC 持续稳定。
说明与最佳实践
- SOC σ 输出:在模型合理时,
SOC ± 2σ构成 95% 置信区间。NIS 统计量可在线验证噪声矩阵是否恰当。 - Valid 输入:电压采样丢失时,算法平滑过渡为纯安时推算,并递增不确定度输出直至信号恢复。
- 双 RC 模型:在剧烈脉冲工况下能有效解耦电化学双电层快速反应与固相锂扩散过程。
- Reset 重置:输入脉冲大于 0 时,重置内部状态与协方差矩阵至初值。
相关模块
- KalmanFilter" class="bw-link">KalmanFilter
- LookupTable" class="bw-link">LookupTable
- RandomNumber" class="bw-link">RandomNumber