Simulink Tutorial
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.
 To run Simulink, first get into Matlab and then from the Matlab command prompt typ simulink .
 Under the file menu, select New, then Model. A window will appear which will be your drawing window for the block diagram.

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:
 In the Simulink menu, doubleclick on the icon labeled "Continue to open up its selections.
 From the Continuous menu, drag the icon labeled ``Transfer Fcn'' to the drawing window.

In the drawing window, doubleclick 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
The numerator polynomial is [1] . The denominator polynomial is [1 8 0] , representing the polynomial . Enter the parameters appropriately and click on Done when you are finished.
 Now place the Gain block (which represents the block ). 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 doubleclicking on the gain icon and setting the parameter. Set the gain to 80 to begin with.
 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.)

Place the summation block on your block diagram.
 Drag the Sum icon from the Math Operations menu to the appropriate place on the drawing window.
 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.
 Connect the output of the summation block to the input of the gain block.
 Connect the output of the transfer function to the input of the summation block. (You can draw each segment of the line separately.)

Provide the input to the system by adding a Step Input.
 In the Simulink menu, doubleclick on the Sources icon to open up its selections. You will see a variety of interesting sources.
 From the Sources menu, drag the Step Input icon to an appropriate location in the drawing window.
 Doubleclick on the Step Input icon to set its parameters. Set the step time to 0 (so the step occurs right at time ). The initial value and final values are correct by default.
 Connect the output of the Step Input icon to the input of the Sum icon.

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.
 In the Simulink menu, doubleclick 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).
 From the Sinks menu, drag the To Workspace icon to an appropriate location in the drawing window.
 The text shown in the icon yout is the name of the Matlab variable that the data is saved to.

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.

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.
 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.
 From the Sinks menu, drag the To Workspace icon to the drawing window.
 Doubleclick on the To Workspace Icon to change the name of the workspace variable. Call the variable t , to represent time.
 Connect the output of the Clock icon to the input of the To Workspace Icon.
 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.

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.)
 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.

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 . 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.)
The Rest of the Assignment
Having done all of the above, now do the following:
 (50 pts) Make plots of the step response of the system you just created for , and . 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.
 (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 steadystate 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 steadystate output amplitude to input amplitude with the theoretical results for gain.
 (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 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.