Code covered by the BSD License  

Highlights from
Lithium Battery Model, Simscape Language and Simulink Design Optimization

4.9 | 9 ratings Rate this file 309 Downloads (last 30 days) File Size: 944 KB File ID: #36019 Version: 1.24
image thumbnail

Lithium Battery Model, Simscape Language and Simulink Design Optimization


Robyn Jackey (view profile)


19 Apr 2012 (Updated )

Multi-temperature lithium battery model using Simscape language and Simulink Design Optimization

| Watch this File

File Information

This file contains multi-temperature lithium battery model examples with thermal dynamics that are implemented using the Simscape language. There are equivalent circuit model examples containing 1 RC branch and 2 RC branches, plus an 80-cell battery pack model. The number of branches can be chosen to balance fidelity and parameter estimation complexity. These models are implemented using Simulink and Simscape language.
Estimating battery parameters can be a complex task. For help, please see:
Estimating Parameters of a Battery (video, 4:49)
An overview that shows how Simulink Design Optimization can estimate parameters.
Automating the Parameter Estimation of a Battery Model (video, 9:55)
A video that shows automating the parameter estimation process, when you have lots of experimental data to process.
Automating Battery Model Parameter Estimation using Experimental Data (webinar, 25:28)
A longer webinar that shows the automated parameter estimation workflow in more detail.


Additional literature:

SAE 2015: Model-Based Parameter Identification of Healthy and Aged Li-ion Batteries for Electric Vehicle Applications

Webinar: Battery Data Acquisition and Analysis Using MATLAB

Webinar: Lithium Battery Model with Thermal Effects for System-Level Analysis

IEEE 2012: Lithium Battery Model with Thermal Effect

SAE 2013: Simplified Extended Kalman Filter Observer for Battery SOC Estimation

SAE 2013: Battery Model Parameter Estimation Using a Layered Technique

SAE 2014: Battery Pack Modeling, Simulation, and Deployment on a Multicore Real Time Target

Webinar: Optimizing Vehicle Electrical Design through System-Level Simulation

Video: Real-Time Simulation of Battery Packs Using Multicore Computers

Video: MATLAB & Simulink Racing Lounge: Battery Modeling with Simulink

Using Model-Based Design to Build the Tesla Roadster


MathWorks Consulting offers services on this topic. For assistance, please contact me or your MathWorks representative.


Automotive Electrical System Simulation And Control inspired this file.

This file inspired Automotive Electrical System Simulation And Control.

Required Products Optimization Toolbox
Parallel Computing Toolbox
Simulink Design Optimization
MATLAB release MATLAB 7.14 (R2012a)
MATLAB Search Path
Other requirements R2012a or later recommended, R2010b or later required
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (38)
03 Nov 2015 cris paul

Hello Robyn,thanks for your model and it has really has helped me a lot. Now I want to simulate the Li-ion battery with a 3 R-C branched model and I have watched your video and paper but I'm still not sure how to set up the starting point and end point at every estimation based on Layered Technique. What's more, I want to know how control the initial parameter values at every estimation ? And could you please share your program using 3 R-C branched model? Thank you in advance.

Comment only
16 Oct 2015 reshma konjari  
15 Oct 2015 Yujie Wang  
07 Sep 2015 reshma konjari

Hello Robyn,really thanks for your models.
I'm getting this error when I run ssc_lithium_cell_1RC

Failed to find 'C_ext' in library 'LiBatteryElements_lib' referenced by 'ssc_lithium_cell_1RC/Lithium Cell (1RC equivalent circuit model)/C1/C_ext'

Can you please help me out with this.

Thank you

Comment only
12 Aug 2015 Daisy Li

Hi Robyn,thanks for your model!
I'm using Matlab R2014b to run the estimation model but errors as follow occurs:

Error evaluating parameter 'C_Table' in 'ssc_lithium_cell_1RC_estim/Lithium Cell (1RC equivalent circuit model, single temperature)/C_table_1Temp'

Undefined function or variable 'C1'。
Component: Simulink | Category: N.A.

Error evaluating parameter 'SOC_Table' in 'ssc_lithium_cell_1RC_estim/Lithium Cell (1RC equivalent circuit model, single temperature)/C_table_1Temp'

Undefined function or variable 'SOC_LUT'。
Component: Simulink | Category: N.A.

Could you give me advice?

Thank you !

Comment only
09 Jul 2015 RT

RT (view profile)

Hi Robyn, thanks for the file.
I want to estimate charge param. I tried use your model but it seems the results is not converged. I replace the PulseData.mat with my own experimental. The experiment is similar with your example, but the current is in charge mode. Could you give me advice? Thank you.

Comment only
07 Jul 2015 satendra kumar

satendra kumar (view profile)

Dear Robyn, thanks a lot for sharing this. I am working on cell balancing with 4 li-ion cells in series.
I want to start the simulation with different values of soc for all cells. I am using 2rc model.
My doubt is, how can I control the starting point of soc for cells.
Thanks a lot in advance.

Comment only
30 May 2015 Kevin

Kevin (view profile)

For those who have a problem such as:

Failed to generate 'LiBatteryElements_lib'

Caused by:
Error using ne_buildpackage (line 32)
File: C:\<path>\C_table.ssc
Line: 9

Input 'T' declared with unit expression that contains an affine unit: 'C'. Affine units are not allowed when declaring members of this type.

Do the following:
Simscape language doesn't like other units than "Kelvin" for temperature. It needs to be converted by an affine transformation, and sometimes induce error when not used properly.
Change the unit 'C' by 'K', and modify the value for the temperature accordingly in the file "C_table.ssc"

06 May 2015 Long Nguyen

Dear Robyn Jackey,
I am working with a team to create a battery management system. I found out your "Lithium Battery Model, Simscape Language and Simulink Design Optimization" some weeks ago and it is very helpful. I want to thank you a lot. However, I have a big question, I tried to use it before and I watched your all videos many times,I saw you did mention about estimate parameters.But I am still not understand at all and I want to ask you how can we use the experiment results and input them in the model?
I watched all videos and I saw that you did not mention how can we input the look-up table into your model. I tried many ways but none of them working.
I am very appreciate your help, please answer me as soon as possible, many thanks.

Kind Regards,
Long Nguyen

20 Feb 2015 Robyn Jackey

Robyn Jackey (view profile)

@ John Arvanitis - Sorry for the delay. I tested the two model advisor checks in R2015a prerelease, and they worked ok. Were you on a prior release? You can email me from the "Contact Author" page if you like.

Comment only
30 Jan 2015 mohand hamouda

Dear Mr. Jackey,

I have used their Li-Ion Battery model as part of my Master's thesis, as I have no real battery.
I would like design an MPC controller and an need a lienearized model , but I have to get a problem with linear-battery model. I can not linearize in a battery model an operating point.
can you please tell me to get help for the ÖLinearisierte model?
should I just leave the Battery and control a DC-DC converter Modllieren and then the battery?

I thank you in advance.

Yours sincerely

Comment only
03 Dec 2014 Valentin

Thank you very much for these nice examples!

We try to characterize a electronic car battery for appropriate SoC-estimation in the car.
Therefore we measured pulse data and are doing parameter estimation.
Now the question: How do you use the gained data later on in the devices (eg our car)? You normally generate look up tables and implement them in the ECU? Or you bring the complete model to the ECUs? What would be the typical way of proceeding?

Thank you in advance!

Comment only
03 Dec 2014 Valentin  
04 Nov 2014 Robyn Jackey

Robyn Jackey (view profile)

Kirankumar - You can use drive cycles (validation) data with Simulink Design Optimization to tune parameters of a model. I would encourage doing so. However, the circuit parameter values may need to have good initial guesses for them to converge.

Pulse data is nice because it allows you to isolate the contributions of the different equivalent circuit elements.

Comment only
03 Nov 2014 Kirankumar

We are trying to estimate parameters for Lithium-Ion battery with Rin+R1||C1 structure. For moment we shall not consider the thermal effect. All three parameters shall be 2-D look-up tables with breakups along SOC and Ibat(temperature in future).

We are looking for high accurate estimation(<10mV). Till now, we used System identification tool box to estimate the parameter for all the scenarios as per the breakups mentioned above. But, while validation with drive pattern data(validation data) we get huge error. We are thinking to try Parameter estimation toolbox to get better results.

My query is:
1) is it possible to directly feed the validation data to parameter identification toolbox for estimation? or its always necessary to provide the pulse data for estimation?
2) Intent is we do not have all the pulse data with different SOC and Ibat.


18 Sep 2014 John Arvanitis

Great Job (Lithium Battery Model, Simscape Language and Simulink Design Optimization)

Now we have an easy way to parameterize battery with accuracy on all conditions.

One question please:
1) During of Model Advisor usage we got
the following error

On Modeling Standards for DO-178C/DO-331 - Check safety-related optimization settings and
On Modeling Standards for DO-178C/DO-331 - Check safety-related code generation settings

Abnormal exit: BLAS loading error: mkl.dll: Not enough storage is available to process this command.

What could I do in order to over come this problem?

Comment only
10 Jul 2014 Johnny Rico

The downloaded zip archive appears to be damaged. I request the author to kindly re-upload the same.


Comment only
23 May 2014 Ali Rostami

I have troule downloading the file from
the error message is " the site is unavailable or cannot be found.
Has anyone experienced the same or any solution?

Comment only
16 Apr 2014 han

han (view profile)

25 Feb 2014 Robyn Jackey

Robyn Jackey (view profile)

I will be presenting during a workshop entitled "Developing Battery Management Systems Using Model-Based Design" at the American Control Conference on June 3rd in Portland, OR. If you are interested in attending, please see:

Comment only
24 Feb 2014 Robyn Jackey

Robyn Jackey (view profile)

Lu - can you email me directly through the contact author page?

Comment only
23 Feb 2014 Lu

Lu (view profile)

Hi Robyn, thank you for sharing.

I have a question about the paper"SAE 2013: Simplified Extended Kalman Filter Observer for Battery SOC Estimation

In this paper, you model the hysteresis effect, and use k as the hysteresis factor.
how can I understand the following sentence in Page5"The value of k was obtained by inspection by minimizing the difference between the experimental and simulated VOC vs. SOC curves. VOC(VSOC) is the instantaneous value of the OCV on the minor loop."

what's the experimental VOC(VSOC),is caculted by(VOCch(VSOC)+VOCdisch(VSOC) )/2?
and what's simulated VOC(VSOC), is the difference between measured terminal voltage (Vt) and VRC?

would you please share the progress of k fitting.


27 Jan 2014 Robyn Jackey

Robyn Jackey (view profile)

Christopher - I have not seen that license error before. Can you please try contacting MathWorks technical support?

Comment only
24 Jan 2014 Christopher

I was trying to follow the instructions in the README file, but step 2 is giving me a couple similar errors, for example:
"Error using save_system>i_builtin (line 188)
Cannot save this library because block R_table_1Temp requires a license for , which could not be obtained.
Please try again when a license becomes available."

I am using Matlab R2013A, Simulink 8.1, Optimization Toolbox 6.3, Parallel Computing Toolbox 6.2, and Simscape 3.9. It doesn't look like I Have the Simulink Design Optimization, but I don't think that's what is causing the error that I am seeing. Do you have any suggestions? I looked under the Simulink examples, and I don't see the battery demo even though it is supposed to ship with it.

Thank you!

Comment only
19 Nov 2013 Robyn Jackey

Robyn Jackey (view profile)

With R2013a and later, the ssc_lithium_cell_1RC and ssc_lithium_cell_2RC, along with the library LiBatteryElements are now shipping Simscape demos. The shipping versions should be used, because of a Simscape change requiring use of Kelvin rather than Celsius in Simscape language code. The additional demos in this MATLAB Central entry should work, just ensure that the older LiBatteryElements libraries are not added to your MATLAB search path, so it uses the shipping versions.

Comment only
13 Nov 2013 Maryam Bahramipanah

Thanks Robyn. I did exactly what is written in Readme.text, but by running "ssc_build LiBatteryElements" , I am receiving this error :
Error using LiBatteryElements.C_table (line 9) Input 'T' declared with unit expression that contains an affine unit: 'C'. Affine units are not allowed when declaring members of this type.

:(. I am using the R2012a files.

Comment only
12 Nov 2013 Robyn Jackey

Robyn Jackey (view profile)

Hi Maryam,
You might need to add all the directories to your MATLAB search path first. To fix the error you encountered, you might need to rebuild the Simscape library for your platform and MATLAB version. There are directions in the included readme.txt file.

Comment only
11 Nov 2013 Maryam Bahramipanah

Robyn, I found that I have to run the liBatteryelemets before. SO, I have no problem with that any more. But there is another problem :( . when I started the estimation, I received this message "index exceed matrix dimension". Do you know what is it for?

Comment only
11 Nov 2013 Maryam Bahramipanah

Hello. First of all thanks for uploading the files.

When I am trying to open each elements of the model (for instance R_table_1Temp), I receive this error:

Error Id: ne_dli: internal: unableToCreatDialog

unable to creat block dialog. If the block belongs to a custom simscape library, please run ssc_build to rebuild the library...."

Can you please help me with that?


Comment only
07 Jun 2013 zwbscg

zwbscg (view profile)

15 Apr 2013 Robyn Jackey

Robyn Jackey (view profile)

For R2012b and later, there are shipping demos of ssc_lithium_cell_1RC and ssc_lithium_cell_2RC models. the LiBatteryElements package is also part of the shipping Simscape demo, so it's not included in the R2012b folder of the zip file.

Comment only
15 Apr 2013 Vita

Vita (view profile)

Isn't there any LiBatteryElements package in the R2012b folder?

Comment only
03 Dec 2012 Robyn Jackey

Robyn Jackey (view profile)

Hi Mengjia - Unfortunately the errors you see are expected and the model will not work in R2010a or earlier. The early versions of Simscape lookup tables required all dimensions to be a minimum of size 4, and my demo model only contains 3 temperatures. It will work fine in newer releases, otherwise it might work if you add a fourth temperature to the data for each lookup table.

Comment only
03 Dec 2012 Mengjia

Hello, I've got errors as below running ssc_lithium_cell_1RC.mdl

1. ssc_lithium_cell_1RC/Solver Configuration: Unable to compile the physical network.

2. sc_lithium_cell_1RC/Lithium Cell (1RC equivalent circuit model)/Main Branch Voltage Source (Em)/PS Lookup Table (1D): The size of the vector of input values or output values must be greater than 3.

3. ssc_lithium_cell_1RC/Lithium Cell (1RC equivalent circuit model)/C1/PS Lookup Table (2D): Y-vector must have no less than 4 elements.

And for other 3 lookup tables(2D) I've got the same Y-vector elements issue, so totally 6 errors.

I've followed the 2 steps as readme.txt stated, please kindly advise where go wrong?

PS: I am using the Matlab R2010a to run the files in folder R2010b.

Comment only
12 Jul 2012 Robyn Jackey

Robyn Jackey (view profile)

To answer your questions:

1. In the paper, we chose the initial conditions based on the driving cycle we used for validation. The temperature T=20 was based on a measured cell temperature (approximately same as electrolyte). Initial SOC was selected based on best fit of the measured vs simulated voltage at the very beginning part of the drive cycle.

2. You can modify the InputData*.xls files and import them into the Signal Builder block if you like to change the input curves. However, you will need to delete the "Copyright ..." string that was placed in cell E1 to avoid an error. Otherwise, Signal Builder tries to import data from column E, causing the error you found.

Comment only
10 Jul 2012 dang hong

Dear Sir,
In reference paper " high fidelity electrical model with model with thermal dependence for characterization and simulation of high power lithium battery cells", how to choose initial SOC = 45 %,T =20, ? For example, in the case of using ssc_lithium_cell_1RC.mdl.
when importing "InputData_1RC.xls" in signal builder of ssc_lithium_cell_1RC, there is a error " attempted to access td(:,3); index out of bounds because size(td)=[46,2]. How to import that file?

Comment only
05 Jun 2012 Robyn Jackey

Robyn Jackey (view profile)

The R2012a folder contains files that use newer features that will only work on R2012a or later. I suspect that is the reason for the build error. The R2010b model should work in that version and up, however it is a little less tidy because the lookup tables were external to the custom Simscape language blocks.

Comment only
04 Jun 2012 david

david (view profile)

run ssc_build LiBatteryElements

the following errors apeared.

Generating 'LiBatteryElements_lib.mdl' in the current directory 'C:\Documents and Settings\Jiucai\My Documents\Downloads\ssc_Li_cell_20120419\ssc_Li_cell_20120419\R2012a' ...
Failed to generate 'LiBatteryElements_lib'

Caused by:
Error using ne_buildpackage (line 32)
File: C:\Documents and Settings\Jiucai\My
Line: 13
Attribute Size is not supported for constructs of type

Comment only
19 Apr 2012 1.1


19 Apr 2012 1.3

Updated copyright statement, link to webinar.

15 Jun 2012 1.6

Added link to demo video. Removed extraneous Simscape mex files. (Note: you will need to run "ssc_build LiBatteryElements" to build a machine-specific Simscape library for the battery building blocks.

02 Jul 2012 1.10

Added 80-cell battery pack model.

19 Dec 2012 1.12

R2012b folder with .SLX file format. Excluded R2012b +LiBatteryElements folder because it is a shipping demo.

ssc_lithium_cell_SDO_Project.mat parallel computing unchecked as default, due to a bug if the toolbox is not installed. See Readme.txt

11 Jun 2013 1.13

Updated the R2012b+ version of the models:
1. The shortcut block to open the custom library was broken
2. Use Kelvin temperature units within the Simscape model

There is a known bug in R2013a. Please see README.txt for info.

13 Jun 2013 1.14

Modified description only to add links to new publications.

18 Jun 2013 1.15

Fixed an issue with temperature units on R2012b demos.

26 Jun 2013 1.16

Updated a bad link to the parameter estimation video.

10 Sep 2013 1.17

Added a new webinar link to the description

28 Jan 2014 1.18

Updated description only. No file changes.

25 Mar 2014 1.19

Description updated - added a link to the Battery Data Acquisition webinar. No changes to the files.

18 Apr 2014 1.21

Added acknowledgement for other entry - electrical system simulation

22 Apr 2014 1.22

Corrected webinar links

05 Nov 2014 1.23

updated links in description only

08 Dec 2014 1.24

Updated link to: SAE 2014: Battery Pack Modeling, Simulation, and Deployment on a Multicore Real Time Target

16 Oct 2015 1.24

added link to new paper on lithium battery cell parameter changes due to aging

02 Nov 2015 1.24

updated a hyperlink in description

Contact us