ƒ

Battery SOC EKF

Advanced
运行在线示例 免费 · 无需注册 · 直接在浏览器中运行

BatterySocEkf 模块实现扩展卡尔曼滤波(EKF),用于通过电池端电压与负载电流测量实时在线估计电池单体的荷电状态(SOC)。基于包含一阶或二阶 RC 极化环节的等效电路模型,该模块有效修正了纯安时积分法的累积漂移和极化动态滞后,并能在线估计电流传感器零点漂移(Bias)与统计置信区间(±2σ\pm 2\sigma)。

开路电压(OCV)特性在类 Excel 双列电子表格编辑器(SOC (0–1) 与 OCV (V))中配置,配备实时 OCV 曲线预览(OCV = f(SOC)),支持分段线性插值或单调三次 Hermite 样条插值(smooth)。实测电池数据可通过 CSV 导入 / 导出(battery_ocv.csv) 或直接从 Excel 粘贴(Ctrl+V)。全部 21 个参数清晰划分为四个逻辑部分:_初始状态与时序_、_噪声协方差 (Q & R)_、_等效电路模型_ 以及 _OCV 查表与求解器_。

数学模型

x=[SOC, V1, V2, b]T,I=Im−b\mathbf{x} = [\text{SOC},\ V_1,\ V_2,\ b]^T, \quad I = I_m - b

连续状态动态方程与端电压输出方程为:

SOC˙=−η I3600 Q,V˙j=−VjRjCj+ICj,b˙=0\dot{\text{SOC}} = -\frac{\eta\, I}{3600\,Q}, \quad \dot{V}_j = -\frac{V_j}{R_j C_j} + \frac{I}{C_j}, \quad \dot{b} = 0
Vterm=OCV(SOC)−V1−V2−R0I,H=[∂ OCV∂ SOC, −1, −1, R0]V_{\text{term}} = \text{OCV}(\text{SOC}) - V_1 - V_2 - R_0 I, \quad \mathbf{H} = \left[\frac{\partial\,\text{OCV}}{\partial\,\text{SOC}},\ -1,\ -1,\ R_0\right]

状态协方差外推与迭代测量校正遵循离散卡尔曼递推公式:

x^k∣k=x^k∣k−1+Kk(Vmeas−h(x^k∣k−1)),Kk=Pk∣k−1HkT(HkPk∣k−1HkT+R)−1\hat{\mathbf{x}}_{k|k} = \hat{\mathbf{x}}_{k|k-1} + \mathbf{K}_k \left(V_{\text{meas}} - h(\hat{\mathbf{x}}_{k|k-1})\right), \quad \mathbf{K}_k = \mathbf{P}_{k|k-1} \mathbf{H}_k^T (\mathbf{H}_k \mathbf{P}_{k|k-1} \mathbf{H}_k^T + R)^{-1}

输入与输出

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

使用示例

示例 1: 静置电池 SOC 快速收敛初始化

静置状态下端电压为 3.72 V 的锂电芯以较大偏差(socInit=0.6\text{socInit} = 0.6)启动。伴随电压测量输入,EKF 在 1.5 秒内迅速收敛至真实的 30% SOC,σsoc\sigma_{\text{soc}} 从 10% 降至 1% 以下。

示例 2: 具有电流零漂的动态行驶工况估计

在电动车脉冲放电工况下,滤波器同步估计荷电状态及电流传感器上 150 mA 的直流零偏,杜绝了长期安时积分发散。

说明与最佳实践

  • 交互式 OCV 电子表格与 CSV 导入导出: 通过 📂 导入 CSV、💾 导出 CSV(battery_ocv.csv)或 Excel 复制粘贴(Ctrl+V)加载标定曲线,即时查看动态 OCV = f(SOC) 曲线。
  • 动态不确定度估计: 输出端口 soc_sigma 提供实时估计标准差,便于电池管理系统(BMS)计算 95% 置信区间(±2σ\pm 2\sigma)。
  • 滤波器一致性监测: 归一化新息平方(NIS)用于诊断滤波器性能;在噪声方差 QQ 与 RR 匹配真实环境时,其统计均值约为 1.0。
  • 传感器丢帧容错机制: 当可选端口 Dropout 处于高电平时暂停测量校正,平滑回退至纯安时积分,同时协方差合理发散增大。
  • 高阶非线性鲁棒性: 采用平滑三次 Hermite 样条插值与局部迭代,避免了 OCV 曲线陡峭拐点处的协方差突变。

常见工程问题解答 (FAQ)

Q: Why is an Extended Kalman Filter (EKF) superior to Coulomb counting for battery SOC?

Pure Coulomb counting (SOC(t)=SOC0−1Qn∫IdtSOC(t) = SOC_0 - \frac{1}{Q_n} \int I dt) irreversibly drifts due to current sensor offsets and unmodeled parasitic reactions. An EKF pairs the Coulomb counting integrator with an Equivalent Circuit Model (ECM, R0+R1∥C1R_0 + R_1 \parallel C_1) and corrects the state estimate at each step using the nonlinear open-circuit voltage relationship Vt=OCV(SOC)−IR0−VRCV_t = OCV(SOC) - I R_0 - V_{RC}. This bounds SOC estimation error within ±2%\pm 2\% across temperature shifts and aging.

相关模块

  • KalmanFilter: 用于线性多变量动态系统状态估计的标准卡尔曼滤波器。
  • LookupTable: 用于构建静态非线性函数的一维查表环节。
  • RandomNumber: 生成高斯白噪声以仿真电压与电流传感器的测量干扰。