Welcome to week four of this course. This is where things start to get really interesting I think because you're going to see how to use some of the techniques that you've learned and apply them to real problems. So so far in this course, you've learned how to make equations that describe the operation of a lithium ion battery cell. You've also seen how to conduct tests in the laboratory and how to use the data that you collected from those tests, in order to determine the static and dynamic model parameter values. Then you learned how to use these mathematical models combined with the parameter values from the lab tests in order to be able to simulate the performance of a single battery cell. In particular, you've learned how to predict a battery cell's output voltage response to a change in its input current. So this week, we're going to look at some other model applications. In this lesson, you will learn how to simulate a constant voltage battery response and later, you will learn how to simulate a constant power battery response. Then in later lessons this week, you will learn how to simulate battery packs comprising many cells connected together in series and in parallel. When we are charging a battery cell, it's common first to apply a constant current charge to the cell until the battery cell achieves some maximum terminal voltage. Then, once we have reached that maximum terminal voltage, instead of supplying a constant current to this cell, we clamp the voltage at the terminal's constant and we allow current to vary until the batteries cell is fully charged. So up until now you have seen how to simulate how a cell's voltage responds when we supply a profile of current versus time, but you have not yet learned how to compute the profile of current versus time that will keep a battery cell's voltage constant and that's what we're going to do now. To see how to do this, it is important to examine the enhanced self-correcting cell model once again, and I have reproduced the equations of this model on the slide. The state equation states or says, that the state of the model right now, is a function of the values of this state at the previous time, combined with values of the input current from the previous time. It will be really important for all of our applications this week to notice that the present state is not a function of the present input, but is a function of past inputs only. Next, let's look at the output equation or the voltage equation of the model. The voltage is computed as the open-circuit voltage plus the hysteresis voltage minus diffusion voltages and minus an ohmic voltage drop. The open-circuit voltage contribution is a function of the present state, but remember that the present state is not a function of the present input. It is a function only of previous inputs. Similarly, the hysteresis value right now is a function of the present state and therefore is a function of previous input current values only. Also, the diffusion voltages are a function of the present state, and so therefore, are a function only of previous values of the input current. So when we look at the model and we look at the part of the voltage, that is a function of the input current right now, the only part of the equation that talks about that is the ohmic voltage drop across resistor R_0. This observation is critical for being able to simulate a constant voltage situation. So to recap, cell voltage has two portions, one portion I will call a fixed part. Now, it's not fixed over all time, but at this point in time, this fixed part is determined by all of the previous input current values and cannot vary at this point in time due to the input current right now. So it's fixed in that sense. Every time step it changes, but right now, the value of this part is fixed by what happened in the past. So we have a fixed part, we also have a variable part and the variable part does depend on the present input current. We're going to make use of this observation to develop a way to simulate a constant voltage scenario. To condense the mathematical notation, make it a little bit easier to talk about, we define the fixed part to be v_f at time step k. So this is the open circuit voltage plus the hysteresis voltage and with the combination of the diffusion voltages as well. Then to simulate a specific constant voltage, we can calculate the input current that produces the desired output voltage in a few easy steps. So we remember that the voltage is equal to the fixed part minus R_0 multiplying the input current. Then, we rearrange the equation such that the input current is isolated on the left-hand side just using standard algebra. We find that the input current, in order to create a desired output voltage, is equal to the fixed voltage, minus the desired, voltage all divided by R_0. So at any point in time, when we require fixing the output voltage at some level, we can use this equation to compute the input current at that point in time that is guaranteed to do so. Then we simply simulate the enhanced self-correcting cell model with this value of input current for this point in time, just like you learned how to do in earlier lessons. So remember one application for this is a common type of battery cell charging protocol especially done in laboratories, where we charge this cell using constant current until we achieve a certain voltage level, and then we hold the voltage constant. So let's have a look at this in some octave code. Here we look at some octave code that can be used to simulate a constant current constant voltage charge of a battery cell. The script here begins with some comments, and then clears the work space and closes all figures, if any happen to be open. It clears the command window also. So we're starting fresh. Then it loads and example cell model from storage into the work space. Here I am loading a model of an E1 cell but this could be done with any enhanced self-correcting cell model. The simulation then does some initializations. It sets the maximum duration of the simulation to be 3,001 time samples which in this case corresponds to 3,001 seconds. Then it sets the temperature to 25 degrees Celsius. After that, it loads some enhanced self-correcting cell model parameter values from the model data structure into a local variable, so that we can simulate the cell more easily. Finally, it sets the maximum charge voltage to 4.15 volts, which is the point we will use for switching from the constant current portion of our charging into the constant voltage segment of our charging profile. Next, the octave code preallocates some storage into which we can save values of our variables so that we can have a look at them later on using plotting functions. For example, the storez variable will be used to store state of charge at every point in the simulation, the storev variable will store a voltage, the storei variable will store current, and the storep variable will store power. Then we initialize the simulation with an initial cell state of charge of z equals 50 percent, the resistor-capacitor current state is initialized to zero, the history usage state is initialized to minus one corresponding to this cell having recently been charged, and the sign of the input current is initialized to minus one in a similar way. We also define the value of constant current that we will use in this simulation and the constant current portion to be nine Amperes. All of these things can be changed and this code will be provided to you on the Coursera website for you to be able to experiment with as well. The code on this slide implements the simulation of the constant current, constant voltage charge. We begin by entering a loop, a for loop that iterates over all of the time allocated for charging. The first step inside of this loop is to compute the fixed part of voltage that applies right now, by computing the open-circuit voltage, the histories, its contribution, and the diffusion voltage contribution. Then we compute the input current necessary or that would be necessary to force the output voltage to the maximum 4.15 volts when charging. Now, at early points in charging, the current required to take a cell from low state of charge to a terminal voltage of 4.15 volts would be an enormous amount of current, that would greatly exceed the constant current threshold of nine amperes that we have set. So if this value that we compute in this equation happens to be greater in magnitude than this threshold of nine amperes, then we use nine amperes as the input current. Otherwise, we use this particular computed value. So what we're doing, is we are guaranteeing that the cell voltage never exceeds 4.15 volts and at the same time guaranteeing that the input current never exceeds the constant current charging rate of nine amperes. That's how we implement the constant current, constant voltage charging. So those were really the tricky lines in this simulation to come up with that logic for how would we know when to do a constant current versus a constant voltage step. Now I think you can see that it's really quite simple after you learn the trick. Everything else in this code should look very familiar to you after having studied the SimCell.m function last week. For example, the next step updates the state of charge equation and then we update the resistor-capacitor, resistor currents equation. Then we compute the hysteresis rate factor and we update the hysteresis state and finally, we update the sign of the input current. At the end of all of this, we store the present values of state of charge and cell voltage and input current and power for later examination. So the simulation is now complete and the code on this slide shows you how you can plot some results from the simulation. We begin by creating a time vector having correct length against which we can plot the voltage and current and power and state of charge. Then in figure one, we plot the state of charge of the cell in percent versus time, in figure two we plot the terminal voltage versus time, in figure three we plot the input current versus time, and finally, in figure four we plot the cell power versus time. The figures on this slide show you some example results from the simulator. In the top left plot, you see state of charge versus time, on the top right you see terminal voltage versus time, in the bottom left, you see cell input current versus time, and finally, on the bottom right, you can see cell power versus time. If we look first at the top right figure, you can easily see that the voltage is increasing as the cell is being charged under the constant current part of the profile. Then when the voltage achieves its maximum value of 4.15 volts, you can see that the voltage is held constant and steady until the end of the simulation. This is exactly what we would hope to see. In the bottom left figure, you can see that the input current is indeed held constant at the constant current value until the maximum voltage is achieved around time 1,500 seconds, after that the magnitude of current decreases towards zero as the terminal voltage is held constant. By the way, this is exactly what we see when we're charging real battery cells also, this is not an artifact of simulation. While the simulation uses a model that is not completely precise, the trends that you see and the basic idea that you see here is exactly what we see when we're charging a battery cell in the laboratory. In the top left figure, you can see state of charge and how it increases linearly over time during the constant current portion of the test. Then you see that when we switch to the constant voltage portion of the test, the state of charge still increases but not as rapidly and so the slope becomes non-constant as state of charge slowly approaches the desired final values. By the way, this is a demonstration of one reason why it's possible for many systems to charge quickly up to about 80 or 90 percent state of charge. But then why it takes so much longer to charge up to the final state of charge, the full state of charge of a battery pack. The reason is if we charged quickly all the way up to a 100 percent state of charge, we would exceed the manufacturer voltage ratings of the cell. But we can get maybe 80 percent of the way quite quickly without exceeding those voltage limits. Finally, the bottom right figure shows power versus time. For the first interval, we know that current remains constant but voltage is increasing and so the magnitude of power is actually increasing. Then for the second interval, the magnitude of current is decreasing while voltage is held constant and therefore the magnitude of power decreases over time. Notice I've been careful talking about magnitude of current and magnitude of power. When we're charging both of these quantities are negative, so I am talking about the size decaying, perhaps, towards zero where you can see that the signed value is actually increasing but the magnitude is decreasing. That brings us to the end of this lesson and in summary, you've learned that our discrete-time, enhanced, self-correcting battery model of cell voltage has a fixed portion and an instantaneous portion at every time step. This observation is really important, it turns out to be critical for everything that we're going to look at this week regarding different ways of simulating battery cells and battery packs. The specific example that we looked at in this lesson, is having an ability to simulate a constant voltage scenario. We applied this to learning how to simulate a constant current, constant voltage charging profile. In the next lesson, you will learn how to exploit the same feature of the cell model having a fixed portion and an instantaneous portion to be able to simulate a constant power, constant voltage charging profile as well.