Personal tools
  •  

Simulink Tutorial

Document Actions
  • Content View
  • Bookmarks
  • CourseFeed

Objective and Background

The objective of this assignment is to familiarize the student with basic operations in Simulink.

Simulink is a systems simulator, which allows you to create block diagrams and then simulate the systems they represent. Simulink runs inside the full version Matlab, and can take advantage of all of Matlab's features.

The first step when using Simulink is to draw the block diagram of the system. For this Simulink provides a powerful graphical editing tool. You can set up all of the parameters of the system, then simulate it. You can display the results of the simulation either using an ``oscilloscope'' display in Simulink, or by saving the results to a Matlab variable and using Matlab's powerful plotting capabilities. In this assignment, you will be using the latter technique.

Simulink Tutorial: A Simple System

The assignment begins with the following steps, which you should carefully work and understand.

  1. To run Simulink, first get into Matlab and then from the Matlab command prompt typ simulink .
  2. Under the file menu, select New, then Model. A window will appear which will be your drawing window for the block diagram.
  3. You will be creating the block diagram shown. This is the Simulink representation of Figure 6.36(b).

    Begin by placing the transfer function representing the motor. To do this:

    1. In the Simulink menu, double-click on the icon labeled "Continue to open up its selections.
    2. From the Continuous menu, drag the icon labeled ``Transfer Fcn'' to the drawing window.
    3. In the drawing window, double-click on the Transfer Fcn Icon. A small window will appear that will allow you to enter the parameters of the transfer function as its numerator polynomial. The transfer function you want (representing the motor) is
      \begin{displaymath}G(s) = \frac{1}{s(s+8)}.
\end{displaymath}

      The numerator polynomial is [1] . The denominator polynomial is [1 8 0] , representing the polynomial $s^2 + 8s$ . Enter the parameters appropriately and click on Done when you are finished.
  4. Now place the Gain block (which represents the block $G_1(s)$ ). From the Math Operations menu, drag the icon labeled ``Gain'' to the drawing window and place it appropriately. Adjust the gain of the Gain block by double-clicking on the gain icon and setting the parameter. Set the gain to 80 to begin with.
  5. Connect the gain block to the transfer function: Place the cursor on the output arrow of the amplifier and drag until it touches the input of the transfer function block. When you release the mouse button, the blocks will be connected (if you have placed everything correctly) and an arrow will appear indicating that the blocks are connected. (If you make a mistake, you can delete a connection by clicking on it to select, then pressing the Delete key.)
  6. Place the summation block on your block diagram.
    1. Drag the Sum icon from the Math Operations menu to the appropriate place on the drawing window.
    2. Set the signs of the inputs so that the top input is $+$ and the bottom input is $-$ . This is done by double clicking on the icon and setting the list of input signs as desired.
    3. Connect the output of the summation block to the input of the gain block.
    4. Connect the output of the transfer function to the $-$ input of the summation block. (You can draw each segment of the line separately.)
  7. Provide the input to the system by adding a Step Input.
    1. In the Simulink menu, double-click on the Sources icon to open up its selections. You will see a variety of interesting sources.
    2. From the Sources menu, drag the Step Input icon to an appropriate location in the drawing window.
    3. Double-click on the Step Input icon to set its parameters. Set the step time to 0 (so the step occurs right at time $t=0$ ). The initial value and final values are correct by default.
    4. Connect the output of the Step Input icon to the $+$ input of the Sum icon.
  8. The basic block diagram is now complete. However, you must provide some means of looking at what is going on in the simulation. What you will do is tell the system to save its output into a Matlab variable. Then the Matlab plotting facilities can be used to plot the results of the simulation.
    1. In the Simulink menu, double-click on the Sinks icon to open up its selections. In data processing terminology, a Source is something that provides data (like a signal generator), and a Sink is something that consumes data (like the drain in a sink).
    2. From the Sinks menu, drag the To Workspace icon to an appropriate location in the drawing window.
    3. The text shown in the icon yout is the name of the Matlab variable that the data is saved to.
    4. Connect the output of the transfer function to the input of the To Workspace icon. Note that an output can be routed to several different places, so this connection is just like all the others, even though the transfer function is already connected to something.
  9. For purposes of plotting the results, we also need to know the "time'' in the simulation. What is happening is this: the Simulink program converts the block diagram into a set of differential equations. Then, using numerical techniques to solve the differential equation, it finds the outputs as necessary. As you will recall from last quarter when you did numerical integration of differential equations, there must be some kind of variable representing time. Despite this lengthy explanation, it is quite easy to accomplish.
    1. From the Sources menu, drag the Clock icon to the drawing window. The Clock has an output that is simply the time variable in the simulation. There are no parameters associated with this device.
    2. From the Sinks menu, drag the To Workspace icon to the drawing window.
    3. Double-click on the To Workspace Icon to change the name of the workspace variable. Call the variable t , to represent time.
    4. Connect the output of the Clock icon to the input of the To Workspace Icon.
  10. You have now completed the drawing of the block diagram. Before doing anything else, you should save the block diagram to a file for future use. This is done using the Save option under the File menu. If you are running in the PC lab, you will want to make sure you save to a diskette.
  11. Set the simulation parameters. In the Simulation menu in the drawing window, select the command Parameters. Several options will appear. You do not need to worry about most of them. The one of interest is the Stop Time: Set it to 5.

    (The buttons at the top select the particular algorithms used for the numerical solution of the differential equations. If you were to select the Euler button, you would be doing the same kind of solution you did in your programming assignments last quarter. The other options are more sophisticated, and hence more accurate, numerical techniques. You should probably just leave it at the default setting.)

  12. You are now ready to simulate. Under the Simulation menu in the drawing window, simply select the command Start. The computer will beep. That is it! Nothing appears on the screen, because the results of the simulation are saved into Matlab variables.
  13. To see the results of the simulation, you will need to go back to the Matlab window. From the Matlab window, enter the Matlab command

    plot(t,yout)

    which plots the variable t versus the variable yout . As you recall, these are the variables that Simulink uses. Compare the results of the plot command with Figure 6.36(c) in the book for $K=80$ . They should be very similar! (If not, make sure that you have the parameters set correctly in the Sum, the Gain, and the Transfer function. Also make sure that the lines are actually connecting as they should be.)

I don't know about you, but I think this is pretty neat! It sure beats solving differential equations by hand.

The Rest of the Assignment

Having done all of the above, now do the following:

  1. (50 pts) Make plots of the step response of the system you just created for $K=7$ , $K=16$ and $K=80$ . Verify that the system operates as the book indicates. Provide a printout of the plots in your writeup. Also provide a plot of your Simulink block diagram.
  2. (20 pts) For this step, leave the amplifier gain at 80. Replace the step input with a Signal Generator (from the Sources menu). The Signal Generator lets you choose a variety of sources. Select the sinusoidal source and leave the peak amplitude at 1. Then for frequencies of 10, 20, 50, and 100 radians/sec, simulate the system. (There are four different simulations to do.) Find the ratio of the steady-state output amplitude (after the effect of the initial conditions dies down) to the input amplitude from plots of the output. For the 20 radians/sec case only, provide a plot of 5 seconds of the output signal. Compare the ratio of steady-state output amplitude to input amplitude with the theoretical results for gain.
  3. (30 pts) Now create a new block diagram that operates the same way. However, this time instead of using a Transfer function block, you will build the transfer function $\frac{1}{s^2 + 8s}$ using integrators, summers, and gain blocks as described in section 6.6. After implementing the transfer function using the cannonical realization, provide the rest of the blocks to complete the simulation of the motor system. Print out the Simulink block diagram. Also, simulate the system again with gains of 7, 16, and 80, and provide plots of the output. They should be the same as the results you obtained before.
Copyright 2008, by the Contributing Authors. Cite/attribute Resource . admin. (2006, May 10). Simulink Tutorial. Retrieved January 07, 2011, from Free Online Course Materials — USU OpenCourseWare Web site: http://ocw.usu.edu/Electrical_and_Computer_Engineering/Signals_and_Systems/Simulink_Tutorial.html. This work is licensed under a Creative Commons License Creative Commons License