Monday, September 15, 2008

Simulink - A simple introduction...

Simulink (Simulation and Link) is an extension of MATLAB by Mathworks Inc. It works with MATLAB to offer modeling, simulating, and analyzing of dynamical systems under a graphical user interface (GUI) environment. The construction of a model is simplified with click-and-drag mouse operations. Simulink includes a comprehensive block library of toolboxes for both linear and nonlinear analyses. Models are hierarchical, which allow using both top-down and bottom-up approaches. As Simulink is an integral part of MATLAB, it is easy to switch back and forth during the analysis process and thus, the user may take full advantage of features offered in both environments. This tutorial presents the basic features of Simulink and is focused on control systems as it has been written for students in my control systems course.

This tutorial has been written for Simulink v.5 and v.6.

Getting Started

To start a Simulink session, you'd need to bring up Matlab program first.

From Matlab command window, enter:

>> simulink

To see the content of the blockset, click on the "+" sign at the beginning of each toolbox.

To start a model click on the NEW FILE ICON as shown in the screenshot above. Alternately, you may use keystrokes CTRL+N.

A new window will appear on the screen. You will be constructing your model in this window. Also in this window the constructed model is simulated. A screenshot of a typical working (model) window is shown below:

To become familiarized with the structure and the environment of Simulink, you are encouraged to explore the toolboxes and scan their contents. You may not know what they are all about at first, but perhaps you could catch on the organisation of these toolboxes according to their categories. For instance, you may see that the Control System toolbox consists of the Linear Time Invariant (LTI) system library and the MATLAB functions can be found under Function and Tables of the Simulink main toolbox. A good way to learn Simulink (or any computer program in general) is to practice and explore. Making mistakes is part of the learning curve. So, fear not you should be!

A simple model is used here to introduce some basic features of Simulink. Please follow the steps below to construct a simple model.

STEP 1: CREATING BLOCKS.

From BLOCK SET CATEGORIES section of the SIMULINK LIBRARY BROWSER window, click on the "+" sign next to the Simulink group to expand the tree and select (click on) Sources.

A set of blocks will appear in the BLOCKSET group. Click on the Sine Wave block and drag it to the workspace window (also known as model window).

I am going to save this model under the filename: "simexample1". To save a model, you may click on the floppy diskette icon . or from FILE menu, select Save or using keystrokes CTRL+S. All Simulink model file will have an extension ".mdl". Simulink recognizes file with .mdl extension as a simulation model (similar to how MATLAB recognizes files with the extension .m as an MFile).

Continue to build your model by adding more components (or blocks) to your model window. We'll continue to add a Scope from Sinks library, an Integrator block from Continuous library, and a Mux block from Signal Routing library.

NOTE: If you wish to locate a block knowing its name, you may enter the name in the SEARCH WINDOW (at Find prompt) and Simulink will bring up the specified block.

To move the blocks around, simply click on it and drag it to a desired location.

Once you've dragged over all necessary blocks, the workspace window should consist of the following components:

You may remove (delete) a block by simply clicking on it once to turn on the "select mode" (with four corner boxes) and use the DEL key or keys combination CTRL-X.

STEP 2: MAKING CONNECTIONS

To establish connections between the blocks, move the cursor to the output port represented by ">" sign on the block. Once placed at a port, the cursor will turn into a cross "+" enabling you to make connection between blocks.

To make a connection: left-click while holding down the control key (on your keyboard) and drag from source port to a destination port.

The connected model is shown below.

A sine signal is generated by the Sine Wave block (a source) and is displayed by the scope. The integrated sine signal is sent to scope for display along with the original signal from the source via the Mux, whose function is to mutiplex signals in form of scalar, vector, or matrix into a bus.

STEP 3: RUNNING SIMULATION

You now may run the simulation of the simple system above by clicking on the play button. Alternately, you may use keystrokes CTRL+T, or choose Start submenu (under Simulation menu).

Double click on the Scope block to display of the scope.

Saturday, April 12, 2008

Generating C Code

Models built in Simulink can be configured and made ready for code generation. Using Real-Time Workshop and Real-Time Workshop Embedded Coder (available separately), you can generate code from the model for real-time simulation, rapid prototyping, or embedded system deployment

Documenting Your Model

It is easy to add documentation to your Simulink model. Annotations can be added directly in the diagram, and descriptions can be added to each block’s properties. The DocBlock lets you include a text file document as a block within your model. Simulink also offers printing capabilities that let you easily document your model. With one command, you can create a document that describes your entire model, including snapshots of the different levels of hierarchy, and all the block specifications.

You can create customized reports that comply with specific document standards using the Simulink Report Generator

Testing and Validating Your Models

Simulink includes tools to help you generate test conditions and validate your model's performance. These include blocks for creating simulation tests. For example, the Signal Builder block lets you graphically create waveforms to exercise models. Using the Signal & Scope Manager, you can inject signals into your model without adding blocks. Simulink also provides model verification blocks to check that block outputs conform to your design requirements.

You can formally link requirements to sections of the model, test cases, and verification blocks using Simulink Verification and Validation

Executing a Simulation & Analyzing Results

Executing a Simulation

Once you have set the simulation options for your model, you can run a simulation either interactively, using the Simulink GUI, or systematically, by running it in batch mode from the MATLAB command line. You can also use MATLAB commands to load and process model data and parameters and visualize results

Analyzing Results

Simulink includes several tools for analyzing your system, visualizing results, and testing, validating, and documenting your models.

Visualizing Results

You can visualize the system by viewing signals with the displays and scopes provided in Simulink. Alternatively, you can build your own custom displays using MATLAB visualization and GUI development tools.

You can also log signals for post-processing.

The Signal & Scope Manager enables you to connect sources and scopes to models without adding blocks. You can then test multiple scenarios using a series of checkboxes to activate and deactivate sources and scopes. Click on image to see enlarged view.

To gain deeper insight into complex 3-D motion of your dynamic system, you can incorporate virtual reality scenes into your visualization using the Virtual Reality Toolbox (available separately).

Debugging a Simulation

The Simulink debugger is an interactive tool for examining simulation results and locating and diagnosing unexpected behavior in a Simulink model. It lets you quickly pinpoint problems in your model by stepping through a simulation one method at a time and examining the results of executing that method. (Methods are functions that Simulink uses to solve a model at each time step during the simulation. Blocks are made up of multiple methods.)

The Simulink debugger lets you set breakpoints, control the simulation execution, and display model information. It can be run from a graphical user interface (GUI) or from the MATLAB command line. The GUI provides a clear, color-coded view of the model’s execution status. As the model simulates, you can display information on block states, block inputs and outputs, and other information, as well as animate block method execution directly on the model.

The Simulink debugger GUI lets you step through the simulation one method at a time, or run to a breakpoint. Click on image to see enlarged view.

Running a Simulation

Solvers are numerical integration algorithms that compute the system dynamics over time using information contained in the model. Simulink provides solvers to support the simulation of a broad range of systems, including continuous-time (analog), discrete-time (digital), hybrid (mixed-signal), and multirate systems of any size.

These solvers can simulate stiff systems and systems with state events, such as discontinuities, including instantaneous changes in system dynamics.

You can specify simulation options, including the type and properties of the solver, simulation start and stop times, and whether to load or save simulation data. You can also set optimization and diagnostic information for your simulation. Different combinations of options can be saved with the model.

An end-to-end, multirate defense communications system, modeled in Simulink and the Communications and Signal processing blocksets. Simulink solvers automatically determine when to call each block’s methods. Click on image to see enlarged view.

Integrating Procedural Code

With Simulink, you can incorporate MATLAB, C, Fortran, and Ada code directly into a model, enabling you to include handwritten code and create custom blocks and providing an alternative way to represent algorithms in your model.

When you incorporate MATLAB code, you can call MATLAB functions for data analysis and visualization. You can also use an embedded subset of the MATLAB language with Simulink to define embedded, matrix-oriented algorithms. These algorithms can then be deployed through code generation with your embedded designs.

Defining and Managing Signals and Parameters

Simulink enables you to define and control the attributes of signals and parameters associated with your model. Signals are time-varying quantities represented by the lines connecting blocks. Parameters are coefficients that help define the dynamics and behavior of the system.

Signal and parameter attributes can be specified directly in the diagram or in a separate data dictionary. Using the Model Explorer, you can manage your data dictionary and quickly repurpose a model by incorporating different data sets.

You can define the following signal and parameter attributes:

1. Data type - single, double, signed or unsigned 8-, 16-, or 32-bit integers; fixed-point; and Boolean

2. Dimensions - scalar, vector, or matrix

3. Complexity - real, imaginary, or complex number

4. Minimum and maximum range, and engineering units

You can also specify the signal sampling mode as sample-based or frame-based, to enable faster execution of signal processing applications in Simulink and the Signal Processing Blockset (available separately).

Using Simulink data objects, you can define bus signals, data structures, and user-defined data types. Bus signals let you define interfaces between design components. Simulink lets you determine the level of signal specification. If you do not specify data attributes, Simulink determines them via propagation. You can specify only component interfaces or all data for your model. In all instances, Simulink conducts consistency checking to ensure data integrity.

You can restrict the scope of your parameters to specific parts of your model through a hierarchy of workspaces, or share them across models via a global workspace.

Using the Model Explorer, you can navigate, create, configure, and search all signals, parameters, and properties of your model. Click on image to see enlarged view.

Organizing Your Model

Simulink lets you organize your model into clear, manageable levels of hierarchy by using subsystems. Subsystems encapsulate a group of blocks and signals in a single block. They are the primary method for including hierarchy in your model.

You can also segment your model into design components to model, simulate, and verify each component independently. Components can be saved as separate models or as subsystems in a library. They are compatible with configuration management systems, such as CVS and RCS, and with any registered Source Control Provider application on Windows platforms.You can reuse the design components on multiple projects, easily maintaining audit and revision histories.

Organizing your models in this way lets you select the level of detail appropriate to the design task. For example, you can use simple relationships to model high-level specifications and add more detailed relationships as you move toward implementation.

Configurable Subsystems

Configurable subsystems let you associate design variants with subsystems within a model. This capability simplifies the creation and management of designs that share components, as one model can represent a family of designs.

Conditionally Executed Subsystems

Conditionally executed subsystems let you change system dynamics by enabling or disabling specific sections of your design via controlling logic signals. Simulink lets you create control signals that can enable or trigger the execution of the subsystem based on specific time or events.

Control flow and logic blocks let you model simple commands to control enabled or triggered subsystems.

You can include more complex logic, as well as model event-driven systems, with Stateflow (available separately).

Building and Editing Your Model

With Simulink, you build models by dragging and dropping blocks from the library browser onto the graphical editor and connecting them with lines that establish mathematical relationships between the blocks. You have immediate access to common graphical editing functions, such as copy, paste, and undo.

You can connect blocks manually, using the mouse, or automatically, by routing lines around intervening blocks and through complex topologies. Click on image to see enlarged view.

Creating and Working with Models

With Simulink, you can quickly create, model, and maintain a detailed block diagram of your system using a comprehensive set of predefined blocks. Simulink provides tools for hierarchical modeling, data management, and subsystem customization, making it easy to create concise, accurate representations, regardless of your system’s complexity.

Selecting and Customizing Blocks

Simulink includes more than 200 blocks that implement functions commonly used in modeling a system. These include:
1. Continuous and discrete dynamics blocks, such as integration and unit delay
2. Algorithmic blocks, such as sum, product, and lookup tables
3. Structural blocks, such as mux, switch, and signal and bus selectors
You can customize these built-in blocks or create your own. Additional blocksets (available separately) extend Simulink with specific functionality for aerospace, communications, signal processing, and other applications.

You can model physical systems in Simulink. SimMechanics and SimPowerSystems (available separately) provide expanded capabilities for modeling mechanical and electrical systems, respectively.

The Library Browser makes it easy to navigate through standard, add-on, or custom block libraries and drag and drop selected blocks into your model. Click on image to see enlarged view.

Introduction and Key Features


Introduction
Simulink is a platform for multidomain simulation and Model-Based Design of dynamic systems. It provides an interactive graphical environment and a customizable set of block libraries that let you accurately design, simulate, implement, and test control, signal processing, communications, and other time-varying systems.

Add-on products extend the Simulink environment with tools for specific modeling and design tasks and for code generation, algorithm implementation, test, and verification.

Simulink is integrated with MATLAB, providing immediate access to an extensive range of tools for algorithm development, data visualization, data analysis and access, and numerical computation.


Key Features
1. Extensive and expandable libraries of predefined blocks
2. Interactive graphical editor for assembling and managing intuitive block diagrams
3. Ability to manage complex designs by segmenting models into hierarchies of design components
4. Model Explorer to navigate, create, configure, and search all signals, parameters, and properties of your model
5. Ability to interface with other simulation programs and incorporate hand-written code, including MATLAB algorithms
6. Option to run fixed- or variable-step simulations of time-varying systems interactively or through batch simulation
7. Functions for interactively defining inputs and viewing outputs to evaluate model behavior
8. Graphical debugger to examine simulation results and diagnose unexpected behavior in your design
9. Full access to MATLAB for analyzing and visualizing data , developing graphical user interfaces, and creating model data and parameters
10. Model analysis and diagnostics tools to ensure model consistency and identify modeling errors

Simulink - Simulation and Model-Based Design

Simulink is a platform for multidomain simulation and Model-Based Design for dynamic systems. It provides an interactive graphical environment and a customizable set of block libraries, and can be extended for specialized applications

1. Overview and Key Features
2. Creating and Working with Models
3. Running a Simulation
4. Analyzing Results
5. Generating C Code

Simulink - Simulation and Model-Based Design

Simulink is a platform for multidomain simulation and Model-Based Design for dynamic systems. It provides an interactive graphical environment and a customizable set of block libraries, and can be extended for specialized applications