16.06 & 16.07 MATLAB & Simulink Tutorials Variable Types Local (default) Every function has its own local variables.Scripts share local variables with functions they call and with the base workspace. Global global speedoflight Shared by functions, scripts, and base workspace. Persistent persistent R, C Can be declared and used only in functions.
Instructor So, let's create our first Simulink model. I'm going to go here to Sources, and let's scroll down and let's pick our favorite one, sine wave. I'll click and drag it into the workspace here, and we see that Simulink gives us a place where we can edit the amplitude. This is nice, but let's take a closer look by double-clicking on the block. This brings up the block parameters for our sine wave.
We'll see here it gives us some nice information, like the output signal is just a basic sine wave, and some other basic information. We can change the sine wave properties here.We can make the amplitude larger or smaller. It defaults to one. The bias or the DC offset is zero. Frequency's in Radians per second, and the sample time. Let's go ahead and leave it at the default values for now, and let's open up the library browser again, and let's have something that we can see our sine wave with.
Let's grab a sink. And the easiest thing to do is grab our scope, so let's put a scope in our workspace here. And if I click on the output arrow here on the side of the sine wave box, I can click and drag it and connect it to the input on the scope.I don't know about you, but I like all my lines to be straight so I'll just use the arrow keys to move my scope around. Then, I'm going to go ahead and zoom in a bit so we can see this a little bit better. So, if we run our simulation by clicking the green run button up here, Simulink will run the simulation, and we can double-click on our scope to see our sine wave. That's a pretty good-looking sine wave.
I'm going to leave our scope down here at the bottom. Let's go ahead and change the frequency here, and we'll see our sine wave change. Change frequency to two Radians for a second, re-run the simulation, double-click on our scope again, and we can see we have a higher frequency sine wave.This is a pretty simple example. Let's do something more interesting. How about let's add some noise to our sine wave? So, I'm going to open the library back up, and let's go to Sources again, and let's pick some band-limited white noise.
I'm going to click and drag that block into our diagram, open up the library again, and we need to add these two together. So, I'm going to type in sum, search for that, and let's drag our addition block in. Now, I'm going to click on this arrow here and delete it, and select the output of our sine wave and click that into our addition box, and grab our noise and connect that to the other input of the addition block.Lastly, let's connect up the output of the addition block to the input of our scope. We can see we can set the noise power, the sample time for the noise, and the seed to generate our random number. Let's go ahead and run the simulation, open up our scope, and there we go. We see that we have a sine wave now with a bunch of noise added to it. Let's turn the noise down just a bit.
The noise power is currently.1. Let's change that to.01. Let's run our simulation again.And there we go, our sine wave is a lot more visible now. You can see how this could be very useful for simulating a signal that's in a noisy environment, and perhaps we'd want to do something like design a digital filter to filter our the noise. Simulink is great for these kinds of applications. MATLAB is one of the most popular programming languages today for engineers and scientists, and with good reason-it allows analysts to work efficiently with large amounts of data.
Instructor Steven Moser shows you how to harness the MATLAB tools and create programs to model your own data and hypotheses. First, learn how to create basic variables and cell arrays, and work with the core MATLAB syntax, which is significantly different than other programming languages. Then discover how to create scripts and functions, work with matrices, debug your program, and import data. To illustrate your findings, Steven shows how to create 2D and 3D plots, add annotations, and incorporate images. The final chapter covers Simulink, the MATLAB block diagram tool.