For modeling, Simulink provides a graphical user interface GUI for building models as block diagrams, using click-and-drag mouse operations.. Chapter 11 provides reference information fo
Trang 1S IMULINK
Modeling Simulation Implementation
Trang 2How to Contact The MathWorks:
The MathWorks, Inc Mail
24 Prime Park WayNatick, MA 01760-1500
http://www.mathworks.com Web
ftp.mathworks.com Anonymous FTP server
comp.soft-sys.matlab Newsgroup
support@mathworks.com Technical support
suggest@mathworks.com Product enhancement suggestions
bugs@mathworks.com Bug reports
doc@mathworks.com Documentation error reports
subscribe@mathworks.com Subscribing user registration
service@mathworks.com Order status, license renewals, passcodes
info@mathworks.com Sales, pricing, and general information
Simulink User’s Guide
COPYRIGHT 1984 - 1997 by The MathWorks, Inc All Rights Reserved.
The software described in this document is furnished under a license agreement The software may be used
or copied only under the terms of the license agreement No part of this manual may be photocopied or
repro-duced in any form without prior written consent from The MathWorks, Inc.
U.S GOVERNMENT: If Licensee is acquiring the software on behalf of any unit or agency of the U S Government, the following shall apply:
(a) for units of the Department of Defense:
RESTRICTED RIGHTS LEGEND: Use, duplication, or disclosure by the Government is subject to tions as set forth in subparagraph (c)(1)(ii) of the Rights in Technical Data and Computer Software Clause
restric-at DFARS 252.227-7013.
(b) for any other unit or agency:
NOTICE - Notwithstanding any other lease or license agreement that may pertain to, or accompany the delivery of, the computer software and accompanying documentation, the rights of the Government regarding its use, reproduction and disclosure are as set forth in Clause 52.227-19(c)(2) of the FAR Contractor/manufacturer is The MathWorks Inc., 24 Prime Park Way, Natick, MA 01760-1500 MATLAB, Simulink, Handle Graphics, and Real-Time Workshop are registered trademarks and Stateflow and Target Language Compiler are trademarks of The MathWorks, Inc.
Other product or brand names are trademarks or registered trademarks of their respective holders.
Printing History: March 1992 First printing
May 1997 Revised for 2.1 (online version) Reprints - December 1993, November 1994, June 1995, July 1996
☎
FAX
✉
@
Trang 3Professional Application Toolboxes 1-5
The Simulink Real-Time Workshop 1-10
2
Quick Start
Running a Demo Model 2-2
Description of the Demo 2-3 Some Things to Try 2-4 What This Demo Illustrates 2-4 Other Useful Demos 2-5
Trang 4Building a Simple Model 2-6
3
Creating a Model
Starting Simulink 3-2
Simulink Windows 3-3 Creating a New Model 3-3 Editing an Existing Model 3-3 Undoing a Command 3-3
Libraries 3-13
Terminology 3-13 Creating a Library 3-13 Modifying a Library 3-14 Copying a Library Block into a Model 3-14 Updating a Linked Block 3-15 Breaking a Link to a Library Block 3-15 Finding the Library Block for a Reference Block 3-16
Trang 5Getting Information About Library Blocks 3-16
Lines 3-17
Drawing a Line Between Blocks 3-17 Drawing a Branch Line 3-18 Drawing a Line Segment 3-18 Displaying Line Widths 3-21
Signal Labels 3-22
Using Signal Labels 3-22 Signal Label Propagation 3-23
Annotations 3-24 Summary of Mouse and Keyboard Actions 3-25 Creating Subsystems 3-27
Creating a Subsystem by Adding the Subsystem Block 3-28 Creating a Subsystem by Grouping Existing Blocks 3-28 Labeling Subsystem Ports 3-29 Using Callback Routines 3-30
Tips for Building Models 3-33 Modeling Equations 3-34
Converting Celsius to Fahrenheit 3-34 Modeling a Simple Continuous System 3-35
Saving a Model 3-38 Printing a Block Diagram 3-39
Print Dialog Box 3-39 Print Command 3-40
The Model Browser 3-42
Contents of the Browser Window 3-42 Interpreting List Contents 3-43
Trang 6Ending a Simulink Session 3-45
Running a Simulation Using Menu Commands 4-4
Setting Simulation Parameters and Choosing the Solver 4-4 Applying the Simulation Parameters 4-4 Starting the Simulation 4-4
The Simulation Parameters Dialog Box 4-6
The Solver Page 4-6 The Workspace I/O Page 4-14 The Diagnostics Page 4-17
Improving Simulation Performance and Accuracy 4-19
Speeding Up the Simulation 4-19 Improving Simulation Accuracy 4-20
Running a Simulation from the Command Line 4-21
Using the sim Command 4-21 Using the set_param Command 4-21
5
Analyzing Simulation Results
Viewing Output Trajectories 5-2
Using the Scope Block 5-2 Using Return Variables 5-2 Using the To Workspace Block 5-3
Trang 7Linearization 5-4 Equilibrium Point Determination (trim) 5-7
6
Using Masks to Customize Blocks
Introduction 6-2
A Sample Masked Subsystem 6-3
Creating Mask Dialog Box Prompts 6-4 Creating the Block Description and Help Text 6-6 Creating the Block Icon 6-6 Summary 6-8
The Mask Editor (An Overview) 6-9
The Initialization Page 6-10
Prompts and Associated Variables 6-10 Control Types 6-12 Default Values for Masked Block Parameters 6-14 Initialization Commands 6-14
The Icon Page 6-17
Displaying Text on the Block Icon 6-17 Displaying Graphics on the Block Icon 6-18 Displaying a Transfer Function on the Block Icon 6-19 Controlling Icon Properties 6-20
The Documentation Page 6-24
The Mask Type Field 6-24 The Block Description Field 6-24 The Mask Help Text Field 6-25
Trang 8Conditionally Executed Subsystems
Introduction 7-2 Enabled Subsystems 7-3
Creating an Enabled Subsystem 7-3 Blocks an Enabled Subsystem Can Contain 7-5
Triggered Subsystems 7-8
Creating a Triggered Subsystem 7-9 Function-Call Subsystems 7-10 Blocks a Triggered Subsystem Can Contain 7-10
Triggered and Enabled Subsystems 7-11
Creating a Triggered and Enabled Subsystem 7-11
A Sample Triggered and Enabled Subsystem 7-12
8
S-Functions
Introduction 8-2
What Is an S-Function? 8-2 When To Use an S-Function 8-4 How S-Functions Work 8-4 S-Function Concepts 8-8 Sample S-Functions 8-10
Writing S-Functions as M-Files 8-11
Defining S-Function Block Characteristics 8-11
A Simple M-File S-Function Example 8-12 Examples of M-File S-Functions 8-15 Passing Additional Parameters 8-25
Writing S-Functions as C MEX-Files 8-26
Statements Required at the Top of the File 8-27 Statements Required at the Bottom of the File 8-27
Trang 9Defining S-Function Block Characteristics 8-28
A Simple C MEX-File Example 8-29 Examples of C MEX-File S-Function Blocks 8-32 Creating General Purpose S-Function Blocks 8-42 Specifying Parameter Values Interactively 8-43 Output and Work Vector Widths 8-51 Removing Ports When No Inputs and/or Outputs 8-51 Using Function-Call Subsystems 8-51 Instantaneous Update of S-Function Inputs 8-53 Exception Handling 8-53 Error Handling 8-54 Normal or Real-Time Workshop Simulation 8-54 Additional Macros in mdlInitializeSizes 8-54
Discrete-Time Systems 10-11
Discrete Blocks 10-11 Sample Time 10-11 Purely Discrete Systems 10-11 Multirate Systems 10-12
Trang 10Sample Time Colors 10-13 Mixed Continuous and Discrete Systems 10-15
B
Model File Format
Model File Contents B-2
The Model Section B-3 The BlockDefaults Section B-3 The AnnotationDefaults Section B-3 The System Section B-3
Trang 11A Sample Model File B-4
Trang 13Getting Started
To the Reader 1-2
What Is Simulink? 1-2
How to Use This Manual 1-3
Professional Application Toolboxes 1-5
The Simulink Real-Time Workshop 1-10
The Fixed-Point Blockset 1-14
The Nonlinear Control Design Blockset 1-15
Trang 141 Getting Started
To the Reader
Welcome to Simulink®! In the last few years, Simulink has become the most widely used software package in academia and industry for modeling and simulating dynamical systems
Simulink encourages you to try things out You can easily build models from scratch, or take an existing model and add to it Simulations are interactive, so you can change parameters “on the fly” and immediately see what happens You have instant access to all of the analysis tools in MATLAB®, so you can take the results and analyze and visualize them We hope that you will get a
sense of the fun of modeling and simulation, through an environment that
encourages you to pose a question, model it, and see what happens
With Simulink, you can move beyond idealized linear models to explore more realistic nonlinear models, factoring in friction, air resistance, gear slippage, hard stops, and the other things that describe real-world phenomena It turns your computer into a lab for modeling and analyzing systems that simply wouldn’t be possible or practical otherwise, whether the behavior of an automotive clutch system, the flutter of an airplane wing, the dynamics of a predator-prey model, or the effect of the monetary supply on the economy.Simulink is also practical With thousands of engineers around the world using
it to model and solve real problems, knowledge of this tool will serve you well throughout your professional career
We hope you enjoy exploring the software
What Is Simulink?
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 Systems can be also 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 With this interface, you can draw the models just as you would with pencil and paper (or
as most textbooks depict them) This is a far cry from previous simulation packages that require you to formulate differential equations and difference equations in a language or program Simulink includes a comprehensive block
Trang 15After you define a model, you can simulate it, using a choice of integration methods, either from the Simulink menus or by entering commands in MATLAB’s command window The menus are particularly convenient for interactive work, while the command-line approach is very useful for running
a batch of simulations (for example, if you are doing Monte Carlo simulations
or want to sweep a parameter across a range of values) Using scopes and other display blocks, you can see the simulation results while the simulation is running In addition, you can change parameters and immediately see what happens, for “what if” exploration The simulation results can be put in the MATLAB workspace for postprocessing and visualization
Model analysis tools include linearization and trimming tools, which can be accessed from the MATLAB command line, plus the many tools in MATLAB and its application toolboxes And because MATLAB and Simulink are integrated, you can simulate, analyze, and revise your models in either environment at any point
How to Use This Manual
Because Simulink is graphical and interactive, we encourage you to jump right
in and try it
The manual contains eleven chapters and five appendices For a useful introduction that will help you start using Simulink quickly, take a look at
“Running a Demo Model” in Chapter 2 Browse around the model, double-click
on blocks that look interesting, and you will quickly get a sense of how Simulink works If you want a quick lesson in building a model, see “Building
a Simple Model” in Chapter 2
Chapter 3 describes in detail how to build and edit a model It also discusses how to save and print a model and provides some useful tips
Chapter 4 describes how Simulink performs a simulation It covers simulation parameters and the integration solvers used for simulation, including some of
Trang 161 Getting Started
the strengths and weaknesses of each solver that should help you choose the appropriate solver for your problem It also discusses multirate and hybrid systems
Chapter 5 discusses Simulink and MATLAB features useful for viewing and analyzing simulation results
Chapter 6 discusses methods for creating your own blocks and using masks to customize their appearance and use
Chapter 7 describes subsystems whose execution depends on triggering signals
Chapter 8 describes how to create blocks using M-files or C MEX-files
Chapter 9 provides reference information for all Simulink blocks
Chapter 10 provides information about how Simulink works, including information about zero crossings, algebraic loops, and discrete and hybrid systems
Chapter 11 provides reference information for commands you can use to create and modify a model from the MATLAB command window or from an M-file.Appendix A lists model and block parameters This information is useful with the get_param and set_param commands, described in Chapter 11
Appendix B describes the format of the file that stores model information.Appendix C provides the contents of the SimStruct, the data structure that describes S-functions
Although we have tried to provide the most complete and up-to-date information in this manual, some information may have changed after it was
printed Please check the Simulink Late-Breaking News, delivered with your
Simulink system, for the latest release notes
Trang 17Professional Application Toolboxes
Professional Application Toolboxes
One of the key features of Simulink is that it is built atop MATLAB As a result, Simulink users have direct access to the wide range of MATLAB-based tools for generating, analyzing, and optimizing systems implemented in Simulink
These tools include MATLAB Application Toolboxes, specialized collections of M-files for working on particular classes of problems
Toolboxes are more than just collections of useful functions; they represent the efforts of some of the world’s top researchers in fields such as controls, signal processing, and system identification MATLAB Application Toolboxes therefore let you “stand on the shoulders” of world class scientists
All toolboxes are built using MATLAB This has some very important implications for you:
• Every toolbox builds on the robust numerics, rock-solid accuracy, and years
of experience in MATLAB
• You get seamless and immediate integration with Simulink and any other
toolboxes you may own
• Because all toolboxes are written in MATLAB code, you can take advantage
of MATLAB’s open-system approach You can inspect M-files, add to them,
or use them for templates when creating your own functions
• Every toolbox is available on any computer platform that runs MATLAB.
Here is a list of professional toolboxes currently available from The MathWorks This list is by no means static— more are being created every year
The Communications Toolbox. The Communications Toolbox provides an integrated set of tools for accelerating the design, analysis, and simulation of modern communications systems It combines MATLAB's high-level language with the ease of use of Simulink's block diagram interface, and provides communications engineers with comprehensive communications system design and analysis capabilities The toolbox is useful in such diverse industries as telecommunications, telephony, aerospace, and computer peripherals
Trang 181 Getting Started
The Control System Toolbox. The Control System Toolbox, the foundation of the MATLAB control design toolbox family, contains functions for modeling, analyzing, and designing automatic control systems The application of automatic control grows each year as sensors and computers become less expensive As a result, automatic controllers are used not only in highly technical settings for automotive and aerospace systems, computer peripherals, and process control, but also in less obvious applications such as washing machines and cameras
The Financial Toolbox. The Financial Toolbox operates with MATLAB to provide
a robust set of financial functions essential to financial and quantitative analysis Applications include pricing securities, calculating interest and yield, analyzing derivatives, and optimizing portfolios The Financial Toolbox requires the Statistics and Optimization Toolboxes The Simulink graphical interface is recommended for Monte Carlo and non-stochastic simulations for pricing fixed-income securities, derivatives, and other instruments
The Financial Toolbox includes functions for the input, processing, and output
of financial data:
• Fixed-income pricing, yield, and sensitivity routines
• Cash flow evaluation and financial accounting functions
• Derivatives analysis procedures
• Portfolio analysis tools
• Date functions
• Graphic formats and cash formatting functions
The Frequency-Domain System Identification Toolbox. The Frequency-Domain System Identification Toolbox by István Kollár, in cooperation with Johan Schoukens and researchers at the Vrije Universiteit in Brussels, is a set of M-files for modeling linear systems based on measurements of the system’s frequency response
The Fuzzy Logic Toolbox. The Fuzzy Logic Toolbox provides a complete set of GUI-based tools for designing, simulating, and analyzing fuzzy inference systems Fuzzy logic provides an easily understandable, yet powerful way to map an input space to an output space with arbitrary complexity, with rules and relationships specified in natural language Systems can be simulated in
Trang 19Professional Application Toolboxes
MATLAB or incorporated into a Simulink block diagram, with the ability to generate code for stand-alone execution
The Higher-Order Spectral Analysis Toolbox. The Higher-Order Spectral Analysis Toolbox, by Jerry Mendel, C L (Max) Nikias, and Ananthram Swami, provides tools for signal processing using higher-order spectra These methods are particularly useful for analyzing signals originating from a nonlinear process
or corrupted by non-Gaussian noise
The Image Processing Toolbox. The Image Processing Toolbox contains tools for image processing and algorithm development It includes tools for filter design and image restoration; image enhancement; analysis and statistics; color, geometric, and morphological operations; and 2-D transforms
The LMI Control Toolbox. The LMI Control Toolbox, authored by leading researchers: Pascal Gahinet, Arkadi Nemirovski, and Alan Laub, allows one to efficiently solve Linear Matrix Inequalities (LMIs) LMIs are special convex optimization problems that arise in many disciplines, including control, identification, filtering, structural design, graph theory, and linear algebra
The LMI Control Toolbox also features a variety of LMI-based tools for control systems design and covers applications such as robust stability and
performance analysis, robust gain scheduling, and multi-objective controller synthesis with a mix of H-infinity, LQG, and pole placement objectives
The Model Predictive Control Toolbox. The Model Predictive Control Toolbox was written by Manfred Morari and N Lawrence Ricker Model predictive control
is especially useful for control applications with many input and output variables, many of which have constraints As a result, it has become particularly popular in chemical engineering and other process control applications
The Mu-Analysis and Synthesis Toolbox. The Mu-Analysis and Synthesis Toolbox, by Gary Balas, Andy Packard, John Doyle, Keith Glover, and Roy Smith, contains specialized tools for H∞ optimal control, and µ-analysis and synthesis, an approach to advanced robust control design of multivariable linear systems
The NAG Foundation Toolbox. The NAG Foundation Toolbox includes more than
200 numeric computation functions from the well-regarded NAG Fortran subroutine libraries It provides specialized tools for boundary-value problems,
Trang 20The Optimization Toolbox. The Optimization Toolbox contains commands for the optimization of general linear and nonlinear functions, including those with constraints An optimization problem can be visualized as trying to find the lowest (or highest) point in a complex, highly contoured landscape An optimization algorithm can thus be likened to an explorer wandering through valleys and across plains in search of the topographical extremes.
The Partial Differential Equation Toolbox. The Partial Differential Equation Toolbox extends the MATLAB Technical Computing Environment for the study and solution of PDEs in two space dimensions (2-D) and time The PDE Toolbox provides a set of command line functions and an intuitive graphical user interface for preprocessing, solving, and postprocessing generic 2-D PDEs using the Finite Element Method (FEM) The toolbox also provides automatic and adaptive meshing capabilities and a suite of eight application modes for common PDE application areas such as heat transfer, structural mechanics, electrostatics, magnetostatics, and diffusion These application areas are common in the fields of engineering and physics
The QFT Control Design Toolbox. The Quantitative Feedback Theory Toolbox by Yossi Chait, Craig Borghesani, and Oded Yaniv implements QFT, a
frequency-domain approach to controller design for uncertain systems that provides direct insight into the trade-offs between controller complexity (hence the ability to implement it) and specifications
The Robust Control Toolbox. The Robust Control Toolbox provides a specialized set
of tools for the analysis and synthesis of control systems that are “robust” with respect to uncertainties that can arise in the real world The Robust Control Toolbox was created by controls theorists Richard Y Chiang and Michael G Safonov
Trang 21Professional Application Toolboxes
The Signal Processing Toolbox. The Signal Processing Toolbox contains tools for signal processing Applications include audio (e.g., compact disc and digital audio tape), video (digital HDTV, image processing, and compression), telecommunications (fax and voice telephone), medicine (CAT scan, magnetic resonance imaging), geophysics, and econometrics
The Spline Toolbox. The Spline Toolbox by Carl de Boor, a pioneer in the field of splines, provides a set of M-files for constructing and using splines, which are piecewise polynomial approximations Splines are useful because they can approximate other functions without the unwelcome side effects that result from other kinds of approximations, such as piecewise linear curves
The Statistics Toolbox. The Statistics Toolbox provides a set of M-files for statistical data analysis, modeling, and Monte Carlo simulation, with GUI-based tools for exploring fundamental concepts in statistics and probability
The Symbolic Math Toolbox. The Symbolic Math Toolbox gives MATLAB an integrated set of tools for symbolic computation and variable-precision arithmetic, based on Maple V The Extended Symbolic Math Toolbox adds
support for Maple programming plus additional specialized functions
The System Identification Toolbox. The System Identification Toolbox, written by Lennart Ljung, is a collection of tools for estimation and identification System identification is a way to find a mathematical model for a physical system (like
an electric motor, or even a financial market) based only on a record of the system’s inputs and outputs
The Wavelet Toolbox. The Wavelet Toolbox provides a comprehensive collection of routines for examining local, multiscale, or nonstationary phenomena Wavelet methods offer additional insight and performance in any application where Fourier techniques have been used The toolbox is useful in many signal and image processing applications, including speech and audio processing, communications, geophysics, finance, and medicine
Trang 221 Getting Started
The Simulink Real-Time Workshop
The Simulink Real-Time Workshop™ automatically generates C code directly from Simulink block diagrams This allows the execution of continuous, discrete-time, and hybrid system models on a wide range of computer platforms, including real-time hardware Simulink is required
The Real-Time Workshop can be used for:
• Rapid Prototyping As a rapid prototyping tool, the Real-Time Workshop
enables you to implement your designs quickly without lengthy hand coding and debugging Control, signal processing, and dynamic system algorithms can be implemented by developing graphical Simulink block diagrams and automatically generating C code
• Embedded Real-Time Control Once a system has been designed with
Simulink, code for real-time controllers or digital signal processors can be generated, cross-compiled, linked, and downloaded onto your selected target processor The Real-Time Workshop supports DSP boards, embedded controllers, and a wide variety of custom and commercially available hardware
• Real-Time Simulation You can create and execute code for an entire system
or specified subsystems for hardware-in-the-loop simulations Typical applications include training simulators (pilot-in-the-loop), real-time model validation, and testing
• Stand-Alone Simulation Stand-alone simulations can be run directly on
your host machine or transferred to other systems for remote execution Because time histories are saved in MATLAB as binary or ASCII files, they can be easily loaded into MATLAB for additional analysis or graphic display
• Optimized code guarantees fast execution.
• Control framework API uses customizable makefiles to build and download
object files to target hardware automatically
Trang 23The Simulink Real-Time Workshop
• Portable code facilitates usage in a wide variety of environments.
• Concise, readable, and well-documented code provides ease of maintenance.
• Interactive parameter downloading from Simulink to external hardware
allows system tuning on the fly
• A menu-driven, graphical user interface makes the software easy to use.
The Real-Time Workshop supports the following target environments:
• dSPACE DS1102, DS1002, DS1003 using TI C30/C31/C40 DSPs
• VxWorks, VME/68040
• 486 PC-based systems with Xycom, Matrix, Data Translation, or Computer
Boards I/O devices and Quanser Multiq board
Trang 241 Getting Started
The Real-Time Workshop Ada Extension
The Simulink Real-Time Workshop (RTW) Ada Extension automatically generates Ada code directly from Simulink block diagrams This allows the execution of continuous, discrete-time, and hybrid system models on a wide range of computer platforms, including real-time hardware Simulink is required
RTW Ada Extension can be used for:
• Rapid Prototyping As a rapid prototyping tool, the RTW Ada Extension
enables you to implement your designs quickly without lengthy hand coding and debugging Control and dynamic system algorithms can be implemented
by developing graphical Simulink block diagrams and automatically generating Ada code
• Embedded Real-Time Control Once a system has been designed with
Simulink, code for real-time controllers can be generated, cross-compiled, linked, and downloaded onto your selected target processor The RTW Ada Extension generates Ada code, which can be run on a wide variety of custom and commercially available hardware
• Real-Time Simulation You can create and execute code for an entire system
or specified subsystems for hardware-in-the-loop simulations Typical applications include training simulators (pilot-in-the-loop), real-time model validation, and testing
• Stand-Alone Simulation Stand-alone simulations can be run directly on
your host machine or transferred to other systems for remote execution Because time histories are saved in MATLAB as binary or ASCII files, they can be easily loaded into MATLAB for additional analysis or graphic display
• Optimized code guarantees fast execution.
• Control framework API uses customizable makefiles to build and download
object files to target hardware automatically
Trang 25The Real-Time Workshop Ada Extension
• Portable code facilitates usage in a wide variety of environments.
• Concise, readable, and well-commented code provides ease of maintenance.
• A menu-driven, graphical user interface makes it easy to use.
The RTW Ada Extension provides turnkey solutions for the following Ada 83 compilers:
• Rational VADS for UNIX platforms
• Thomson ActivAda for Windows Professional Edition
• Thomson ActivAda for Windows NT
Trang 261 Getting Started
Blocksets
Similar to MATLAB and its application toolboxes, The MathWorks offers Blocksets for use with Simulink Blocksets are collections of Simulink blocks that are grouped in a separate library from the main Simulink library
The DSP Blockset
The DSP Blockset extends Simulink for use in the rapid design and simulation
of DSP-based devices and systems With the DSP Blockset, Simulink provides
an intuitive tool for interactive block-diagram simulation and evaluation of signal processing algorithms Its graphical programming environment makes
it easier for engineers to create, modify, and prototype DSP designs Simulink
is required
Applications for the DSP Blockset include design and analysis of communications systems, computer peripherals, speech and audio processing, automotive and aerospace controls, and medical electronics It is ideal for both time and frequency domain algorithms, including problems such as adaptive noise cancellation
The Fixed-Point Blockset
The Fixed-Point Blockset, for use with Simulink, includes a collection of block diagram components that extend the standard Simulink block library With this new set of blocks, you can create discrete-time dynamic systems that utilize fixed-point arithmetic As a result, Simulink can simulate effects commonly encountered in fixed-point systems for applications such as control systems and time-domain filtering Simulink is required
The Fixed-Point Blockset allows you to simulate fixed-point effects in a convenient and productive environment The new blocks provided by the Fixed-Point Blockset include blocks for:
• Addition and subtraction
• Multiplication and division
• Summation
• Gains and constants
• Conversion between floating-point and fixed-point signals
• 1- and 2-D lookup tables
Trang 27• Logical operators
• Relational operators
• Conversion/saturation of fixed-point signals
• Switch between two values
For example, you can create plant models using the standard Simulink blocks and model the controller with fixed-point blocks Data range blocks provide maximum and minimum values encountered during simulation from any point
in the block diagram
The Fixed-Point Blockset lets you build models using unsigned or 2’s complement 8-, 16-, or 32-bit word lengths A combination of blocks with differing word lengths may be used in the same block diagram Scaling of fixed-point values is achieved by specifying the location of the binary-point within the fixed-point blocks During simulation, data types can be changed allowing you to immediately see the effects of different word sizes, binary-point locations, rounding versus truncation, and overflow checking
Another powerful feature of this blockset is automatic location of the binary-point to give maximum precision without overflow
By using the data range blocks, you can fix binary point locations to appropriate values
The Fixed-Point Blockset requires Simulink 1.3 and MATLAB 4.2c and is currently shipping on PC and Macintosh
The Nonlinear Control Design Blockset
The Nonlinear Control Design (NCD) Blockset offers time domain-based, robust, nonlinear control design Controller designs are developed as block diagrams in Simulink You select a set of tunable model parameters and
Trang 281 Getting Started
graphically place time response constraints on selected output signals Successive simulation and optimization methods are applied automatically, thereby tuning the selected model parameters
Simulink is required with the NCD Blockset
Trang 29Quick Start
Running a Demo Model 2-2
Description of the Demo 2-3
Some Things to Try 2-4
What This Demo Illustrates 2-4
Other Useful Demos 2-5
Building a Simple Model 2-6
Trang 302 Quick Start
Running a Demo Model
An interesting demo program provided with Simulink models the thermodynamics of a house To run this demo, follow these steps
1 Start MATLAB See your MATLAB documentation if you’re not sure how to
do this
2 Run the demo model by typing thermo in the MATLAB command window This command starts up Simulink and creates a model window that contains this model:
When you open the model, Simulink opens two Scope blocks, labeled Indoor
vs Outdoor Temp and Heat Cost ($)
3 To start the simulation, pull down the Simulation menu and choose the
temperatures appears in the Indoor vs Outdoor Temp Scope block and the cumulative heating cost appears in the Heat Cost ($) Scope block
Trang 31Running a Demo Model
4 To stop the simulation, choose the Stop command from the Simulation
menu If you want to explore other parts of the model, look over the suggestions in “Some Things to Try” on page 2–4
5 When you’re finished running the simulation, close the model by choosing
Close from the File menu.
Description of the Demo
The demo models the thermodynamics of a house using a simple model The thermostat is set to 70 degrees Fahrenheit and is affected by the outside temperature, which varies by applying a sine wave with amplitude of 15 degrees to a base temperature of 50 degrees This simulates daily temperature fluctuations
The model uses subsystems to simplify the model diagram and create reusable systems A subsystem is a group of blocks that is represented by a Subsystem block This model contains five subsystems: one named Thermostat, one named House, and three Temp Convert subsystems (two convert Fahrenheit to Celsius, one converts Celsius to Fahrenheit)
The internal and external temperatures are fed into the House subsystem, which updates the internal temperature Double-click on the House block to see the underlying blocks in that subsystem
The Thermostat subsystem models the operation of a thermostat, determining when the heating system is turned on and off Double-click on the block to see the underlying blocks in that subsystem
the House subsystem
the Thermostat subsystem
Trang 32Some Things to Try
Here are several things to try to see how the model responds to different parameters
• Each Scope block contains a signal display area and controls that enable you
to select the range of the signal displayed, zoom in on a portion of the signal, and perform other useful tasks The horizontal axis represents time and the vertical axis represents the signal value For more information about the Scope block, see Chapter 9
• The Constant block labeled Set Point (at the top left of the model) sets the
desired internal temperature Open this block and reset the value to 80 degrees while the simulation is running See how the indoor temperature and heating costs change Also, adjust the outside temperature (the Avg Outdoor Temp block) and see how it affects the simulation
• Adjust the daily temperature variation by opening the Sine Wave block
labeled Daily Temp Variation and changing the Amplitude parameter.
What This Demo Illustrates
This demo illustrates several tasks commonly used when building models:
• Running the simulation involves specifying parameters and starting the
simulation with the Start command, described in detail in Chapter 4.
• You can encapsulate complex groups of related blocks in a single block, called
a subsystem Creating subsystems is described in detail in Chapter 3
• You can create a customized icon and design a dialog box for a block by using
the masking feature, described in detail in Chapter 6 In the thermo model,
Fahrenheit to Celsius conversion (F2C)
Trang 33Running a Demo Model
all Subsystem blocks have customized icons created using the masking feature
• Scope blocks display graphic output much as an actual oscilloscope does A
Scope block displays its input signal Scope blocks are described in detail in Chapter 9
Other Useful Demos
Other demos illustrate useful modeling concepts You can access these demos from the Simulink block library window:
1 Type simulink in the MATLAB command window The Simulink block library window appears:
2 Double-click on the Demos icon The MATLAB Demos window appears This window contains several interesting sample models that illustrate useful Simulink features
the Demos icon
Trang 342 Quick Start
Building a Simple Model
This example shows you how to build a model using many of the model building commands and actions you will use to build your own models The instructions for building this model in this section are brief All of the tasks are described
in more detail in the next chapter
The model integrates a sine wave and displays the result, along with the sine wave The block diagram of the model looks like this:
Type simulink in the MATLAB command window to display the Simulink block library and, if no other model window is open, a new untitled model window The Simulink block library window looks like this:
You might want to move the new model window to the right side of your screen
so you can see its contents and the contents of block libraries at the same time
In this model, you get blocks from these libraries:
• Sources library (the Sine Wave block)
• Sinks library (the Scope block)
• Linear library (the Integrator block)
• Connections library (the Mux block)
Open the Sources library to access the Sine Wave block To open a block library, double-click on the library’s icon Simulink displays a window that contains all
Trang 35Building a Simple Model
the blocks in the library In the Sources library, all blocks are signal sources The Sources library window looks like this:
You add blocks to your model by copying them from a block library or from another model For this exercise, you need to copy the Sine Wave block To do this, position the cursor over the Sine Wave block, then press and hold down
the Sine Wave block
Trang 37Building a Simple Model
When the pointer is where you want the block to be in the model window, release the mouse button A copy of the Sine Wave block is now in your model window
In the same way, copy the rest of the blocks into the model window You can move a block from one place in the model window to another using the same dragging technique you used to copy the block You can move a block a small amount by selecting the block, then pressing the arrow keys
With all the blocks copied into the model window, the model should look something like this:
If you examine the block icons, you see an angle bracket on the right of the Sine Wave block and three on the left of the Mux block The > symbol pointing out
of a block is an output port; if the symbol points to a block, it is an input port
A signal travels out of an output port and into an input port of another block through a connecting line When the blocks are connected, the port symbols disappear
You might have noticed that the Mux block has three input ports but only two input signals To change the number of input ports, open the Mux block’s dialog
box by double-clicking on the block Change the Number of inputs parameter
Output portInput port
Trang 38Hold down the mouse button and move the cursor to the top input port of the Mux block Notice that the line is dashed while the mouse button is down and that the cursor shape changes to double-lined cross hairs as it approaches the Mux block.
Now release the mouse button The blocks are connected You can also connect the line to the block by releasing the mouse button while the pointer is inside the icon If you do, the line is connected to the input port closest to the cursor’s position
Trang 39Building a Simple Model
If you look again at the model on page 2–6, you’ll notice that most of the lines connect output ports of blocks to input ports of other blocks However, one line
connects a line to the input port of another block This line, called a branch line,
connects the Sine Wave output to the Integrator block, and carries the same signal that passes from the Sine Wave block to the Mux block
Drawing a branch line is slightly different from drawing the line you just drew
To weld a connection to an existing line, follow these steps:
1 First, position the pointer on the line between the Sine Wave and the Mux
block
2 Press and hold down the Ctrl key on a Windows or X Windows system, or the Option key on a Macintosh Press the mouse button, then drag the
pointer to the Integrator block’s input port or over the Integrator block itself
3 Release the mouse button Simulink draws a line between the starting point and the Integrator block’s input port
Finish making block connections When you’re done, your model should look something like this:
Trang 40Close the Simulation Parameters dialog box by clicking on the Close button
Simulink applies the parameters and closes the dialog box
Choose Start from the Simulation menu and watch the traces of the Scope
block’s input
The simulation stops when it reaches the stop time specified in the Simulation
Stop time parameter