Sie sind auf Seite 1von 39

BASICS FOR SIMULINK

Dr. N. YADAIAH
ASSOCIATE PROFESSOR DEPT. of E.E.E. JNTUCEH

INTRODUCTION
Simulink is a software package for modeling, simulating, and analyzing dynamical systems. It supports linear and nonlinear systems, modeled in continuous time, sampled time, or a hybrid of the two. It can be used to explore the behavior of a wide range of real-world systems, including electrical circuits, shock absorbers, braking systems, and many other electrical, mechanical, and thermodynamic systems. The systems can also be multirate, i.e., have different parts that are sampled or updated at different rates. For modeling, Simulink provides a graphical user interface (GUI) for building models as block diagrams, using click-and-drag mouse operations. This is a far cry from previous simulation packages that require formulating differential equations and difference equations in a language or program. Simulink has its own comprehensive block library of sinks, sources, linear and nonlinear components, and connectors. Also it can be customized and create new blocks. Steps the system through time using an engine that
Propagates signals Computes block outputs

Uses MATLAB workspace for parameters Can interface with MATLAB workspace for system inputs & outputs

STARTING SIMULINK
Simulating a dynamic system is a two-step process with Simulink. First, Simulink's model editor is used to create a model of the system to be simulated. The model graphically depicts the time-dependent mathematical relationships among the system's inputs, states, and outputs.

Then, Simulink is used to simulate the behavior of the system for a specified time span.

The Simulink can be explored in two ways:

1.Click on the Simulink icon on the MATLAB toolbar.


2.Enter the Simulink command at the MATLAB prompt.

STARTING SIMULINK
To run Simulink from MATLAB Window:

Blocks represents the elementary dynamic systems that Simulink knows how to simulate.

SIMULINK FEATURES
Modeling Dynamical Systems with Simulink Simulink provides a library browser that allows us to select blocks from libraries of standard blocks and a graphical editor that allows us to draw lines connecting the blocks and we can model virtually any real-world dynamic system by selecting and interconnecting the appropriate Simulink blocks. Simulink Library A Simulink block diagram is a pictorial model of a dynamic system. It consists of a set of symbols, called blocks, interconnected by lines. Each block represents an elementary dynamic system that produces an output either continuously (a continuous block) or at specific points in time (a discrete block). The lines represent connections of block inputs to block outputs. Every block in a block diagram is an instance of a specific type of block. The type of the block determines the relationship between a block's outputs and its inputs, states, and time.

SIMULINK LIBRARY
The Simulink library Blocks can be used as follows:

Block search

Block description

Libraries
Blocks

CREATING MODEL WITH BLOCKS


Dragging, Dropping and Connection Blocks
Collect blocks by pulling them into the model Connect blocks using left mouse drag

COPYING AND INSERTING BLOCKS


Right click-drag on block to copy Place block over line to insert

SETTING BLOCK PARAMETERS

BRANCHING AND REROUTING LINES


Right click-drag on line to add branch line

Left click-drag on line to reroute

COMBINING SIGNALS

SIMULATION OF DYNAMICAL SYSTEMS


Simulating a dynamic system refers to the process of computing a system's states and outputs over a span of time, using information provided by the system's model. Simulink simulates a system when we choose Start from the model editor's Simulation menu, with the system's model open.
Simulation of the system occurs in two phases:

model initialization and model execution.

RUNNING THE SIMULATION


Click the PLAY button to simulate diagram Double-click on scopes to observe results

ZOOMING BLOCK DIAGRAMS


Select Zoom In from View menu Press spacebar to fit to view

MODEL INITIALIZATION PHASE


During the initialization phase, Simulink: Evaluates the model's block parameter expressions to determine their values. Flattens the model hierarchy by replacing virtual subsystems with the blocks that they contain. Sorts the blocks into the order in which they need to be executed during the execution phase. Determines signal attributes, e.g., name, data type, numeric type, and dimensionality, not explicitly specified by the model and checks that each block can accept the signals connected to its inputs. Simulink uses a process called attribute propagation to determine unspecified attributes. This process entails propagating the attributes of a source signal to the inputs of the blocks that it drives. Determines the sample times of all blocks in the model whose sample times we did not explicitly specify. Allocates and initializes memory used to store the current values of each block's states and outputs.

RENAMING BLOCKS
Single click on block name to select and edit. Every block has a unique name. Block names can be multiple lines. Drag to the opposite side of block to change position. Use Format menu to hide the name.

ANNOTATING DIAGRAMS
Double click on background to create textbox Type in the text Right click on text to change font, size, alignment Left click and move to change position

LABELING SIGNALS
Double click on signal to type label Left-click and move anywhere on the Signal On attempt to move elsewhere, the label will snap back to the signal

PROPAGATING SIGNAL LABELS


Signal labels can be propagated through blocks that do not alter the signals Type < as a signal label to propagate Update diagram Propagates only in the direction of signal flow

CHANGING POSITION/ORIENTATION
Shift and left click and drag to disconnect Ctrl-I to flip Ctrl-R to rotate by 90 degrees

Simulink Libraries

SIMULINK LIBRARIES
Continuous: Systems with continuous states

Discrete: Systems with discrete states


Functions & Tables: MATLAB functions and lookup tables, simple expressions, S-functions

Math: Arithmetic, logic, trigonometric functions


Nonlinear: Limiters, quantizers, switches Signals & Systems: Interfacing and manipulating signals Sinks: Observing signals Sources: Input waveforms

CREATING SUBSYSTEMS
Select the region to be encapsulated (left click-drag on background) Select Create Subsystem in Edit menu

INPORTS AND OUTPORTS

EXERCISE: SQUARE THE INPUT


Create a model that will square the input vector. Source: Sine Wave with amplitude 2. Display the original and resulting signals on a Scope. Place your implementation in a subsystem. Create signal labels and propagate them. Save the diagram

SOLUTION: SQUARE THE INPUT

>> squared_sine

PARAMETERS FROM WORKSPACE


Simulink can use MATLABs workspace Block parameters can be variables from the MATLAB workspace Simulink can use the MATLAB workspace to evaluate expressions

OUTPUT TO WORKSPACE
Simulink can use the MATLAB workspace for its input/outputs. Use To Workspace block. Output written to Workspace when simulation is paused/ stopped. Can be saved as structure (includes time) or array.

INPUT FROM WORKSPACE


From Workspace block can be used to use MATLAB workspace variables as input signals

Format: t=0:time_step:final_time; x =func(t); block parameter: [t, x] or piecewise linear

Example: t=0:0.1:10; x=sin(t); t=[0 3 6 9];x=[-1 1 -1 1]; simin=[t,x];

WORKSPACE I/O VIA INPORT/OUTPORT


Inport/ Outport at top level of system ==> pass data to/from workspace Format same as To/From Workspace blocks Options controlled from Simulation menu--> Simulation Parameters--> Workspace I/O Tab

MODIFYING BLOCKS
Resize a block by dragging its corner Change coloring of a block using the context menu Right click on block Choose background and foreground color

3.6 Vectors and Matrices

VECTORS AND MATRICES


Block parameters can be real or complex vectors >> vector_gain Simulink also works with matrices >> matrix_gain

FUNCTIONS AND FUNCTION BLOCKS


Function block for a general expression >> fun_mfun MATLAB Function block to call a MATLAB function

WORKING WITH LARGE MODELS


To build a model with complex hierarchy from scratch (top down), start with empty Subsystem blocks. To work with a complex model, use the model browser.

EXERCISE: FEEDBACK SYSTEM


Open and view the class library, simclasslib. Use the blocks in the class library to create a feedback system. Input is a constant between 0 and 1 (or use a waveform!) Observe the speed on a scope Bonus: Output data to workspace and plot

SOLUTION: FEEDBACK SYSTEM

>> cruisesystem

EXERCISE: SIMPLE COMMS SYSTEM


Open and view the Class library signallib. Use the blocks in the library to create a simple communications system. Add noise to transmitted signal. Observe output on a scope . Output to workspace and observe.

SOLUTION: SIMPLE COMMS SYSTEM

>> simplecomms

REFERENCES
[1] Simulink help files [2] Ashish Tewari, Modern Control Design with MATLAB and Simulink, John Wiley & Sons, Ltd, 2003.

THANK YOU

Das könnte Ihnen auch gefallen