Virtual Labs with MATLAB and Simulink
Overview
Developing new virtual lab activities or moving a laboratory course completely online while achieving learning objectives is challenging. It can be difficult to reproduce the collaborative and interactive learning environment that helps develop the soft skills needed for global industry. In this webinar, you will find ideas and resources for creating online labs using MATLAB and Simulink.
We will explore different approaches to implementing online labs including simulations, remotely accessed hardware, and home lab kits. Examples of these approaches using MATLAB and Simulink will be presented. We will also discuss strategies for creating engaging student experiences by incorporating tools within MATLAB and Simulink that enhance interactivity such as MATLAB apps, live scripts, and Simulink Online.
Highlights
- Discussion and examples of virtual, remote, and hardware at home labs.
- MATLAB apps and Simulink create visually engaging lab activities.
- Live scripts for exploring course concepts and creating interactive reports or electronic lab notebooks.
- MATLAB projects to track group work and control your lab activities.
About the Presenter
Sumit Tandon is a Senior Team Lead in the Customer Success Engineering team at MathWorks. He has a BE in Electrical Engineering from Jadavpur University, India and an MS in Electrical Engineering from the University of Texas at Arlington. He has been at MathWorks for over 13 years, advising MATLAB users in the industry and academia in the domains of image processing, computer vision, physical system modeling and simulation, embedded systems, data analytics and high-performance computing.
In his current role he and his team manage the technical relationship of MathWorks with key academic institutions and systems in western US, Canada and Latin America. Here, he partners with faculty, researchers and research centers in the exploration and effective use of MathWorks products, and programs, for curriculum and research. To bring the industry perspective and facilitate exchange of ideas – he also serves on several industry advisory boards in the University of California and California State University system schools – including UC Irvine, CSULB, CSULA – and also engineering education focused organizations like ECEDHA.
Recorded: 13 Nov 2020
Hello, everyone. Welcome to this talk on implementing virtual labs with MATLAB and Simulink. My name is Sumit, and I am a customer success engineer at MathWorks. In this role, I am part of a team of engineers and scientists at MathWorks who partner with educators and researchers around the world, and help them explore and adopt MathWorks products and resources for curriculum and research.
The goal for this talk is to provide you with a very high level overview of the types of labs that MATLAB and Simulink can support, and start a dialogue on this topic. If you would like to have a deeper discussion, we would be happy to do that offline. Before we take a dive into the virtual labs, let's chat a bit about the impact of technology.
Digital transformation has been impacting everything around us. Be it, the doorbell that started its life as a simple mechanical device, to something which now has a video camera, a motion sensor, and a smartphone interface that can even recognize the person who is at your door. And this digital transformation is impacting both industry and academia.
In industry, digital transformation is revolutionizing how things are done across the board. A typical example is using the digital print of heavy machinery, in this case a triplex pump. Along with machine learning techniques to build a mathematical model that can predict when equipment needs maintenance, and in turn maximizing the ROI and lifespan of the equipment itself.
We have also noticed this shift in academia with educators like Professor Nielsen from UC Davis, adopting innovative approaches and technology to take the courses, and even good projects online. And we want to keep this trend moving.
In the short term, we have taken our instructor-focused model of facilitating group work within students, experimentation in the lab, and some computational work, and moved it online. Long term, we want to take the lessons we have learned back to our instructor-focused model to improve learning outcomes, and make our classrooms more resilient. This can be done by adding new modes of interactivity to engage students, complementing lab hardware with simulations, and exposing students to the growing field of industrial workflows.
Talking about workflows, let's consider the case of labs. In a typical lab workflow, we start with some new concept introduced in the classroom. Then, we explore the background theory and solve back of the chapter problems to further explore or reinforce the concepts.
Then we move into the lab experiment, or better understand the behavior of the system and collect data, or even try out different scenarios. Next, as a student, we would take what we have learned in the class, or in the labs, and could build something, for example, a software app, or build and program a hardware. And finally, synthesize the learnings and report back, which can lead to advancing the topic or introducing the next step in the project of the lab.
And this should now look very familiar, since this is applicable in case of class projects, research projects, and even in the industry. Of course, depending on the type of the project, some of these steps might be skipped, or re-ordered, et cetera.
The question then becomes what do labs look like in an online or hybrid format? From our experience working with our partners in industry and academia this year, it seems that we are converging to these three high-level categories. Please do share your thoughts on this in the chat window as well.
First, fully virtual, where a process, test, apparatus, or other activity is simulated, or is completely software- or data analysis-based.
The second one is hardware at home labs, which incorporate kits or mobile devices that students have in their possession, or fairly easy access to. And these could include hardware like mobile devices, Arduinos, Raspberry Pis, National Instruments, or MyDAC instruments, et cetera. Some of these might be student-owned, or perhaps they're supplied by the institution for the duration of the project.
The third one is remotely-accessed hardware, where equipment that exists on campus or another location is viewed, access, or controlled by the students remotely. And these typically would be industrial-standard equipment.
Now, each of these categories vary widely in terms of realism, complexity, cost, logistics, and most importantly, student experience. So it is important to choose the best, or a combination, of these approaches to make sure that all the lab objectives are met and maximized. Be it exposure to the scientific method, or learning how to do things, like acquire and process data, or gaining experience with industrial tools and workflows. Let's take a look at how MATLAB and Simulink can help you implement these three types of approaches.
To get started, let's take a look at an example of a fully virtual lab from the electrical engineering discipline. So for this demo, we will explore the example of an RC circuit, which is a very fundamental electrical circuit with a wide variety of applications as timers, windows, et cetera. A topic like this is typically covered in the first- or second-year engineering courses. The goal of this demo is to introduce the concept of RC circuits to the learners, and reinforce the concepts, and create exploration opportunities with exercises in labs.
So we will start by deriving the equations associated with a typical RC circuit in the symbolic domain and creating some plots in order to explore the current and voltage in the circuit. Then we will switch to the numerical domain and explore the effects of availing the circuit parameters on the current and voltage.
We will then use a Simulink model as a virtual lab and explore the circuit, perhaps add and remove some components, similar to what would happen while working in a lab with real equipment. Finally, we will bring the data from virtual lab to MATLAB for further processing and analysis, and reporting observations and conclusions.
If you are new to MATLAB or Simulink, don't worry about it. I will also discuss some resources at the end to get started on MATLAB and Simulink as well. So now let's switch over to MATLAB and see how we can implement or set up a virtual lab like this using MATLAB and Simulink.
Just in case you're not familiar with MATLAB, this is what a MATLAB desktop looks like. And in particular, I am going to use a live script and a Simulink model for this particular demo. So this is live script, which has the entire demo setup. And looking at it from a different perspective, this can also be looked at as a teaching or instruction tool, as well as maybe even a template project that can be given to students for filling out.
Coming back to this example, you'll see I have a table of contents on top that highlights the outline of the whole example. But I just stepped to it real quick to show you how this is set up, and how some student can use this and explore this concept around RC circuits. So I have some introduction and learning objectives here in the beginning. And then I'll be looking at some-- let me actually clear out the outputs, so we can start from scratch.
So you start with a basic circuit diagram of an RC circuit here, with resistance, capacitance, and a switch, and a voltage source. And then these are some initial voltage and current equations that are introduced to start talking about the mathematical representation of the circuit, and the relationship between current and voltage, and the different circuit parameters. In order to explore this in MATLAB, I'm actually going to use the symbolic math toolbox, and set up the a symbolic version on this equation.
If I run this section by clicking on this blue bar on the left-hand side of the live script, that executes the section and that sets up my symbolic expressions. And you can see the output-- the current and voltage expressions on the right-hand side being displayed. Now, in order to start exploring the mathematics behind the RC circuit, I'm going to do a couple of things. In this particular case, I'm going to set some starting value for the capacitance, the resistance, and the voltage source. And I'll set all of those to 1. And then I'm going to use the Command-F plot to plot the voltage and current.
So if I just run that, they can see the initial values that I have set up for the voltage and current. And then you can see in this plot what the voltage and current look like. Now, the next thing that I'm going to set up would be to explore the effect of varying the subject parameters. But it's tough going to work in the symbolic domain. I'm going to switch things around a bit. And I'm going to switch to the numerical domain. And if I use this command MATLAB function, that will give me numerical versions of the voltage and current equations, and give me function handles like these.
In the next section of this live script, I have actually set up a couple of these interactive controls-- some of these sliders and an editable box here where I can vary the values of these parameters. And if you want to see how you can include some of those controls, like edit fields and sliders and so on, you can check out the Insert tab and Live Editors.
Once my interactive controls are set up in the script, I can easily play with those. And then I can vary the values of the resistance and capacitance, in this case, and then I can get a sense of how changing those values is impacting this basic RC subject. And this is kind of very similar to, in some ways, working on problems in the back of the book, but in a more interactive fashion that can help build intuition about these concepts and topics a lot faster.
Once, as a student, I have some idea about what is going on in the circuit, now I can switch towards going to a lab. And in this particular case we'll be exploring virtual lab, which is being set up in the form of a Simulink model. Now, before I open up the Simulink model to show you the virtual lab, what I'm going to do is I'm going to set up some parameter values that would be used in the Simulink model, which are basically voltage and resistance, capacitance, and some of those parameters. So let me just, under Section 2, set up these parameter values, and then open up the Simulink model.
So this is what the Simulink model of this RC circuit looks like. In case you're not familiar with Simulink, it's a block diagram-based environment where you can set up your system design in blocks like these. And just to show you what some of these blocks represent, of course, the first block here is a voltage source. I can double click on the block and see what's inside that. So you can see there's an ideal voltage source here, with a resistance. Then I have a switching circuit here. I have centered over the switching circuits so I can do some advanced manipulation as well.
I can look at what's inside the block for the switch. There's a pulse generator, which triggers the switch circuit. So that is the-- I guess, in some some way, it's the support setup of this circuit. And the main components here are the resistance and capacitance. Now, if I double-click on the resistance block, I can look at the block parameters. And I can see that there's a value R1 here, which I defined the live script of a few seconds ago. And then there's a capacitance here.
And if you look at the circuit then it is pretty similar to what it would look like in real lab situations. You have resistance and capacitance connected in series, and the switching circuit, and then even a voltage source.
So what do you do after this? So once something like this is set up in Simulink, and then the parameters have been defined, all I have to do is click on the Run button. And this is going to simulate the circuit over time. And then I can view the response of the circuit. And to view the response of the circuit, I can launch the Simscape Results Explorer and look at the different circuit components.
So I click on the capacitor, and I can see the voltage and the current associated with the capacitor. And it says the circuit is set up for one charging and one discharging cycle. So that's why you see drops like these. And similarly, we can look at the resistor as well.
Now, in order to continue the exploration, what I can also do is I can easily add and remove more components from the circuit. Let's say, for example, if I want to add another resistor to the circuit, which is already added here, all I have to do is just comment it. So I can un-comment it. And it becomes an active part of the circuit. And I can now click on the Run button again. And I go back to the same Simscape Results Explorer. Now I see R2 showing up here as well. And this is the voltage and current characteristics for this component in the circuit. So you can see how easily we can actually add or remove components, and we can write things out, and then explore this circuit in a virtual lab environment to gain better understanding of the topic.
So I showed you some simple components here. But if you want to add more advanced components here, if you want to create labs for other topics, you can explore the other blocks available in your installation of MATLAB and Simulink. And you can see there are a lot of other things that Simulink can do.
To give you a few ideas here, from an interactivity and engagement perspective, you can use some blocks on the Dashboard Library. And then you can make the Simulink models a lot more engaging and very similar to what actual lab instruments might look like. As you can see, there are lots of libraries available that you can use.
Continuing in the vein of electrical circuits, if you look at the Simscape electrical library, there are lots of other components available here. So you can actually create fairly advanced models, and Simulink models and labs that can allow you to explore pretty advanced machinery in a simulation environment.
Now the typical next step, as you talked about after the lab, is maybe recording data and analyzing the data. If you want to take an approach like that, then it is fairly easy to bring data back from a Simulink model into MATLAB for the analysis. And I have a small custom function set up at the bottom of the script that you can explore later on, which can actually render Simulink models and bring the data back. And in this way, you can even set up Simulink models to be a source of scientific data that can be used to create data analysis-type projects.
In the next few sections of this live script, I just added a few other ways of analyzing the circuit, or extending the circuit. For example, adding components to the circuit, or changing the switching frequency, or changing the voltage source, and even setting up experimentations or exploration of RC and rectifying circuits. Now, as you can see, not everything is filled out right now. And some of the sections are empty. So this live script can even be shared with students as a project template that they have to fill out. And then they have to submit it back as a report.
If the key is how do you create a report from a live script like this, you can go to the live Editor tab, and click on Save, and export to PDF. And if you do that, that is going to generate a PDF report that potential students can fill out and submit as part of the lab project. So this is what the generated report looks like.
So let's go back to the slides for a minute. So just to recap, in this demo, we saw how to introduce the concept of RC circuits, explore it mathematically both in the symbolic and numeric domains, perform virtual experiments with Simulink, extend the exploration to advanced concepts, and capture everything in a report. Just for a reference, the products used in this particular demo of MATLAB are Symbolic Math Toolbox, Simulink, Simscape, and Simscape Electrical.
Changing gears a bit, let's talk about using a Hardware-at-Home approach for labs. In this particular case, we will discuss how to introduce students to the concepts around Deep Learning using a smartphone. So the assumption here is that they have already been introduced to some theory around Deep Learning in the class. And the approach here is to use a mobile device and an industry-standard pre-trained GoogLeNet network to explore the concepts around Deep Learning with a mobile device camera.
So I won't be able to show you anything running, per se, but I will step you through how this whole thing is set up. And then you're welcome to explore it offline on your own. And if you have any questions, do reach out to us. So all the details are actually available on this link at the bottom of the slide. So let's go there.
Clicking on that link actually brings up an example that we actually ship with our documentation. And this is actually the entire workflow setup right here. The first thing that needs to be done is to set up MATLAB Mobile on your iOS device. The next thing to do is actually to connect to the camera on the device. And that can easily be done by creating a mobiledev object.
So while we are focusing on this Deep Learning example, and using images from the camera, just keep an eye on what has been displayed here as properties of the mobiledev object. So as you can see here, MATLAB Mobile can actually capture data from different sensors on an iOS device, like the acceleration sensor, the angular velocity sensor, magnetic sensor, orientation sensor, and even position sensor that provides GPS latitude, longitude information and so on. So you can easily create different types of projects using even a mobile device or a smartphone.
So in this particular case, as you can see, the demo goes to connecting to the camera, particularly the back camera. Then it goes on to show how to load a pre-trained GoogLeNet network using the Deep Learning toolbox, and then use that network in order to classify and display the acquired image.
So while it might look pretty simple, and just a few lines of MATLAB code, this is actually pretty advanced. Well, we are capturing data on a cell phone, and then classifying it using a neural network, and then showing the results. And it also creates opportunities for further exploration as well. This could very well be the tail end of a larger project, where the students have actually trained or used household learning to re-train an existing network, and then they're testing out the results using a mobile device.
While we are here, I would also like to point out a few other things. So if you click on the Support button right up top, and then look at all the support resources that are available on MATLAB's website, one thing I'll highlight are the examples. So these examples-- shipping examples that are available, obviously, on our website. And these range from simple things, like basic matrix operations, to spectral analysis, using FFT, to more advanced things, and exciting things, like a simulation of a bouncing ball, or modeling an automatic transmission controller for a car, or even all the way up to maybe aircraft controller radar design. So, my point being, this is a really good place to look for different types of examples that could be used in a virtual lab environment.
So to quickly wrap up this particular demo, we saw how we can easily use readily accessible hardware, like a smartphone, and then explore and experiment with advanced concepts with relative ease. And the products used in this case were MATLAB, MATLAB Mobile, and Deep Learning Toolbox. If you're wondering about what kind of hardware can you use with MATLAB and Simulink, check out this page, mathworks.com/hardware.
In short, MATLAB and Simulink can connect to pretty much any industrial and educational hardware currently available for both live data streaming, and code generation, and targeting workflows. And since we have been talking about hardware at home, you can see on this slide how you can find information about connecting with Arduinos, Raspberry Pis, and so on, as well.
Continuing with our discussion of different approaches for labs, let's take a look at an example of a lab that involves remotely accessed hardware. Though given that I know the hardware that we will talk about, you could also say that this is an example of hardware at home lab as well.
In this case, we will use an example for the discipline of Civil Engineering, specifically traffic management and roadway design. And the goal is to provide recommendations for traffic or lane management based on remotely-collected traffic data. At a high level, we will see how traffic data generated by remote hardware and stored on an IoT platform, and then analyze the data locally, and then share recommendations based on the data analysis for, I guess, wide consumption via the IoT platform, and then create a report. So let's jump into this demo.
Typically for projects like these in the real world, temporary or permanent expensive sensors are put on the roadways to evaluate traffic. How to create a class project? We could have a setup like this, where there's a camera looking outside a window and counting the number of cars going on the road. And for reference, we have a couple of links here that we can take a look at in some more detail.
So the first link brings you to File Exchange, where you can download the files for the first part of this demo, which deals with, actually, the hardware aspect of it. So the webcam is actually connected to a Raspberry Pi. And on the Raspberry Pi, we have a Simulink model, or C version of a Simulink model running, which is actually running a computer version algorithm which is counting the number of cars.
And it is automatically counting the number of cars going East, and the number of cars going West. And it is putting that information on this IoT channel and on a IoT platform called ThingSpeak. And as you can see, right now the traffic is going in both directions, going East and going West. That's why the colors are green. And then this channel, this IoT platform, is capturing traffic data for some period of time.
Now if you come back to MATLAB, let's go ahead and take a look at the rest of the demo here for analyzing the data that we are gathering for traffic information. But if we pause for a second and think about this whole thing. And actually, we've set up as a group project as well, with one student working on designing the car-counting algorithm, the computer version side of things, another student working on actually working with the hardware and deploying the algorithm with Raspberry Pi, and the third student can be working on the data analysis and reporting side of things.
Coming back to the step three of this demo, that's what we're discussing, which is accessing data, and then analyzing the data. So the data has already been generated by the camera and the Raspberry Pi. And it has been uploaded to ThingSpeak. And then, in order to bring that data back from ThingSpeak to MATLAB, all you have to do is use a command like this, thingSpeakRead, and then provide a channel ID. And this is going to bring the data back into MATLAB.
There are different ways in which you can read data from this platform. And then you can just get raw data, or you can get data with some time information. Or you can even get data that you can specify that you want x number of data points to come back with it. So if I run this section here, you can see the different formats in which the data is coming back from ThingSpeak into MATLAB.
Now once the data is in MATLAB, it is just data. And then you can actually do pretty much any type of processing on the data. Let's say for example, if I want to create a bar chart to look at the data, all I have to do is use the bar command, and then you can show the data that has been downloaded from ThingSpeak. Now at this point of time, we can provide some information or guidance to the students on how to analyze the data, and then report the results back via ThingSpeak.
So to wrap up, in this demo, we saw how we can acquire data generated by a remote target, analyze the data locally, and then use the Internet of Things, or IoT for collaboration. And for the reference, the products that we used here were MATLAB, Statistics and Machine Learning Toolbox and ThingSpeak.
I haven't had a chance to talk a whole lot about ThingSpeak, but I wanted to point out that ThingSpeak is our platform for Internet of Things. And it makes it very easy to collect and analyze realtime sensor data, as well as create collaborative projects. And there are a lot of publicly available datasets on ThingSpeak as well that you can use as data sources for our data analysis-type projects as well.
So I hope that all this discussion gives you some ideas on how to implement virtual labs and remote projects using MATLAB and Simulink. Let's take a look at some of the resources that you can take advantage of right now in order to get going, and in case you already aren't your way.
So the first resource that I'll point out is our page on online teaching with MATLAB and Simulink. And this is where you can find all the resources. So the resources around instruction-- for example, there are tutorials around MATLAB and Simulink. There are freely downloadable MATLAB and Simulink-based courseware. There's information about books written on different topics using MATLAB and Simulink, and so on.
You will also find examples of virtual labs and projects here, and ideas that you could use to create your own labs or projects, or adapt existing content. And there is information about online assessment here as well. So if you want to create automatically-graded MATLAB-based assignments, and you're looking for tools for that, if you're looking for question banks around that, you can find information here.
If you want to collaborate with educators worldwide while teaching remotely or online using MATLAB tools, do check out the Distance Learning Community as well.
So to wrap up, we saw several different approaches for implementing virtual or online labs. So choose one or a combination of online lab approaches that work best for you. And explore the MATLAB and Simulink-based resources that could help you in implementing some of these approaches for either one curriculum. And do share thoughts with us at the Distance Learning Community as well. Thank you very much for listening.