Getting Started with Simulink - MATLAB & Simulink
Video length is 4:23

Getting Started with Simulink

From the series: “How To” Video Series for Biomedical and Pharmaceutical Applications

Learn what Simulink® is, why is it used, and how you can use it to model bioreactors and medical devices such as infusion pumps. Find out how to get started in just a few minutes.

Published: 22 Sep 2021

Hello, everyone. Paul Huxel from MathWorks. Today I'm going to give you a brief introduction to Simulink, and demonstrate how you can get started modeling the behavior of your complex systems. For example, here we see Simulink being used to model and test the design of an infusion pump, which is a medical device used to deliver fluids into a patient's body in a controlled manner.

At this top level we see interconnected blocks modeling a user's interaction with the embedded software and physical components of the device. Clicking into the plant model, we see a DC motor and drive system have been implemented to depress the plunger. Opening the delivery line block, we see the tubing and flow sensor are being modeled with Simscape components.

One of the advantages of creating a full system simulation is we can easily and safely inject faults into the system to test that the device and software behavior as required. Here we've introduced an inclusion into the delivery line just before the one minute mark. As design the system detects the resulting resistance and commands the motor to stop applying a force to the plunger.

The model we'll be building is based on the simple bioreactor model we posited in our recent webinar on batch process optimization. You can learn more about this problem by watching the video on our website. But for now, all you need to know is that the ordinary differential equations you see here, are simple representation of the biomass growth and death cycle of an organism as it consumes and depletes a nutrient.

In the webinar, we integrated this system of equations using MATLAB. By comparison, MATLAB is a textual programming language written with lines of code while Simulink is a graphical environment used to design, implement, and test multi-domain systems. To begin, I've created a MATLAB script to initialize some variables we'll be using and Simulink. Well then launch Simulink from the Home tab in MATLAB.

There are many examples to help you get started, but in this case, we'll start fresh with a blank model. Instead of requiring users to remember to run our initialization script, we'll add a callback to the model properties to automatically run the script when the model is loaded.

Next, just as we added comments to document or MATLAB script, let's annotate our model with the equations we'll be implementing. You can find hundreds of built in blocks in the library browser, but in our case, since we know we need to integrate these equations, we can just click on the Canvas and start typing to find an integrated block. Was that the initial condition of the nutrient using the and not variable we created earlier.

As indicated in the first equation, we'll need to multiply the nutrient by the negative of the k1 kinetic parameter. This can be done using a gain block. To complete the first equation, we just need to connect all the blocks together. Had we written our equation in matrix form, we could use a matrix gain with an initial condition vector to implement both equations at the same time. However, for the sake of practice let's continue with the scalar implementation.

As such, next we'll implement the second equation. To do so, first of all add another game block then multiply the nutrient signal by the K2 kinetic parameter. Next, we'll add a summation block since the time rate of change of the biomass is the sum of two terms. To compute the biomass in the second term, we'll need another integration block and similarly we'll set the initial condition using the B not variable in the workspace.

Finally, we'll use another game block to scale the biomass signal by the negative k3 kinetic parameter, and then connect the result to the summation block to complete the loop. With our model complete, we'll enable data logging on the biomass and nutrient signals, reduce the stop time from the default value to three time units, and run our model. Since we enable data logging, we can quickly view current and past runs in the data inspector.

I hope this quick introduction demonstrated how easy it is to begin building models with Simulink. When you're ready to get started, please check out our free Simulink, Stateflow, Control Design, and Simscape Onramps available on the Simulink start page. Like the MATLAB Onramp, these interactive tutorials will provide you with a practical introduction to these tools and about two hours each. And if you'd like to leverage Simulink as a platform for model-based design, please visit the Simulink product page to learn more. Thanks for watching.

Up Next:

View full series (10 Videos)

View more related videos