Boost Converter – Simulink Model Using MATLAB Embedded Function

In this post, I am going to talk about modelling dc-dc power converters using MATLAB’s user defined function block. Doing so saves a lot of time and it’s much more easier as compared to the Buck converter model in which each dynamical equation is implemented using blocks. Doing so is not only time consuming, but tracking back and finding out errors is hard especially when the system becomes larger. In this model, I have used as few blocks as possible.

The Boost converter circuit is shown in fig.1. I have accounted for the parasitic resistance in passive components as well as the ON resistance for active device.

Fig. 1: Boost converter circuit

Inputs the converter model are:

  • Input voltage V_g
  • Voltage control (duty cycle) d
  • Load current i_{out}

Converter outputs:

  • Capacitor voltage v_C
  • Inductor current i_L
  • Output voltage V_{out}
  • Input current I_g

Step 1:

  • Start Simulink either using the MATLAB command window or by clicking the Simulink button on the toolbar
  • Create a new Simulink model file and save it as boost.mdl
  • From the Simulink place 3 instances of constant block located under “commonly used blocks”. Also place a subsystem block as well a scope block.

At this point your model file will look something like fig. 2. Notice that I have renamed the blocks to identify their respective characteristic.

Fig. 2: Initial set up for Boost converter model

Step – 2:

  • Open the Boost converter subsystem block by double clicking on it.

Notice the default connection between in1 and out1. Delete this connection.

  • Add 2 more instances of In1 and 3 more instance of Out1 found under commonly used block
  • Add an instance of subsystem, mux, and demux found under commonly used block
  • Navigate to user-defined functions and add a MATLAB Function block to your model file
  • Go to the continuous library and add 2 instances of integrator block to your model file.

Make the connections as shown in fig.3 and rename your blocks appropriately. Notice that by default mux block has 2 inputs and demux has 2 outputs. This can be changed by double clicking on the respective blocks and changing the number of inputs/outputs

Fig. 3: Boost converter subsystem block

Step – 3:

  • Open the PWM system block, and delete the default connection between In1 and Out1
  • Add a repeating sequence block found under Sources
  • Go to Math library and add a subtract block
  • Finally from the discontinuous library add a relay block and make the necessary connection as shown in fig. 2

Fig. 4: PWM subsystem block

Open the repeating sequence block by double clicking. This block lets you set up switching frequency for the converter as well as the amplitude V_M for the PWM signal. Rather than setting it to some default value, this parameters can be set as variables so that the user has control over changing them for different design.

Fig. 5: Setting parameters in repeating sequence block

Step – 4:

Going back to the user defined function, this is where we will enter the converter state equations. You can refer to the boost converter post to get an in-depth view of how these equations are derived.

When the MOSFET M_1 is on, the behavior of the converter can be captured by the following equations,

v_L = V_g - I_L\left(R_L + R_{on}\right)

i_C = - i_{out}

I_g = i_L

V = v_C - R_{ESR}i_{out}

Similarly, when MOSFET switches off, the equations are

v_L = V_g - I_LR_L - V

i_C = I_L - i_{out}

I_g = i_L

V = v_C + R_{ESR}\left(I_L - i_{out}\right)

Over one switching period T_s, the equations can be combined and represented as follow:

Inductor voltage,

v_L = \left[V_g - I_L\left(R_L + R_{on}\right)\right]*D + \left(V_g - I_LR_L - V\right)\left(1 - D\right)

Capacitor current,

i_C = -i_{out}*D + \left(I_L - i_{out}\right)\left(1 - D\right)

Input current,

I_g = I_L*D + I_L*\left(1 - D\right)

Output voltage,

V = \left[v_C - R_{ESR}i_{out}\right]*D + \left[v_C + R_{ESR}\left(I_L - i_{out}\right)\right]*\left(1 - D\right)

Solving them, the equations simplify to,

v_L = V_g - V\left(1 - D\right) - I_L\left(R_L + R_{on}D\right)

i_C = I_L\left(1 - D\right) - i_{out}

I_g = i_L

V = v_C + R_{ESR}\left[I_L\left(1 - D\right) - i_{out}\right]

The above equations can be entered directly to our MATLAB function. The 5 inputs via mux are stored in an array format. The code should look something as follow:

function y = CCMBoost(u,L,C,RL,Ron,Resr)

% Inputs:
% u = [Vg D iout v_C i_L]
% Parameters:
% L, RL, C, Resr, Ron
% Outputs:
% y = [dv_C/C di_L/L Vo ig]

Vg = u(1);                  % Input voltage
D = u(2);                   % Switch control
iout = u(3);                % Load current
vC = u(4);                  % Capacitor voltage
iL = u(5);                  % Inductor current

dbar = 1-D;

% State equations
Vo = vC + Resr*((iL*dbar) - iout);          % Output voltage
Ig = iL;                                    % Input current
iC = (iL*dbar) - iout;                      % Capacitor current
vL = Vg - (Vo*dbar) - iL*((Ron*D) + RL);    % Inductor voltage

% Output
y = [iC/C vL/L Vo Ig];

Save the MATLAB function. Now we want the parameters be set as variables so that the user can change them. In order to do so, select edit data/ports under tools as shown in fig. 6

Fig. 6: User function parameters

In the next window, select you will find a list of your I/O ports as well as the parameters specified in the function file. Select the input port u and change it’s size to 5 so that it matches the input array.

Fig. 7: Changing data port u property

Also, change the scope of L, C, R_L, R_{ESR}, and R_{ESR} from input to parameter. This can be done simply by clicking on the respective input and selecting parameter from the drop down menu. At the end, your port manager window should look as follow:

Fig. 8: Port/Data Manager

Going back to the Boost subsystem block, you can set up initial conditions for the inductor current and capacitor voltage. In order to do so, open the capacitor integrator block, and type in a variable name under the initial condition field. Do the same for inductor integrator block as well. I have named them as vC_0 and iL_0.

Fig. 9: Configuring initial condition variable

Now, go back to the starting, open the scope block and open the scope parameters. Under general settings for scope parameters, change the number of axes to 4. Then under history uncheck limit data points to last. Click apply and connect the scope inputs to the boost converter outputs.

Fig. 10: Changing scope setting

Fig. 11: Final connections

Right click on the Boost subsystem block, and select mask subsystem. This will open mask editor where you can create a UI for the user to change the boost converter variables and parameters. In the mask editor, click on parameters tab. Then add all the variables via the add button. Make sure that the variable name matches the ones used within the subsystems. Your final mask window should look something as follow,

Fig. 12: Mask editor

Apply your settings and close the editor window. Now if you try and open the Boost converter subsystem block you will see a dialog box as follow,

Fig. 13: Setting parameters

I have set the parameters as follow:

Input voltage: V_g = 12 V

Required output voltage is 30 V. Hence,

Duty cycle, D = 1 - \frac{V_g}{V} = 1 - \frac{12}{30} = 0.6

Load resistance, R = 50 \Omega

Load current, i_{out} = \frac{V}{R} = \frac{30}{50} = 0.6 A

Switching frequency, f_s = 100 kHz

Inductance L = 120 \mu H

Inductor series resistance R_L = 10 m\Omega

Capacitance C = 50 \mu F

Capacitor series resistance R_{ESR} = 1 m\Omega

Switch on resistance, R_{on} = 10 m\Omega

PWM amplitude V_M = 1

Initial inductor current i_L(0) = 1.5 A

This value for inductor current was obtained using the fact that the average inductor current in a boost converter is given by I_L = \frac{V}{\left(1 - D\right)R}

Initial capacitor voltage v_C(0) = 30 V

You can even leave the initial condition set to 0.

Now that all the parameters are configured, its time to simulate and verify that our model produces the expected result. Save your design and go to configure parameters under simulation. I have set the stop time to 100 ms and step size to 1 \mu s.

Fig. 14: Simulation parameter

Now run the simulation. If everything works out properly, then you will get the following result.

Fig. 15: Simulation result

I hope that it all works out for you. In case it didn’t then you can download this file and rename the extension from Boost.pdf to Boost.mdl and re-run the simulation or figure out your error.


92 comments on “Boost Converter – Simulink Model Using MATLAB Embedded Function

  1. Thanks a lot mate,very helpful.Can you make a tutorial on how to obtain photovoltaic characteristics I-V and P-V curve using Matlab/simulink.

    Thanks in advance

    • I am not to familiar with photovoltaic’s. Although, I snooped around and found some details about it. I guess you are looking forward to plot IV curve governed by
      I = I_L – I_D; where I_L is the current generated by photoelectric effect and I_D is the diode current. Lemme know if that’s what you are looking for; I can generate a simple MATLAB function for that. In the mean time you can find more info on the following link:

      • Yeah I want you to simulate the ‘Figure 2 – Simplified Equivalent Circuit Model for a Photovoltaic Cell’ in this link on Simulink. I want to obtain IV and PV curve for different value of Temperature(T=25,35,50) and Insolation(G=200,400,…1000 W/m2)

        Please make a tutorial on this.I found your tutorial really helpful!

      • thank u sir …god blass u…sir i want solar pv system matamatical modal…simulation of pv array with mppt controller…plz provide..matlab coading..with simulatsion

      • Hi,
        first, thank you very much your help. I want to simulate a buck-boost converter with Simulink. I’ve follow your publications with buck and boost converters because I want for to design its performance. Do you have some publication about Buck-Boost converters? Thank you again.

  2. I did exactly what you did, but did not get the same graphs. I tried to download the PDF but it isn’t supported. You have “Vo” in your matlab code, does that effect the output since you labeled it “vout”? Thanks

  3. Hi, would it be simpler to use the Simpower?
    If not, what is the advantage of that one over a converter built using Simpower only?


    • From what I have understood is the fact that Simscape/Simpower are physical modeling environments. Particularly Simpower involves electrical environment, you don’t need the dynamical equations for the system in order to model it’s behavior. On the other hand, is a block level environment in which if you wanted to model a system, you need to know the dynamical equations, or the relationship between system input, system output and system response. I hope this helps.

    • Go to the link and look at the slide #17 in order to get an overview of a closed loop system, in case you need some background.

      On the main configuration, where you will have inputs, boost converter block and scope, you will need a gain block which takes “vout” as an input and steps it down to meet something close to “Vref”. Usually, this is shown as resistive divider in circuits. Place a subtract block which takes “Vref” and “vout” as input and outputs the error signal. This will feed into your compensator. Since you are implementing PI, you will need an integrator block taking the error signal as input and the output feeds into a gain block, which will be your compensator gain. Once that is all set up, delete the constant block for duty cycle d. Now the output of the compensator gain will need to be feed to duty cycle input. That’s it, you are all good to go.

  4. I am trying to design dc-dc bidirectional converter to be used for battery charge and discharge, the problem is how to model the converter to find the transfer function in order to design controllers to control the converter via PWM,, the Simulink model is functioning but the control is poor, i know modelling the bi-directional dc-dc converter should be done using averaged state space approach and then the PWM is also to be modelled before I can design PD controllers to regulate and control the power for charge and discharge the battery
    It would be great help if you could guide me in how to model and design bi-directional dc-dc converter book-boost,

    • Hi nuflia,

      I am also trying to design bidirectional dc-dc converter to charge and discharge the battery connected to a microgrid. I am struggling to design. Did you get any ideas or any materials about this. If so, please send me the files to


    • Hello Nuflia,

      I am also working on design of bidirectional dc-dc converter for charging and discharging the battery. I have the same problem with controllers. Please can you give me ideas how did you solve the problem. If possible, can you send me the model for reference. I hope you understand my concern, and would be great help in guiding me.

      thank you.

  5. Outstanding work this is …but my simulation isn’t giving the same result and i couldn’t download neither pdf nor mdl file (showing page not available) Pease help me out as i am dire need of it in my project of isolated solar system .
    Please just mail me the complete mdl file of the same at ,
    so that i could find my error.


  6. hello the tutorial is so usefull. how to implement the boost converter for multiple inputs? can u please give any tutorial for that//

  7. Hi thanks for the tutorial. however i get an error saying
    “Unable to locate a C-compiler required by Stateflow and MATLAB Function blocks.
    Use ‘mex -setup’ to select a supported C-compiler.”
    will you be able to help me with this ?
    thank you!

  8. awesome………….great……………
    dear sir,
    I am a student and very much new to Simulink.
    I am working on a project from past 2 months called single phase pwm converter.
    for which I have to convert AC(100v) to DC(200) ie boost converter.
    I learned much from still I could not able to sort out my problem.
    I designed my own control logic to get the regulated output to 200v(dc).
    my converter is based upon IGBT bridge.
    main problem is how to configure the configuration parameter to get the output regulated within 1 or 2 seconds. Every time I have to wait for more than 1 hour.
    PI block is also giving me trouble when I am telling it to tune on his own.
    so many problems are there.
    I just want to show you my .mdl file so that u could help me out.
    because I cannot explain everything over here.
    will you please give me your mail id so that I can send you .mdl file.

    I will be very much thankful to you if you will help me.
    thanks and regards

  9. Hello,
    I have matlab 2008b version and I did as you showed here. I have this error

    Embedded MATLAB Interface Error: Can not resolve Simulink signal object ‘y’ for output port 1 of ‘Boost/Boost/Embedded MATLAB Function’.

    Also the Matlab function has now 6 entries (u, L, C, RL, Ron, Resr)

  10. Hello,
    I have a problem when i try to donwload the file “boost.pdf” i can’t rename the file for trying simulte it in matlab simulink, if you can help me …

  11. I can modify the circuit to get Vout=12v with Vin=6 or less and Pout=200watt. It’s for a fuel cell with Iout = 16.66 A

  12. i also tried this boost converter..but not working.when i took the mask editor and entered the 9 variables..but while taking subsystem i am only getting 7 variable to enter..can anybody give a solution to this.even if i simulating with out considering this error showing in the pgm..

  13. sir
    i simulated this but i am getting error in code as index expression out of bounds.attempted to acess elements 2.the valid range is 1-1.
    plz do reply as early as possible..i ve written the same code..
    thanks in advance

  14. I have a problem in the simulation !!!
    Inferred size (‘[1 4]’) for data ‘y’ (#23) does not match specified size

  15. I want to design boost converter using dynamic equations and design should also work in discontinuous conduction mode

  16. hi, tnx for your helpful tutorial
    i want to control the duty cycle for MPPT (maximum power point tracking) purpose, and i know that it should add ineasted of repeating sequence in PWM system….but i can’t open the block since it mask!!! what should i do? could you please help me to control the duty cycle?

  17. It’s remarkable to visit this web site and reading the views of all
    friends regarding this piece of writing, while I am also eager of getting

  18. Hi, I am designing the community based solar photovoltaic system . I am trying to implement this model but am not getting the desired result.Can anyone mail me .mdl file of this outstanding work in my email

    Thanks in advance

  19. aslaam o alaikum

    we want to design boost regulator at 12 v input to 440v dc. we try your model. but we try to get the output at 440v. it will not show us required output.
    please give us some idea and we have a very short please…

  20. Can you send me the mdl. model to, please.
    the link on this website does not work and I’m getting some errors, like:
    Inferred size (‘[1 4]‘) for data ‘y’ (#23) does not match specified size
    Thank you.

  21. pls send me the the details of matlab simulation of closed loop pi control boost converter in continuous mode.because in closed loop voltage is not boosted up as desired as we got for open loop operation. pls send me the details value of each end every parameter. I want to boost the voltage from 24 v to 300V.

  22. Hi eprimes(Swapnil Christian),

    i’m glad that i came through your site. and i hope you can reply to my comment here.
    i’m doing an assignment about boundary conduction mode by using boost converter.
    i know that your tutorial is for CCM but i just followed it for better understanding of boost converter. However, I’ve come across an error

    [Error evaluating MATLAB Function parameter data ‘Ron’ in its parent workspace.

    Caused by:
    Undefined function or variable ‘Ron’. ]

    which I think it might be better if you can explain why/how to correct it.
    Furthermore, nothing could be better if you can show me one-by-one step for BCM(boundary mode controller) using boost converter.

    your cooperation is highly appreciated.
    feel free to contact me at
    thank you

  23. Hi.. can anyone help me to design a boost converter with low power application. The input voltage is too small which is 0.15 V. I want to use boost converter to step up that voltage to be 1.5 V. It is suitable to use boost converter to boost up that smallest input voltage?

  24. Thanks a lot for sharing this information
    i simulated this but i am getting error and i couldn’t download neither pdf nor mdl file (showing page not available) Pease help me out as i am dire need of it in my project of PV system .
    Please just mail me the complete mdl file of the same at

  25. Hi,
    I have created an averaged model for the boost converter as you did; however, when I linearized the model to get the bode plot for the control to output transfer function, it gave me a blank plot. I have worked out a similar model for the buck converter and it worked just fine. Any idea how I can linearize your model and get the bode plot from d to Vout?

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s