# Battery Capacity Estimator (Kalman Filter)

**Libraries:**

Simscape /
Battery /
BMS /
Estimators

## Description

The Battery Capacity Estimator (Kalman Filter) block implements an estimator that calculates the cell capacity of a battery by using the Kalman filter algorithms.

Use this block in conjunction with another block that estimates the state of charge (SOC) of the battery, such as SOC Estimator (Kalman Filter) or SOC Estimator (Adaptive Kalman Filter).

This block supports single-precision and double-precision floating-point simulation.

**Note**

To enable single-precision floating-point simulation, the data type of all inputs and
parameters, except for the **Sample time (-1 for inherited)**
parameter, must be `single`

.

For continuous-time simulation, set the **Filter type** parameter to
`Extended Kalman-Bucy filter`

or ```
Unscented
Kalman-Bucy filter
```

.

**Note**

Continuous-time implementation of this block works only in a double-precision floating-point simulation. If you provide single-precision floating-point parameters and inputs, this block casts them to double-precision floating-point values to prevent errors.

For discrete-time simulation, set the **Filter type** parameter to
`Extended Kalman filter`

or ```
Unscented Kalman
filter
```

and the **Sample time (-1 for inherited)**
parameter to a positive value or `-1`

.

### Equations

To estimate the battery capacity, the Battery Capacity Estimator (Kalman Filter) block starts from the equations of the derivative of the capacity and the SOC:

$$\begin{array}{l}\frac{dQ}{dt}=0\\ 0=\frac{dSOC}{dt}+\frac{i}{3600Q}\end{array}$$

where

*SOC*is the state of charge.*i*is the current of the battery cell.*Q*is the capacity in Ampere-hour.

The first equation is the state equation. The second equation is the output equation.

For the Kalman filter algorithms, the Battery Capacity Estimator (Kalman
Filter) block uses *Q* as the state and these process
and observation functions:

$$\begin{array}{l}f\left(Q\right)=0\\ h\left(Q,SOC\right)=\frac{dSOC}{dt}+\frac{i}{3600Q}\end{array}$$

**Extended Kalman Filter**

This diagram shows the structure of the extended Kalman filter (EKF):

The EKF technique relies on a linearization at every time step to approximate the nonlinear system. To linearize the system at every time step, the algorithm computes these Jacobians online:

$$\begin{array}{l}F=\frac{\partial f}{\partial Q}=0\\ H=\frac{\partial h}{\partial Q}=-\frac{i}{3600{Q}^{2}}\end{array}$$

The EKF is a discrete-time algorithm. After the discretization, the Jacobians for the SOC estimation of the battery are:

$$\begin{array}{l}{F}_{\text{d}}=1\\ {H}_{\text{d}}=-\frac{i{T}_{\text{s}}}{3600{Q}^{2}}\end{array}$$

where *T*_{S} is the
sample time.

For more information about the implementation of the EKF algorithm steps, see the Extended Kalman Filter section of the SOC Estimator (Kalman Filter) block.

**Extended Kalman-Bucy Filter**

This diagram shows the structure of the extended Kalman-Bucy filter (EKBF):

The EKBF is the continuous-time variant of the Kalman filter. In continuous time, the prediction and correction steps are coupled.

For more information about the implementation of the EKF algorithm steps, see the Extended Kalman-Bucy Filter section of the SOC Estimator (Kalman Filter) block.

**Unscented Kalman Filter**

This diagram shows the structure of the unscented Kalman filter (UKF):

The EKF locally approximates nonlinear functions with the linear equations obtained from the Taylor expansion by using only the first term of the expansion. In a highly nonlinear system, these solutions are not very accurate.

The UKF uses nonlinear transformations on a set of sigma points that the
algorithm chooses deterministically. This technique is called
*unscented transformation*. The mean and the covariance
matrix of the transformed points are accurate to the second order of the Taylor
series expansion.

For more information about the implementation of the EKF algorithm steps, see the Unscented Kalman Filter section of the SOC Estimator (Kalman Filter) block.

**Unscented Kalman-Bucy Filter**

This diagram illustrates the structure of the unscented Kalman-Bucy filter (UKBF):

The derived continuous-time filtering equations of the UKBF are similar to the EKBF equations.

For more information about the implementation of the EKF algorithm steps, see the Unscented Kalman-Bucy Filter section of the SOC Estimator (Kalman Filter) block.

## Ports

### Input

### Output

## Parameters

## Extended Capabilities

## Version History

**Introduced in R2023b**