Developing Electrical Systems With Simscape Electrical - Introduction To Electrical System Modeling
Developing Electrical Systems With Simscape Electrical - Introduction To Electrical System Modeling
Hi, my name is Christine Li, and I'm an Application Engineer at MathWorks. Today we are going to kick off a video series electrical
power system and design. This video series will focus on how to use Simscape Electrical for many different electrical power
systems and design applications. It will cover microgrid and energy storage. The simulation of switch mode power supply, and
some trade offs for electrical system design.
For this video, I'm going to give you an introduction to the electric system modeling with Simscape Electrical. This will be a good
start point for those of you who are new to Simscape Electrial and want to do some modeling and simulations. And if you are
interested in other topics that we just mentioned, please check the following session in this video series.
OK. So this is our agenda. First, I would give you an overview of the Simscape Electrical, like what is it and why we need it. Next, I
would build a model of a simple electrical power system with Simscape Electrial to work with some essentials. And we also will
cover the topic like how to choose a software or how to change the model fidelities. Finally, I will share with you some resources
and technical support to help you get started.
OK, so we know that there are lots of benefits for the modeling and simulation of electrical power systems. And the very important
part here is how to build a model that can meet the requirements. Everyone have different situations. You may know the dynamics
of your system really well or you may have no idea of the inside of your system, but you can get some data from it, right? That's
why we have multiple methods for the modeling of the dynamic systems from the first principle based to the data driving based.
And as you can see here masterworks has many different tools right but specifically for today's topic, you may already know that
Simulink is a graphical based platform for the first principle modeling, which means you generally need to derive the equations to
build the model. However, sometimes it may not be realistic for us to derive the equations. It might be very time consuming or we
don't know much information about it. That's why the Simscape products can help us.
So Simscape is on the top of Simulink for physical system modeling. It is still based on the first principle modeling methods, but
instead of deriving the equation by yourself, it gives you many preview the physical components to build the system much easier
and quicker.
So Simscape has preview components for many multiple domains, like electrical, mechanical, thermal, and m but those are very
fundamentals right how if we want to do more advanced electrical system modeling. That's where the Simscape electrical can help
us.
So Simscape Electrical is one of the extensions from the Simscape fundamental for the electrical power system and design. It
provides the components libraries for the modeling and the simulating the electronic, mechatronic, and electrical power systems in
close models of semiconductors, motors, and components for applications such as smart grid, renewable energy system, or
electromechanical systems.
You can use these components to build your model for many different simulations or analysis, especially if your electrical power
system needs to integrate with other domains, such as mechanical, hydronic, thermals, which are all pretty common right? You
can use the components from the Simscape fundamental or other add-ons to build the whole system.
Now the highlight is that Simscape give electrical is on the top of Simulink, so you can leverage Matlab and Simulink for a system
level design, such as design control rhythms in Simulink willing or do some data analysis in Matlab, especially similar to Matlab
Simulink, systems give electrical also support state code generation. So if you're interested in things like real time testing, like
hardware in the loop, this is also something you can do with Simscape Electrical.
All right. That's an overview of Simscape electrical. Now let's go to Matlab to see how to use Simscape scale electrical. We will
cover three topics. First, I will build a simple model and work you through some Simscape electrical essentials. And then we will
talk about how to parameterize or change the model fidelity and how to choose the right solvers.
All right, so this is Matlab, and to get started with the model, we need the first open the Simulink. To open up, we first will see this
Simulink star page. Here you can create a blank model or use some templates from the list. You can also access lots of sim
examples that can be related to your design.
So some linear resources here that you can access, for example, the Simscape on-ramp can help you get started with Simscape,
and also the circuit simulation RAM is in other new courses. You can always get started for with a blank model, but here we can
see that Simscape also give you a lot of templates for different domains. Basically, it will have some price settings that is good for
this type of applications, and it comes with some essential blocks. So here we will just create a block from the Simscape Electrical
templates.
So when we open up this model, we can see that it comes with some initial blocks, like the software configuration block the ground
reference signal block, and you need a block to convert Simulink and the Simscape signals, and we have some scope to end the
spectrum analyzer to see some results. We also here have some hyperlinks that you can check out, some documentation or the
reference.
OK. So now we don't have anything here but I want to build a simple power system. So first step is we can open this Simulink
library. So let me just move this window side by side. OK. So when I opens a Simulink library, you can see that we have the
similarly fundamental library comes with a lot of blocks that you can use to build your model. But for the Simscape. it also comes
with the libraries. So Simscape has its fundamental libraries and some extended ones, like electrical is where we are going to cover
The fundamental library already gave you a lot of elements that you can use for your design, like electrical. It has some, like a
capacitor, diode, resistor, all the stuff that you can build very fundamental or simple electrical systems. But for more advanced
So for the Simscape electrical library, we have many subsections that covers like control or semiconductors or passive blocks or
even integrated circuits and so on and so forth that you can use. Quick or mention here is Simscape Electrical actually has two
main parts, all the stuff here from Simscape electrical call library, but we also have the other part. It's called a specialized power
system. And this one is generally used for large power distribution system modeling. This will not be where we are going to cover
To get started, we can add a voltage source, right? So I want to add some AC sources. So I can go to the source library. And you
can see from the list. We have many things like a battery or other like controlled or non-controlled voltage or current sources, and
these are like fuel cells, load flow sources, and more.
So here I would just start from simple. I'm going to just add this very simple voltage source for three phase. After I added it, I can
just drag in a job. So let me first adjust to open all the name to keep the block name be there. And then this is a voltage source
forever plug when you add it or you may not sure what is it, and what is it and the ports right. How can connect it?
So a really good resource here is, when you double click every block, you can open a documentation from here. When you open
the documentation, you can see that it will just give you all the information about this block, like how it has been viewed all the
equations under the hood, especially you can navigate to like ports, and then you understand what is this port present for, like is
present to a y center. And to the parameterization, every parameter has been explained.
This is documentation, and for this one we will know that the parameters here. It gave me a voltage, and I can serve others but
let's now just keep it as default. So I need to first connect this to the ground block. And next after I have this three phase voltage
source, I also want to add a load. So I can see here in the passive, I actually have many different types of passive block I can add.
I'm going to just add very simple like RLC load. I'm going to just add a three phase RLC three phase block, and I connect it to the
network.
So next, after I have this load added, I also want to add a converter to convert the AC to DC. You can go ahead and see that we
have this semiconductor and the converter sections. You can go ahead to see that we have some diode GTO or some H bridge or
half bridge RGB D MOSFET. You can use all them based on what you need, but here I would just go ahead to go to the converter
So I have to rectify. There's average one, but we'll use it later, but here let's just use a very regular one. This is rectified for the
three phase. So I just drag it and drop to add this rectify and then I can just connect it. Right now I have this DC side. For the DC
side, I want to add a resistor. So instead of go to the library to pick it up, if you know the name, a really quick way to add it is on
this canvas, any empty places, double click, you can tape the name. And there you will have see that there is some intelligence
recommends here, right. You can choose a one, and they're just so connected based on what you learned from your textbook.
OK. And that's it so now I have all the system be connected. I'm going to run the simulation. So I was just going to just change the
simulation time to 0.05 seconds, and for the solver here, I would just set up as a solver. We will cover it later, but here I'm going to
OK. So next, I can run the simulation. Right, as you can see it will compile, and then it will just really quick. After I run the
simulation, I definitely want to visualize the results, but how can I do it. So if you are familiar with Simulink, you will know that you
can use a scope to just a branch any single node in your model.
But Simscape is a little bit different because it's providing you those physical components. So those are all physical components.
You cannot directly drag and to connect it to a scope. Instead, you will you need a sensor to measure any signals you want to
measure. I can go to the sensor section. You'll see that we have lots of sensor available for you to use from simple to very
But here I want to pick a very simple one to measure this three phase current and voltage. And here we go, right? So we have this
current and the voltage be available. So to add it, I can just drag it and drop, and I want to feed it in here or here. So let me just
add it to here. I just need to break this line and connect it.
So now as you can see with the sensor, it will give me two ports, the voltage and the current. So for the voltage, I can connect it to
here. It will cover the color line, which is Simscape signal into Simulink that I can use a scope to see that. And for the current, I'm
going to stay connected to the spectrum analyzer. And next I can rerun the simulation. I can now have this. So this looks not really
good. I can just achieve the sample time to-- leave it small. And here we're going to use one microsecond instead. And let's run the
spectrum analyzer, and it will show me some frequency domain analyzing results. OK. So that's about how we can use Simscape
Electrical block to view the whole system model. And then we can use a scope to visualize that data. We can use a scope but
sometimes we go on to monitor many other signals. So use scopes for each of them will make our model look a little bit messy
So Simscape comes with a logging system that you can use with Simscape explore to analyze all the signals in your circuit. So we
can just open the Simscape Task explorer and you can see it listed all the components, you used your model and for each them, it
will have some data you can see right. I can double click, it will display on the the right side. This is my current, my voltage, right,
and also it has something that has been calculated. And it also comes with a system, that you can convert it to see the results. OK,
And sometimes, you may use Simulink as well to view the whole system, so you may have some Simscape data, but also Simulink
data as well. So instead of go here and there to check out the results a really convenient way is to use that data inspector, so you
can log all the data you want to see. So for example here, I'm going to just a log of this data I can just log it easily from here, and
I can also log all the Simscape data that you see in the Simscape explorer in this data use factor. To do so, I'm just going to set up
quickly it's in the model settings. We have a Simscape section, so I can record data in the Simulink data inspector, and next I can
And you can see the existing inspector load some new data. I can open it up. This is all from the model to the data you saw in the
scheme export, but this is the data way we have enabled. And we can see that for the Simscape it's all here that you can check it
out. So this is a data inspector and we're going to use it more in our later section.
OK good so that's about the first part. Everything essential has been covered. Next is about the model privatization and fidelity. So
you can change the model parameters for each of the block just by opening up. There will be something there that you can
change from the settings. This is a way to parameterize the system but sometimes, you may want to leverage the fidelity to a
more like a detailed model. This is also something that Simscape can support. So you can use Simscape or actually to do a full
range of fidelity modeling. And I'm going to use a model here to show you how it works.
So here how I just open the second model, which is about the fidelity comparison. So this is a model that almost is the same as
what we just created, but I just added some sensors to each side to mirror the voltage and current. The difference here is about
the rectify. What we use before is a regular rectify, and here I also view the same model that changes to an average-value rectify.
So what is the difference of those two? Those are all from Simscape Electrical, but the rectifying block, it can capture those
switching effects of the diode. However, the average-value one, it's a little lower fidelity, so it does not capture the switching
effects. So we can just run the simulation to see the results. But first let me just go to some initial data that will be needed by this
And then next step I will just compare the voltage and the current from the two different models to see if there are any difference.
I can compare the voltage or current, probably the current. I can click here to open the current. So as you can see, this is current
and this it the voltage. For the current, and this is the average current. We have three phase. This is one and we have a Iabc
average two and three, which are now the two phases. I will just add the one which is the regular rectify and the same scope and
rectify captures those switching events. So that's a difference, and you can also compare others here. So the main reason that we
change the fidelity of the model level is to run efficient simulation to answer some specific are question when you are interested.
For example, the average renewal converters or inverters, they are typically used when we are focused on the system level
simulations, but for more detailed converters, like the one we are using here, you will captures the switching events. It also will
have a longer simulation time. OK so you can definitely build your model based on where you need.
So that's about changing the model fidelities. And the next topic I want to cover is the solver. We have singled out the solver a
little bit in our first part when we build the model, but here I have an example to compare the different solvers and how the solvers
So as you can see here, we have built the same model. The difference is the left side where using all global software which is
actually the Simulink solver. And the rice side, we are using Simscape solvers itself to simulate or solve this circuit. For this circuit,
it is very simple. We have DC voltage stores connected with a resistor, and we are using voltage to measure the voltage in the
network. And this one network has a simple switch that has been controlled by the PWM wave.
And this one we don't have the software to be selected, so we're using Simulink solver and the right side, we check the local
solvers settings. So it was just the use of Simscape solver. And then we can run the simulation and compare how it looks like for
First, for the PWM waves, we can open it up. It looks pretty close. We don't see any difference. So both solvers can capture those
period up and down curves. Let's see the voltage. For the voltage, it's definitely different right? The blue line, which is using the
Simulink solver it goes over it can capture those minor steps. However, the yellow line, which the Simscape Local Solver one, it
OK, so that's a difference. The reason is actually because here we are using a pretty large sample time for the Simscape Local
Solver. To get it better, we can change the sample time. So here, I'm going to use smaller a sample time, which is 1e minus 6,
which is a 1 microsecond. When I type it in, it will apply, and I can rerun the simulation in this time. So as you can see, this time is
better. The Simscape local solver also can capture the detail the small step information.
So this is a comparison of the sovereign so sovereign is important to simulation, but when you get started and not sure which is
good for your studies, you can always keep the local solver unchecked and to try to use the Simulink global solver. And you can
see this is the global solver we are currently using. You can open the Settings from there. I'll go to the modeling and settings to
choose the one that you can use. You can add this knowledge now and choose a solver, or you can use your own preferred solvers
from the list of based on your models. And then you can try your simulation and compare to see if that's what you need.
Just a closing, so the last thing I want to cover is about the control design. So we mentioned in the beginning that Simulink is a
client that can use all the tools to fuel your model. And for example, you can use Simulink design control for your power electronic
So here this is the example that I would not dive into the detail, but I wanted to show that we have created an AC system and this
system with AC/DC converter in telecom. And this has been viewed in Simscape Electrical. And we have some batteries, fuel cells,
generators. For example, for the battery converter and the controllers we have some system, but for the control we actually use
first step, but this was the active and reactive power control. We actually leverage a Simulink to do the PID control. So this is a
really good thing where you can leverage all the tools to build the model and run the simulations for what you need.
All right, now let's back to the slides. So in this video, we introduced the Simscape Electrical and use the demo to show you how we
use Simscape Electrical. And finally, I want to share with you some useful resources and MathWorks technical support to help you
So we have many different types of engineering support to help you, such as trainings, consulting, and also our technical support.
So if you are interested in any of those support, please check out the website for more information. We also have some training,
for example, we have the on-ramps which are free training that you can get started with different tools. We also have the paid
trainings, and here are some for the Simulink or the control Simscape and state flow. Please check out those links to explore more.
Another very important thing is the shipping examples. So Simscape Electrical has a lot of shipping examples, covering many
different applications, and we keeping adding more in each release. So please check out to see if you can find any use for example
that is close to your design. Thank you. That's all about the video.