Main Content

Battery Capacity Estimator (Least Squares, Variable Weights)

Battery capacity estimator using least-squares algorithms and variable weights

Since R2024a

Libraries:
Simscape / Battery / BMS / Estimators

Description

The Battery Capacity Estimator (Least Squares, Variable Weights) block calculates the cell capacity of a battery by using least-squares algorithms. The values of the weights at the input ports VarianceSoc and VarianceCurrent can be variable.

For discrete-time simulation, set the Sample time parameter to a positive value. To inherit the sample time, set Sample time to -1. For continuous-time simulation, set Sample time to 0.

Equations

The least-squares estimation finds the line of best fit for a set of data points by minimizing the sum of the squared residuals. The squared residuals are the difference between the observed responses and the predicted responses of the model. This line of best fit predicts the dependent variable.

This equation defines the battery state of charge (SOC) at time tn2,

SOC(tn2)=SOC(tn1)+1Qtn1tn2i(τ)dτ,

where:

  • SOC(tn1) is the SOC at time tn1, with n={1,…,N}.

  • Q is the capacity in ampere-hours.

  • i is the battery cell current in amperes.

  • tn1tn2i(τ)dτ denotes the integrated battery cell current over the time interval tn2 - tn1. Time tn1 and tn2 must be in hours for the units to be consistent.

Define xn=SOC(tn2)SOC(tn1) and yn=tn1tn2i(τ)dτ, and rewrite the SOC equation:

yn=Qxn.

The block uses this linear equation to determine an estimate of the cell capacity using the least squares estimation,

(ynΔyn)=Q^(xnΔxn),

where:

  • Δxn is the error associated with the SOC estimation.

  • Δyn is the error associated with the current sensor.

  • Q^ is an estimate of the true cell capacity under noisy measurements.

Ordinary Least Squares

The weighted ordinary least squares (OLS) method estimates the cell capacity by minimizing the weighted squared errors, Δyn, of the merit function

xWLS2=n=1N(ynYn)2σyn2=n=1N(ynQ^xn)2σyn2,

where σ2yn denotes the variance of the current measurement and Yn is a point on the line Yn=Q^xn that corresponds to the measurement data point {xn,yn}. The block assumes that yn has noise and xn has no noise.

To solve the weighted OLS problem, the block differentiates the merit function with respect to Q^ and solves for Q^ by setting the partial derivative to zero [1]:

xWLS2Q^=2n=1Nxn(ynQ^xn)σyn2=0Q^n=1Nxn2σyn2=n=1Nxnynσyn2Q^=n=1Nxnynσyn2n=1Nxn2σyn2

This method can be computed recursively and is easily adapted to allow fading of past measurements.

If you define the forgetting factor as 0γ1, then the block obtains the estimated capacity from the equation

Q^=k2,nk1,n,

where:

k1,n=γk1,n1+xn2σyn2k2,n=γk2,n1+xnynσyn2

Total Least Squares

The weighted total least squares (TLS) method estimates the cell capacity by minimizing the sum of both weighted square errors, Δxn and Δyn, of the merit function [1],[2],

χWLTS2=n=1N(ynYn)2σyn2+(xnXn)2σxn2,

where σ2yn denotes the variance of the current measurement, σ2xn denotes the variance of the error on the SOC estimates, and Xn and Yn are points on the line Yn=Q^Xn that corresponds to the noisy measured data point {xn,yn}.

To enforce Yn=Q^Xn, the block augments the merit function with Lagrange multipliers λi:

χWLTS,a2=n=1N(ynYn)2σyn2+(xnXn)2σxn2λi(YnQ^Xn).

The block sets the partial derivatives of χWLTS,a2 with respect to λi, Yn, and Xn to zero:

χWLTS,a2λi=(YnQ^Xn)=0Yn=Q^XnχWLTS,a2Yn=2(ynYn)σyn2λi=0λi=2(ynYn)σyn2χWLTS,a2Xn=2(xnXn)σxn2+λiQ^=0Xn=xnσyn2+Q^ynσxn2σyn2+Q^2σxn2

Then the block rewrites the merit function as [1]:

χWLTS2=n=1N(ynYn)2σyn2+(xnXn)2σxn2=n=1N(ynQ^xn)2σyn2+Q^2σxn2.

Finally, the block sets the partial derivative of χWLTS2 with respect to Q^ to zero:

χWLTS2Q^=n=1N2(Q^xnyn)(Q^ynσxn2+xnσyn2)(Q^2σxn2+σyn2)2=0.

In this equation:

  • There is no closed-form solution in the general case. To find a closed-form solution, perform a Newton-Raphson search for Q^.

  • There is no recursive update in the general case.

  • The solution is impractical for implementation in an embedded system.

Recursive Approximation of Total Least Squares (RTLS)

The block substitutes σxn=kσyn in the equation of χWLTS2:

χRTLS2=n=1N(ynYn)2σyn2+(xnXn)2kσyn2=n=1N(ynQ^xn)2(Q^2k2+1)σyn2.

The partial derivative of the WTLS merit function reduces to:

χRTLS2Q^=2n=1N(Q^xnyn)(Q^k2yn+xn)(Q^2k2+1)2σyn2=0Q^2n=1Nk2xnynσyn2a+n=1Nk2xn2k2yn2σyn2b+n=1Nxnynσyn2c=0Q^=b±b24ac2a

The block incorporates fading memory by using this equation

Q^=k1,n+k2k3,n+(k1,nk2k3,n)2+4k2k2,n22k2k2,n,

where:

k1,n=γk1,n1+xn2σyn2k2,n=γk2,n1+xnynσyn2k3,n=γk3,n1+yn2σyn2

Approximate Total Least Squares (ATLS)

The ATLS method is recursive and allows σ2yn and σ2xn to be non-proportional.

This figure shows the definitions the block uses to derive the approximate weighted total least squares:

The block defines Δxn and Δyn as the x-distance and y-distance between the data point n and the line, respectively. The slope of the line is Q^=ΔynΔxn for all n. The angle of the line is θ=tan1Q^.

This equation defines the shortest distance between the line and a given data point:

Rn=Δyncosθ=Δyn1+Q^2.

If δxi=Risinθ and δyi=Ricosθ, the block defines the x and y components of the perpendicular distance between the data point n and the fitting line. Then the block can define the AWTLS merit function using this equation:

χAWTLS2=n=1Nδxn2σxn2+δyn2σyn2=n=1N(ynQ^xn)2(Q^2+1)2(Q^2σxn2+1σyn2).

This equation defines the Jacobian of the AWTLS merit function:

χAWTLS2Q^=2(Q^2+1)3n=1NQ^4xnynσxn2+Q^3(2xn2σxn2xn2σyn2yn2σxn2)+Q^2(3xnynσyn23xnynσxn2)+Q^(xn22yn2σyn2+yn2σxn2)+xnynσyn2.

The roots of the quartic equation are the candidate solutions for Q^. The block rewrites the quartic equations as

c5,nQ^4+(2c4,nc1,nc6,n)Q^3+(3c2,n3c5,n)Q^2+(c1,n2c3,n+c6,n)Q^c2,n=0,

where:

c1,n=γc1,n1+xn2k2σyn2c2,n=γc2,n1+kxnynk2σyn2c3,n=γc3,n1+yn2σyn2c4,n=γc4,n1+xn2σxn2c5,n=γc5,n1+kxnynσxn2c6,n=γc6,n1+k2yn2σxn2

The ATLS merit function does not equal the weighted TLS merit function when σxn=kσyn.

When σxn=kσyn, the block uses this equation to estimate the true cell capacity:

Q^corrected=Q^k.

Implementation

This figure shows how the block estimates the battery capacity using the different least-squares algorithms:

During the Data Acquisition phase, the block runs in a loop until the algorithm finds a valid data point. The block follows these steps:

  1. The block receives an SOC estimate at time tn1 using an SOC estimator.

  2. The block recevies a second SOC estimate at time tn2.

  3. While SOC(tn1)SOC(tn2)<SOCmin_change, the block:

    • Keeps receiving SOC estimates.

    • Integrates cell current, yn=tn1tn2i(τ)dτ.

    • Overwrites time tn2 with a new timestamp.

    • If the battery is charging, the block discards the measurement and goes back to step 1.

Assumptions and Limitations

  • The block assumes the random errors Δxn and Δyn follow a zero-mean normal distribution.

  • The block assumes that the weights σ2xn and σ2yn are known.

  • In the RTLS algorithm, the scaling factor k must proportionally relate the weights σ2xn and σ2yn such that σxn=kσyn

Ports

Input

expand all

Battery current, in amperes, specified as a scalar for a single cell or a vector for multiple cells. To specify this input as a vector of cell currents, select the Specify Current input as cell current(s) parameter. If you select this parameter, the size of this input port must be equal to the size of the other input ports.

State of charge of one or multiple cells, specified as a scalar or vector of entries in the range [0, 1]. The size of this input port must be equal to the size of the InitialCellAH, VarianceSOC, and VarianceCurrent input ports.

Variance of the battery SOC, specified as a positive scalar or vector of positive values. The size of this input port must be equal to the size of the InitialCellAH, CellSOC, and VarianceCurrent input ports.

Variance of the current measurement, specified as a positive scalar or vector of positive values. The size of this input port must be equal to the size of the InitialCellAH, CellSOC, and VarianceSOC input ports.

Initial cell capacity of the battery, in ampere-hours, specified as a scalar for a single cell or a vector for multiple cells. The size of this input port must be equal to the size of the CellSOC, VarianceSOC, and VarianceCurrent input ports.

Output

expand all

Estimated cell capacity of the battery, in ampere-hours, returned as a scalar or a vector. The size of this output port is equal to the size of the InitialCellAH input port.

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Option to specify the value of the Current input port as a vector of cell currents. If you select this parameter, the value at the Current input port can be a scalar or a vector of size equal to the size of the block inputs.

Least-square algorithm that the block uses to estimate the battery cell capacity.

Threshold to detect a change in the SOC. Typical values are 0.05 or 0.03, which represent a 5% or 3% change.

Forgetting factor.

Scaling factor k.

Dependencies

To enable this parameter, set Least squares algorithm to Recursive total least squares or Approximate total least squares.

Time between consecutive block executions. During execution, the block produces outputs and, if appropriate, updates its internal state. For more information, see What Is Sample Time? and Specify Sample Time.

For inherited discrete-time operation, specify this parameter as -1. For discrete-time operation, specify this parameter as a positive integer. For continuous-time operation, specify this parameter as 0.

If this block is in a masked subsystem or a variant subsystem that supports switching between continuous and discrete operations, promote the sample time parameter. Promoting the sample time parameter ensures correct switching between the continuous and discrete implementations of the block. For more information, see Promote Block Parameters on a Mask.

References

[1] Plett, G., Battery Management Systems: Volume II, Equivalent-Circuit Methods, Artech House, 2015.

[2] E. Bakas, B. Rosca, S. Wilkins, T. Donkers. Least-Squares-based Capacity Estimation for Lithium-ion Battery Cells, The European Battery, Hybrid and Fuel Cell Electric Vehicle Congress, Geneva, Switzerland, 2017.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2024a