MATLAB Examples

Use the model of the missile airframe presented in a number of published papers (References [1], [2] and [3]) on the use of advanced control methods applied to missile autopilot design. The

Combine Stateflow® with Simulink® to efficiently model hybrid systems. This type of modeling is particularly useful for systems that have numerous possible operational modes based on

Simulate the working of an automatic climate control system in a car using Simulink® and Stateflow®. You can enter a temperature value you would like the air in the car to reach by double

Examples to use the Simulink model kalmanfilter. By Yi Cao at Cranfield University on 25 January 2008

Use two different approaches to modeling a bouncing ball using Simulink®.

Use an extended Kalman filter with the MATLAB® Function block in Simulink® to estimate an aircraft's position from radar measurements. The filter implementation is found in the MATLAB

Model an automotive drivetrain with Simulink®. Stateflow® enhances the Simulink model with its representation of the transmission control logic. Simulink provides a powerful

How zero crossings work in Simulink®. In this model, three shifted sine waves are fed into an absolute value block and saturation block. At exactly t = 5, the output of the switch block changes

Model a conceptual air traffic control (ATC) radar simulation based on the radar range equation.

Use the Control System Toolbox™ and Simulink® Control Design™ to interact with Simulink to design a digital pitch control for the aircraft. In this example, we will design the controller to

Use anti-windup schemes to prevent integration wind-up in PID controllers when the actuators are saturated. We use the PID Controller block in Simulink® which features two built-in

Approximate nonlinear relationships of a type S thermocouple.

Simulate the electrical system of a vehicle using Simulink® and Simscape™ Power Systems™.

Model a simplified half-car model that includes an independent front and rear vertical suspension. The model also includes body pitch and bounce degrees of freedom. The example provides a

Use Simulink® to model a hydraulic cylinder. You can apply these concepts to applications where you need to model hydraulic behavior. See two related examples that use the same basic

Interface the vehicle climate control system with a model of the electrical system to examine the loading effects of the climate control system on the entire electrical system of the car.

Use Simulink® to create the thermal model of a house. This system models the outdoor environment, the thermal characteristics of the house, and the house heating system.

Model a simple model for an Anti-Lock Braking System (ABS). It simulates the dynamic behavior of a vehicle under hard braking conditions. The model represents a single wheel, which may be

------------------------------------------------------------------------%

- Low speed model is not perfect, review the effect on pneumatic trail (t) and aligning torque (Mz) - Turn slip equations needs to be reviewed, specially for Mz

Simulate a simple closed-loop control algorithm in Simulink® and how to run it on LEGO® MINDSTORMS® EV3™ hardware.

This page provides examples of the commands needed to find library links in a model. For a graphical way to investigate library links, see the Model Advisor.

Model six degrees of freedom motion in Simulink®. You can switch between using Euler Angles and Quaternions to model the equations of motion, using the Variant Subsystem block's "Variant >

The model of a permanent magnet DC motor. The mode logic and dynamics of the DC motor are both modeled using Stateflow.

This model shows a simple use of Simulink functions in Stateflow. Starting from R2008b, you can use Simulink function call subsystems in Stateflow just like other function objects such as

A model that demonstrates a basic temperature control simulation that allows you to enter the temperatures and the power of the air conditioner that you want to use.

Model a popular toy called "Newton's cradle" which consists of a row of seven identical balls which are hung from a common height. At rest they are arranged such that they just touch each other.

Models an intersection of two 1-way roads controlled by a Stateflow® traffic light system. The Stateflow® chart uses active state outputs and a mask. The behavior of the traffic lights is

The use of flow charts in a Stateflow® C chart to create C statements such as the FOR loop. This particular example shows how you can create a simple FOR Loop that defines an array variable. The

How a WHILE loop and a DO-WHILE can be implemented in Stateflow® in order to create a variable array. The equivalent statements in C-Code are as follows:

This model shows how you can schedule a Simulink algorithm using Stateflow.

This model shows a re-visit of the classic tetris game which has been shipping with Stateflow® to use some of the more modern programming paradigms and features. It shows the use of the

The use of flow charts in Stateflow® to create C or MATLAB® statements such as the IF - ELSE statement. This particular example shows how you can create a simple IF - ELSE statement in Stateflow.

The example shows the ability of Stateflow® to accept matrix input signals from Simulink® and also output matrix signals to Simulink. In this particular example, we are multiplying a [2x2]

The use of Simulink® and Stateflow® to model a hydraulic servomechanism controlled by a pulse-width modulated (PWM) solenoid. This type of motion control system is used in industrial,

This model shows how you can design switching controllers by combining the power of Stateflow and Simulink functions.

The State Transition Matrix view for a simple model of a debouncing logic that uses State Transition Tables in Stateflow® (new in R2012b).

Design a fault detection, isolation, and recovery (FDIR) application for a pair of aircraft elevators with redundant actuators. The fault detection control logic used in this model is the

Use Stateflow® to model a bang-bang control system that regulates the temperature of a boiler. The boiler dynamics are modeled in Simulink® in a boiler plant model.

Model a home alarm system including motion sensors. Like in modern alarm systems, if the system detects an intrusion, it allows a certain (small) time for the alarm to be disabled, otherwise

This model shows the basic semantics of absolute time temporal logic in Stateflow®.

This model shows a method for measuring the frequency response of a continuous time system (plant) using Stateflow®. It illustrates several features of Stateflow® such as the

This model shows how to define continuous time state variables and their derivatives in Stateflow®. The dynamics of a bouncing ball can be defined in terms of two continuous time variables,

The concept of a graphical function and how it can be used to simplify your Stateflow® model. In this example, we pass two inputs in the Stateflow chart. The first input is a sine wave with

The advantage of using the EVERY function to call a graphical function when certain events occur. Notice how complicated it becomes when you try to accomplish the same behavior without the

Model a launch abort system. An aircraft is launched into outer space. If an anomaly or fault occurs during the launch, the operation is aborted, and the aircraft is sent back down to Earth.

The starting procedure for a synchronous motor.

Phasor simulation of a 9-MW wind farm using Induction Generators (IG) driven by variable-pitch wind turbines.

A detailed model of a 100-kW array connected to a 25-kV grid via a DC-DC boost converter and a three-phase three-level VSC.

Model a lithium cell using the Simscape™ language to implement the elements of an equivalent circuit model with two RC branches. For the defining equations and their validation, see T.

The Antoine class provides a computational framework to help doing simple vapor-liquid equilibrium calculations in Matlab. These notes introduce Antoine's equation, then shows how the

The measurement distortion due to saturation of a current transformer (CT).

The simulation of an H-bridge used to generate a chopped voltage and to control the speed of a DC motor.

An average model of a 100-kW array connected to a 25-kV grid via a DC-DC boost converter and a three-phase three-level VSC.

The Machine Load Flow tool of Powergui block to initialize an induction motor/diesel-generator system.

A current-controlled 60-kW 6/4 SRM drive using the SRM specific model based on measured magnetization curves. 8/6 and 10/8 preset models are also presented with same control strategy.

Energy management systems for a fuel cell hybrid electric source.

The operation of two models of on load tap changer (OLTC) regulating transformer.

An ideal AC transformer plus full-wave bridge rectifier. It converts 120 volts AC to 12 volts DC. The transformer has a turns ratio of 14, stepping the supply down to 8.6 volts rms, i.e.

How the Simscape™ Foundation Library Asynchronous Sample & Hold block can be used to build components with more complex behaviors. The model implements a controllable PWM voltage source

An aircraft electrical power generation and distribution system. The AC power frequency is variable and depends of the engine speed

This example was authored by the MathWorks community.

The operation of a typical transformerless photovoltaic (PV) residential system connected to the electrical utility grid.

Models a vapor-compression refrigeration cycle using two-phase fluid components. The compressor drives the R-134a refrigerant through a condenser, an expansion valve, and an

Phasor simulation of a 9 MW wind farm using Doubly-Fed Induction Generator (DFIG) driven by a wind turbine.

An average model of a distribution STATCOM.

Use functions which analyze Simscape™ logging data to get harmonic magnitudes, calculate total harmonic distortion percentage and plot harmonic magnitudes. The model to which this

The use of the Three-Phase Transformer Inductance Matrix Type block to model a three-phase core-type saturable transformer. It also shows that using three single-phase transformers to

A six-pulse cycloconverter driving a static load.

Use Simulink® to model a toy quadcopter, based on the Parrot (R) series of mini-drones, to help estimate the snow levels on the MathWorks Apple Hill campus roof.

How the Sphero Connectivity Package can be used to connect to a Sphero device and perform basic operations on the hardware, such as change the LED color, calibrate the orientation of the robot

Control the motion of a Sphero using the Sphero Connectivity Package

Describes the Simulink library for the Sphero Connectivity package, and how the blocks from the library can be used to control a Sphero.

Sphero is not listed under available devices when creating the sphero object, or the following error is received:

Automatically tune a PID Controller block using PID Tuner.

This model shows how to use MathWorks® products to address the technical and process challenges of aircraft design using the design of a lightweight aircraft.

Tune a PID controller for plants that cannot be linearized. You use the PID Tuner to identify a plant for a buck converter. Then tune the PID controller using the identified plant.

Estimate the parameters of a multi-domain DC servo motor model constructed using various physical modeling products.

Obtain a Linear Parameter Varying (LPV) approximation of a Simscape Power Systems™ model of a Boost Converter. The LPV representation allows quick analysis of average behavior at various

Use numerical optimization to tuning the controller parameters of a nonlinear system. In this example, we model a CE 152 Magnetic Levitation system where the controller is used to position a

Automatically generate a MATLAB function to solve a Design Optimization problem. You use the Response Optimization tool to define an optimization problem for a hydraulic cylinder design

Use Simulink® Design Optimization™ to optimize the controller of an inverted pendulum. The inverted pendulum is on a cart and the motion of the cart is controlled. The controller's

Use Simulink Control Design, using a drum boiler as an example application. Using the operating point search function, we illustrate model linearization as well as subsequent state

This model shows the simulation of multiple aircraft in formation flight, with emphasis on the necessary requirements and the realized benefits in making the simulation vectorized so that

This document describes how to use the Flight Simulation project template using Simulink® Projects. This template provides a framework for the collaborative development of a flight

Use Simulink® Design Optimization™ to estimate multiple parameters of a model by iterated estimations.

This model shows how to model the Wright Brother's 1903 Flyer modeled in Simulink®, Aerospace Blockset™ and Simulink® 3D Animation™ software. This model simulates the longitudinal motion

Use Simulink® Design Optimization™ to tune the gains of the PID controller (Kp, Ki, and Kd) and optimize the step response of the plant. To view the results, use the following steps.

Use parallel computing to optimize the time-domain response of a Simulink® model. You use Simulink® Design Optimization™ and Parallel Computing Toolbox™ to tune the gains of a discrete PI

This model shows how to compute true airspeed from indicated airspeed using the Ideal Airspeed Correction block. The Aerospace Blockset™ blocks are indicated in red.

This model shows how to model the DeHavilland Beaver using Simulink® and Aerospace Blockset™ software. It also shows how to use a pilot's joystick to fly the DeHavilland Beaver This model has

Tune multiple compensators (feedback and prefilter) to control a single loop.

Filter a sinusoid with the Overlap-Add and Overlap-Save FFT methods using the Frequency-Domain FIR filter block.

The basic structure of turbo codes, both at the transmitter and receiver ends, and characterizes their performance over a noisy channel using components from the Communications System

This model shows how to simulate a phase-locked loop (PLL) frequency synthesizer. The model multiplies the frequency (synFr) of a reference signal by a constant synN/synM, to produce a

This model shows a satellite link, using the blocks from the Communications System Toolbox™ to simulate the following impairments:

This model shows how to use the SISO Fading Channel block from the Communications System Toolbox™ to simulate multipath Rayleigh and Rician fading channels, which are useful models of

This model shows symbol timing adjustments using interpolation and numerically controlled oscillator (NCO) based control as part of clock recovery in a digital modem as described in the

This model shows the implementation of a QPSK transmitter and receiver. The receiver addresses practical issues in wireless communications, e.g. carrier frequency and phase offset,

This model shows the state-of-the-art channel coding scheme used in the second generation Digital Video Broadcasting standard (DVB-S.2), planned to be deployed by DIRECTV in the United

This model shows an adaptive orthogonal space-time block code (OSTBC) transceiver system over a multiple-input multiple-output (MIMO) channel. The system uses a variable number of

Model analog-to-digital conversion using a sigma-delta algorithm implementation.

How to:

This model shows the effects of adjacent and co-channel interference on a PSK modulated signal. The model includes two interferers, Interferer 1 and Interferer 2. The model enables you to

Simulate delay-based and lumped-element transmission lines using blocks in the RF Blockset™ Circuit Envelope library. The example is sequenced to examine circuit envelope and passband

HDL code generation support for the Viterbi Decoder block. It shows how to check, generate, and verify the HDL code you generate from a fixed-point Viterbi Decoder model. This example also

This model shows how to simulate a key multi-discipline design problem from the Aerospace Defense industry sector.

This model shows how to use the Convolutional Encoder and Viterbi Decoder blocks to simulate a tail-biting convolutional code. Terminating the trellis of a convolutional code is a key

This model shows the improvement in BER performance when using log-likelihood ratio (LLR) instead of hard decision demodulation in a convolutionally coded communication link.

This model shows the nonlinear effect of a RF Blockset™ Equivalent Baseband amplifier on a 16-QAM modulated signal.

Use blocks from the RF Blockset™ Circuit Envelope library to simulate a transmit/receive duplex filter and calculate frequency response curves from a broadband white-noise input. Blocks

Use the RF Blockset™ Circuit Envelope library to simulate the sensitivity performance of a direct conversion architecture with the following RF impairments:

This model shows how to simulate a phase-locked fractional-N frequency synthesizer. The model multiplies the frequency synFr of a reference signal by a constant synN+synM, to produce a

Simulate steady-state behavior of a fixed-point digital down converter for GSM (Global System for Mobile) baseband conversions. The example model uses blocks from Simulink® and the DSP

Use two different options for modeling S-parameters with the RF Blockset™ Circuit Envelope library. Time-domain (rationalfit) technique creates an analytical rational model that

Use the function fixpt_look1_func_plot to find the maximum absolute error for the simple lookup table whose breakpoints are 0, 0.25, and 1. The corresponding Y data points of the lookup

Open up the "Controller" subsystem. Notice that this model uses a Triggered Stateflow® Chart to do the "Enable" and "Setpoint" calculation. It uses a discrete PID Controller to compute the

Demonstrates how to use the Embedded Coder Support Package for STMicroelectronics Discovery Boards to run a Simulink® model on an STMicroelectronics STM32F4-Discovery board or

Generate a cosimulation model in of HDL Coder and integrate the generated HDL code into an HDL Verifier™ workflow. Automation of cosimulation model generation enables seamless

The Target for TI HERCULES RM48 MCUs package is dependent on a number of other Mathworks and TI software products. Before continuing, please make sure that all required prerequisites are

Model a controller and implement it on a Xilinx® Zynq™-7000 All Programmable SoC target. This example is based on a ZedBoard using an Analog Devices motor control FMC board. Note that if you do

This function must be customized and then executed before the target support package for TI RM48 MCUs will run properly. Note: if you are viewing the abbreviated form of this help through the

Run a processor in the loop (PIL) Simulation using the Target for TI HERCULES™ RM48 MCUs package.

Communicate with the FPGA IP core on the Zynq hardware using AXI4®-Lite protocol. AXI4 (Advanced eXtensible Interface 4) is an ARM® standard.

Copyright (C) 2012-2014 Texas Instruments Incorporated - http://www.ti.com/

Model a three band parametric equalizer algorithm and run it on the ARM® Cortex M based STMicroelectronics® STM32 Discovery boards.

This function performs simple checks on the preferences configured by the function TI_HERCULES_RM48_setup(). These checks are limited to confirmation that paths and certain

Use the GPIO blocks in the STMicroelectronics STM32F4-Discovery library to control the push-button and the LED's on the STMicroelectronics STM32F4-Discovery board.

Use the Embedded Coder Support Package for ARM Cortex-M Processors to run a Simulink model on an ARM Cortex-M3 emulator provided by QEMU.

HDL support is provided for Gamma correction in Vision HDL Toolbox™. This example demonstrates the functionality of the pixel-stream Gamma Corrector block and compares the results with

Utilize RAM resources in your FPGA design using HDL Coder™.

Build an LTE compliant OFDM Modulator and Detector for implementation with HDL Coder™, and use LTE System Toolbox™ to verify the HDL implementation model.

Use Embedded Coder Support Package for STMicroelectronics Discovery Boards for code verification and validation using PIL and External mode.

Use code replacement libraries for ARM Cortex-M processors to generate optimized code for the STMicroelectronics STM32F4-Discovery board.

Instantiate multiple top-level synchronous clock input ports in HDL Coder.

This model shows the code generated for a Stateflow chart which uses absolute time temporal logic. Simulate the model. Click on the scope to observe the "pulse" output.

The RSim target was designed to let you run batch simulations at the fastest possible speed. Using variable-step or fixed-step solvers with RSim combined with the use of a tunable parameter

The example model "sldrtex_canio" shows how to transfer data through CAN bus. The model sends data within one computer, from one CAN channel to another. The two CAN channels can be either

The example model "sldrtex_counter" shows how to measure input signal frequency using Simulink Desktop Real-Time™. The measured signal is connected to the counter input of your data

The example model "sldrtex_streamio" shows how to transfer data through UDP communication protocol using ASCII encoding. The model sends data within one computer, from one UDP port to

The example model "sldrtex_packetio" shows how to transfer data through UDP communication protocol using binary encoding. The model sends data within one computer, from one UDP port to

The example model "sldrtex_controller" shows how to build a simple closed-loop real-time controller using Simulink Desktop Real-Time™. The output of the controlled plant is connected to

The example model "sldrtex_siggen" shows how to produce an analog output signal using Simulink Desktop Real-Time™. Because analog output typically requires less configuration and is

The example model "sldrtex_vdp" shows a real-time version of the Simulink® Van der Pol simulation model. This model does not need any external signals, so it does not need any data

The example model "sldrtex_pwmmeasure" shows how to measure PWM signal frequency and duty using Simulink Desktop Real-Time™. The measured signal is connected to gate pins of two counter

The example model "sldrtex_filter" shows a real-time filter built using DSP System Toolbox™ and Simulink Desktop Real-Time™. The unfiltered signal is acquired by the analog input, passed

The example model "sldrtex_canmessage" shows how to transfer data through CAN bus, utilizing the CAN_MESSAGE data type and the CAN Pack and CAN Unpack blocks available in Vehicle Network

The example model "sldrtex_dashboard" shows a real-time model of a water tank controlled by dashboard controls. You can change the inputs to the plant using the knobs and observe the

The example model "sldrtex_profiling" shows how to analyze model execution performance in Simulink Desktop Real-Time™. The example is a multirate multi-tasking model that performs a

Use Simulation Data Inspector (SDI) to log signal data from the real-time application. Use Simulink® external mode to establish a communication channel between your Simulink® block

Perform a frequency-response test of the model ex_slrt_slt_osc (matlab:open_system(docpath(fullfile(docroot, 'toolbox', 'xpc', 'examples', 'ex_slrt_slt_osc')))).

Create a Simulink® Real-Time™ Explorer instrument panel for the xpctank model. The instrument panel contains the following instruments:

Use Simulation Data Inspector (SDI) to log signal and task execution time (TET) data from the real-time application. You can select signals for display from models referenced at arbitrary

A data acquisition target computer that transmits timestamped data to a second target computer that analyzes the data.

Use Performance Advisor to detect blocks and parameter settings that can reduce performance. It determines the lower limit on sample time that does not produce a CPU overload.

Profile the task execution time and function execution time of your real-time application running on the target computer. Using that information, you can then tune its performance.

These examples demonstrate charting with the fanChart visualization function

The tidal fitting toolbox simplifies the task of fitting tide models to time series. It is split into a tidalfit and a tidalval functions using the the familiar structure of polyfit and

Use Simulink® Design Verifier™ functions to log input signals, create a harness model, generate test cases for missing coverage, merge harness models, and execute test cases.

Use Simulink® Design Verifier™ functions to replace unsupported blocks and to how customize test vector generation for specific requirements.

Verify the seat belt reminder design model referenced in the top block above.

How Simulink® Design Verifier™ can extend test cases with additional time steps to efficiently generate complete test suites.

Use Simulink® Design Verifier™ to extend an existing test suite to obtain missing model coverage.

The use of two custom Test Objective blocks.

How Simulink® Design Verifier™ can target its analysis to a single subsystem within a continuous-time closed-loop simulation and generate test cases for missing coverage in that

Generate test cases that achieve complete model coverage for a flip-flop.

Verify safety properties in a thrust reverser design model.

Find a property violation using Simulink Design Verifier property proving analysis.

Model temporal system requirements in a power window controller model for property proving and test case generation using Simulink® Design Verifier™ Temporal Operator blocks.

Perform a Simulink Design Verifier property proof using a Proof Assumption block.

Generate test cases that achieve complete model coverage.

Use input port minimum and maximum values as analysis constraints by Simulink Design Verifier during both test generation and property proving.

Model temporal system requirements for property proving and test case generation using Simulink® Design Verifier™ Temporal Operator blocks.

Constrain input values.

Prove properties in a fixed-point cruise control algorithm.

Use Simulink® Design Verifier™ command-line functions to generate test data that incorporates different parameter values.

Generate test cases that satisfy Decision, Condition, and MCDC coverage.

The vr_octavia example shows the benefits of visualization of complex dynamic model in the virtual reality environment. It also shows Simulink® 3D Animation™ 3D off-line animation

Illustrates the possibility to convert generally available Digital Elevation Models into VRML format for use in virtual reality scenes.

Extends the vr_octavia example to show multiple-object scenario visualizations.

Use the Space Mouse via MATLAB® interface.

The vrcrane_joystick example illustrates how a Simulink® model can interact with a virtual world. The portal crane dynamics is modeled in Simulink and visualized in virtual reality. The

The vrmemb example shows how to use a MATLAB® generated 3-D graphic object with the Simulink® 3D Animation™. The famous membrane was generated by the logo function and saved in the VRML format

The vrplanets example shows the dynamic visualization of the first 4 planets of the Solar system, Moon orbiting around Earth and Sun rotating itself. The model uses the real properties of the

Illustrates use of the Simulink Report Generator to verify that a wing flutter suppression system design meets its design requirement. The example exploits the Report Generator's ability

Extends the vr_octavia example and shows how to combine virtual reality canvas in one figure with other graphical user interface objects. In this case, three graphs are displayed under the

Illustrates the use of the Simulink® 3D Animation™ MATLAB® interface. In a step-by-step tutorial, it shows commands for querying and manipulating virtual world objects. You will learn

The vrmanipul_stereo3d example shows a manipulator in active stereoscopic vision mode. It illustrates the effect of stereo rendering properties and the way how to work with the

The vrbounce example visualizes a ball bouncing from a floor. The ball deforms as it hits the floor keeping the volume of the ball constant. The deformation is achieved by modifying the scale

The vrpend example illustrates the various ways a dynamic model in Simulink® can interact with a virtual reality world. It is the model of 2-dimensional inverted pendulum controlled by a PID

Use Simulink® Report Generator™ to create a System Design Description report for a model. The report provides summary or detailed information about a system design represented by a

Illustrates the use of the Simulink® 3D Animation™ with the MATLAB® interface for manipulating complex objects.

Illustrates the use of Simulink® 3D Animation™ MATLAB® interface to create 2D off-line animation files.

Illustrates the use of global coordinates in Simulink® 3D Animation™ models. Global coordinates can be used in the model in many ways for object tracking and manipulation, simple collision

Use Simulink® Report Generator™ to customize a System Design Description report for a model. The default version of the report provides information about a system design represented by a

This model illustrates the use of Simulink® 3D Animation™ for virtual reality prototyping and testing the viability of designs before the implementation phase. Also, this example

Plane Take-Off with Trajectory Tracing

This model represents a tutorial example described in the documentation. See the 'Displaying a Virtual World' chapter in the Simulink 3D Animation User's Guide.

Vrmaglev is an example showing the interaction between dynamic models in Simulink® and virtual worlds. The Simulink® model represents the HUMUSOFT® CE152 Magnetic Levitation

Choose your country to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a location from the following list:

See all countries