Experiment 8 SIMULINK
Simulink Introduction to simulink SIMULINK is an interactive environment for modeling, analyzing, and simulating a wide variety of dynamic systems. SIMULINK provides a graphical user interface for constructing block diagram models using drag-and-drop operations. A system is configured in terms of block diagram representation from a library of standard components. SIMULINK is very easy to learn. A system in block diagram representation is built easily and the simulation results are displayed quickly. Simulation algorithms and parameters can be changed in the middle of a simulation with intuitive results, thus providing the user with a ready access learning tool for simulating many of the operational problems found in the real world. SIMULINK is particularly useful for studying the effects of nonlinearities on the behavior of the system, and as such, it is also an ideal research tool. The key features of SIMULINK are Interactive simulations with live display. A comprehensive block library for creating linear, nonlinear, discrete or hybrid multi-input/output systems. Seven integration methods for fixed-step, variable-step, and stiff systems. Unlimited hierarchical model structure. Scalar and vector connections. Mask facility for creating custom blocks and block libraries. SIMULINK provides an open architecture that allows you to extend the simulation environment: You can easily perform what if analyses by changing model parameters either interactively or in batch mode while your simulations are running. Creating custom blocks and block libraries with your own icons and user interfaces from MATLAB, Fortran, or C code. You can generate C code from SIMULINK models for embedded applications and for rapid prototyping of control systems. You can create hierarchical models by grouping blocks into subsystems. There are no limits on the number of blocks or connections. SIMULINK provides immediate access to the mathematical, graphical, and programming capabilities of MATLAB, you can analyze data, automate procedures, and optimize parameters directly from SIMULINK. The advanced design and analysis capabilities of the toolboxes can be executed from within a simulation using the mask facility in SIMULINK. The SIMULINK block library can be extended with special-purpose blocksets. The DSP Blockset can be used for DSP algorithm development, while the Fixed-Point Blockset extends SIMULINK for modeling and simulating digital control systems and digital filters. 2
Getting Start : You start Simulink by clicking on the SIMULINK button on the MATLAB desktop tool bar. As an alternative method: type simulink in the command window 3
There are several groups of Simulink blocks in the Simulink icon such as Commonly Used Blocks, Continuous, Discontinuities, Math Operations, Sinks and Sources, etc. Selecting Commonly Used Blocks will provide a list of blocks shown in Fig. 2. Fig 2 : a list of blocks in Commonly Used Block group Selecting Continuous will provide a list of blocks shown in Fig. 3. The ones that we often use are Transfer Fcn, State-space and Integrator. Selecting the Sources icon yields the library shown in Fig. 4. The most commonly used sources are Clock (which is used to generate a time vector), Step (which generates a step input), and Constant (that generate a constant function). The Sinks icon as shown in Fig. 5 provides a set of Sinks blocks that are used to display 4
simulated results. The most often used blocks may be To Workspace (to which a variable passed is written to a vector in the MATLAB Workspace), Scope (to represent data graphically). Fig 3: A list of blocks in Continuous group 5
Fig 3: A list of blocks in source group 6
Fig 3: A list of blocks in Sinks group 7
Block Libraries Block icon Name Use Continuous State-Space Implement a linear state-space system Transfer Fcn Implement a linear transfer function Math Operations Derivative Merge scalar, vector or matrix signals Divide Multiply or divide inputs Function Gain Integrator Apply a specified expression to the input Multiplies the input by a constant value (gain) Integrate the input signal Math Function Perform a mathematical function Product Multiply inputs Sum Add or subtract inputs Transport Delay Delay the input by a given amount of time 8
Signal Routing Demux Mux Split vector signals into scalars or smaller vectors Extract and output the elements of a bus or vector signal Sinks Scope Display signals generated during a simulation To Workspace Write data to the workspace Sources XY Graph Clock Display an X-Y plot of signals using a MATLAB figure window Generate a time vector Constant Generate a constant Ramp Output a ramp signal Sine Wave Generate a sine wave signal Step General a step signal Table 1 Summary of Commonly Used Simulink Blocks 9
Example 1. Simulation of an Equation. In this example we will use Simulink to model an equation. Let's consider where the displacement x is a function of time t, frequency w, phase angle phi, and amplitue A. In this example the values for these parameters are set as follows: frequency=5 rad/sec;phase=pi/2;a=5. 1. From Simulink's library drag the following blocks to the Model Window Blocks to be dragged to the model window Ramp Constant Gain Sum Product Trigonometry Function Scope Mux Where located in Simulink library browser Sources Sources Math Operation Math Operation Math Operation Math Operation Sinks Signal Routing 2. The next step is to connect these blocks as shown. x(t)=2cos(5t+pi/2) 5 Constant Product Constant1 cos Trigonometric Function 5 Gain Ramp pi/2 Scope 01
Double click on the blocks and enter the appropriate values as prompted by the popup dialog windows. Note that the cosine function can be selected from the pull-down menu in the pop-up window. In the arrangement shown above, the input signal (a ramp function) is to be displayed along with the output (displacement) via the use of the mux tool. To view the plots, double click on the scope. 3. Make sure all blocks are connected correctly then run the simulation (CTRL+T). You may need to select the Autoscale button on the scope display window to obtain a better display of the plots. You may find the sinusoidal plots to be a bit "jaggy". You may want to improve the resolution of the displayed plot by redefining the Max Step Side value ("auto" is set a default value) in Simulation Parameters window (with keystrokes CTRL+E in the model window). Just for fun, you may want to experiement with different choice of solver. ODE45 is a default choice. You are encouraged to learn more about the solver methods by checking out the help files in Matlab command window. For instance, help ODE45 for parameters in non-stiff differential equations. How Simulink Works Simulink is a software package that enables you to model, simulate, and analyze systems whose outputs change over time. Such systems are often referred to as dynamic systems. The Simulink software can be used to explore the behavior of a wide range of real-world dynamic systems, including electrical circuits, shock absorbers, braking systems, and many other electrical, mechanical, and thermodynamic systems. This section explains how Simulink works. Simulating a dynamic system is a two-step process. First, a user creates a block diagram, using the Simulink model editor, that graphically depicts time-dependent mathematical relationships among the system's inputs, states, and outputs. The user then commands the Simulink software to simulate the system represented by the model from a specified start time to a specified stop time. What Is a Solver? A solver is a component of the Simulink software. The Simulink product provides an extensive library of solvers, each of which determines the time of the next simulation step and applies a numerical method to solve the set of ordinary differential equations that represent the model. In the process of solving this initial value problem, the solver also satisfies the accuracy requirements that you specify. To help you choose the solver best suited for your application, Choosing a Solver Type provides background on the different types of solvers while Choosing a Fixed-Step Solver and 00
Choosing a Variable-Step Solver provide guidance on choosing a specific fixed-step or variable-step solver, respectively. Discrete Continuous Variable-Order Fixed-Step Explicit Not Applicable Explicit Fixed-Step Continuous Solvers Implicit Not Applicable Implicit Fixed-Step Continuous Solvers Not Applicable Not Applicable Variable- Step Explicit Choosing a Variable-Step Solver Explicit Continuous Variable-Step Solvers Variable-Order Solvers Implicit Implicit Continuous Variable-Step Solvers Variable-Order Solvers Choosing a Solver Type The Simulink library of solvers is divided into two major types in the Solver Pane: fixed-step and variable-step. You can further divide the solvers within each of these categories as: discrete or continuous, explicit or implicit, one-step or multistep, and single-order or variable-order. 5.1) Simulation Parameters and Solver You set the simulation parameters and select the solver by choosing Parameters from the Simulation menu. SIMULINK displays the Simulation Parameters dialog box, which uses three pages to manage simulation parameters. Solver, Workspace I/O, and Diagnostics. SOLVER PAGE 02
The Solver page appears when you first choose Parameters from the Simulation menu or when you select the Solver tab. The Solver page allows you to: Set the start and stop times You can change the start time and stop time for the simulation by entering new values in the Start time and Stop time fields. The default start time is 0.0 seconds and the default stop time is 10.0 seconds. Choose the solver and specify solver parameters The default solver provide accurate and efficient results for most problems. Some solvers may be more efficient that others at solving a particular problem; you can choose between variable-step and fixed-step solvers. Variable-step solvers can modify their step sizes during the simulation. These are ode45, ode23, ode113, ode15s, ode23s, and discrete. The default is ode45. For variable-step solvers, you can set the maximum and suggested initial step size parameters. By default, these parameters are automatically determined, indicated by the value auto. For fixed-step solvers, you can choose ode5, ode4, ode3, ode2, ode1, and discrete. Output Options The Output options area of the dialog box enables you to control how much output the simulation generates. You can choose from three popup options. These are: Refine output, Produce additional output, and Produce specified output only. 03
NOW, make this example: Using Simulink plot this function 2 1 1 1 1 x ( t ).5 cost cos3t cos5t cos7t cos9 t... 3 5 7 9.5 Constant Sine Wave Sine Wave1 Sine Wave2 Scope Sine Wave3 Sine Wave4 Add 04
Exercise Question 1 : Model the equation that converts Celsius temperature to Fahrenheit. Obtain a display of Fahrenheit-Celsius temperature graph over a range of 0 to 100 C. T F 9 T 5 C 32 First, consider the blocks needed to build the model. These are: A ramp block to input the temperature signal, from the source library. A constant block, to define the constant of 32, also from the source library. A gain block, to multiply the input signal by 9=5, from the Linear library. A sum block, to add the two quantities, also from the Linear library. A scope block to display the output, from the sink library. To create a SIMULINK block diagram presentation select new from the File menu. This provides an untitled blank window for designing and simulating a dynamic system. Copy the above blocks from the block libraries into the new window by depressing the mouse button and dragging. Assign the parameter values to the Gain and Constant blocks by opening (double clicking on) each block and entering the appropriate value. Then click on the close button to apply the value and close the dialog box. The next step is to connect these icons together by drawing lines connecting the icons using the left mouse button (hold the button down and drag the mouse to draw a line). You should now have the SIMULINK block diagram as shown below: 05
The Ramp block inputs Celsius temperature. Open this block, set the Slope to 1, Start time to 0, and the Initial output to 0. The Gain block multiplies that temperature by the constant 9/5. The sum block adds the value 32 to the result and outputs the Fahrenheit temperature. Pull down the Simulation dialog box and select Parameters. Set the Start time to zero and the Stop Time to 100. Double click on the Scope, click on the Auto Scale, the result is displayed as shown below Question2: Implement the below function by Simulink 2X 2 3 Make sure that the range of the function appears in scope between (-3,10). 06