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
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
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 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
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
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.
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
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 >
Enhance a version of the open-loop engine model (sldemo_engine - described in "Modeling Engine Timing Using Triggered Subsystems" example). This model, sldemo_enginewc, contains a
How the Simulink® Project's checks support upgrading from MDL format model files to SLX format. The default file format for Simulink models in R2012b and subsequent releases is SLX.
Model a four-cylinder spark ignition internal combustion engine from the throttle to the crankshaft output. We used well-defined physical principles supplemented, where appropriate,
How one of the engineers who worked on the Apollo Lunar Module digital autopilot design team would have done it using Simulink® if it had been available in 1961.
Use data dictionaries to manage the data for a fuel rate control system designed using Simulink® and Stateflow®. To familiarize yourself with the fuel rate control model see
Model flight control for the longitudinal motion of an aircraft. First order linear approximations of the aircraft and actuator behavior are connected to an analog flight control design
Generate a movie with 64 frames and a frame size of 64 by 64 pixels (at 10 frames per second). The movie contains a simulation of a moving target that is moving through a structured background
Regulate the speed of an electric motor using two degrees-of-freedom PID control with set-point weighting. We use the PID Controller (2DOF) block in Simulink® as shown below.
Model, prototype, tune, and deploy algorithms using Simulink® and Embedded Coder® with the STM32F4 Discovery board. The audio filter tuning example demonstrates this workflow.
A simulink model of Kalman filter organized as a feedback control system
Use MathWorks® software and the Model-Based Development process to go from concept to implementation for a power window system for an automobile.
Write a HIGH or a LOW value to a digital pin. If the pin has been configured as an OUTPUT with pinMode(), its voltage will be set to the corresponding value: 5V (or 3.3V on 3.3V boards) for HIGH, 0V
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
Model an automotive drivetrain with Simulink®. Stateflow® enhances the Simulink model with its representation of the transmission control logic. Simulink provides a powerful
Compares the behavior of messages, events, and data in Stateflow®.
Use the MATLAB Discrete Event System block to write a custom N-Server from which specific entities can be selected using a key lookup. Passengers enter from the IN port of the block and are
Use entity priority to sequence entity departures when multiple entities are available to depart. The example models an airport check-in counter where passengers arrive to be checked in.
Use a MATLAB Discrete Event System block to model a single server that can pause service. The input port IN receives entities to be served. Additionally, the system may receive sporadic pause
Model a single-queue single-server system with a single traffic source and an infinite storage capacity. In the notation, the M stands for Markovian; M/M/1 means that the system has a
Use SimEvents to model a process such as the boarding of an aircraft. The process consists of multiple activities such as "Disembark", "SecurityCheck", "Refueling" etc. Some activities
Different ways to generate and initialize entities and their attribute values.
Model a single-queue single-server system in which the interarrival time and the service time are uniformly distributed with fixed means of 1.1 and 1, respectively. The queue has an
Have you ever been in a supermarket checkout and wondered why you are in the slowest line? This example shows how queuing systems can be modeled in SimEvents for this type of application. Two
Model a single-queue single-server system that has a Poisson arrival process and a server with constant service time. The queue has an infinite storage capacity. In the notation, the M
Use a Discrete-Event Chart block to model a queue-server that can flush entities when it receives a message on the "FlushCmd" port.
Model a central resource that manages distributed processing according to an explicit formula. The example describes a distribution center that manages a series of processes that each job
Open the model to investigate the bicycle assembly line that mathces set of wheels to the corresponding frame for assembly.
How, depending on the workload, a AT90S8535 microcontroller uses a dynamic voltage scaling (DVS) feature to adjust the input voltage. By lowering the input voltage when the workload is low,
Model a customer scheduler using the SimEvents MATLAB Discrete-Event System block. The model includes a Scheduler block that can simulate a multicore system with an arbitrary number of
Model the task scheduling of a control application using SimEvents blocks. SimEvents expands Simulink with the capability to model and simulate architectural components of a real-time
How stochastic network traffic causes timing latency and uncertainty in an anti-lock braking system (ABS) that uses Control Area Network (CAN) communications. The model is
A hybrid system with both continuous time and discrete event sections. The discrete event part models tanks, represented by entities, which are being queued and need to be filled up. Each
A technique for allocating resources from multiple resource pools. It shows how to choose a pool from which to draw a resource, based on given criteria.
The Dining Philosophers problem is a classical problem, originally formulated by E.W. Dijkstra, to demonstrate classical problems in computer science and the programming of concurrent
Model and optimize the use of shared resources in a system, to identify resource deficiencies and improve capacity planning. The example is based on a batch production process, where
A single-phase dynamic load block built with Simulink® blocks.
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.
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.
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.
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.
A model of a solid oxide fuel cell (SOFC) which can be utilized in Specialized Power Systems.
An aircraft electrical power generation and distribution system. The AC power frequency is variable and depends of the engine speed
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
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.
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
An average model of a distribution STATCOM.
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 quadcopter, based on the PARROT® series of mini-drones.
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.
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™ Electrical™ Power Systems model of a Boost Converter. The LPV representation allows quick analysis of average
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 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 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
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 estimate multiple parameters of a model by iterated estimations.
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.
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
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.
Trim and linearize an airframe using Simulink® Control Design™ software
Use Simulink® Design Optimization™ to optimize the temperature control of a heat exchanger around a temperature set-point.
This model shows how to compute the indicated airspeed from true airspeed using the Ideal Airspeed Correction block. The Aerospace Blockset™ blocks are indicated in red.
Plot linearization of a Simulink model at particular conditions during simulation. The Simulink Control Design software provides blocks that you can add to Simulink models to compute and
This model shows how to compare the implementation of a state-space controller [A,B,C,D] in a self-conditioned form versus a typical state-space controller [A,B,C,D]. This model
Create an estimation experiment from measured data stored in a file and how to preprocess the measured data. You use the imported data to estimate the parameters of a simple RC circuit.
Design a PI control system to control the speed of a DC motor, and is based on the Control System Toolbox™ example "DC Motor Control".
Model computational delay and sampling effect using Simulink Control Design.
How 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
This model shows how to simulate a key multi-discipline design problem from the Aerospace Defense industry sector.
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 two different options for modeling S-parameters with the RF Blockset™ Circuit Envelope library. The Time-domain (rationalfit) technique creates an analytical rational model that
Use the RF Blockset™ Circuit Envelope library to test intermodulation distortion of an amplifier using two-carrier envelope analysis.
Set up a radar system simulation consisting of a transmitter, a channel with a target, and a receiver. For the Aerospace Defense industry, this is an important multi-discipline problem. RF
Use the RF Blockset™ Circuit Envelope library to calculate the image rejection ratio (IRR) for high-side-injection in Weaver and Hartley receivers. The Weaver receiver shows the effect of
Use Input Port and Output Port blocks of the RF Blockset™ Equivalent Baseband library to convert between dimensionless Simulink signals and equivalent-baseband signals.
This model shows the relationship between two signal representations in RF Blockset™ Circuit Envelope: complex baseband (envelope) signal and passband (time domain) signal. The step
Use the Model-Based Design methodology to overcome the challenge of exchanging specifications, design information, and verification models between multiple design teams working on a
Use the RF Blockset™ Circuit Envelope library to run a two-tone experiment that measures the second- and third-order intercept points of an amplifier. The model computes the intercept
Write your own nonlinear RF Blockset Circuit Envelope model in Simscape® language, build the custom library and use it in RF Blockset simulation.
This model shows how to use blocks from the RF Blockset™ Equivalent Baseband library to build cascaded RF systems.
This model shows three different ways to use RF Blockset™ Equivalent Baseband library blocks and RF Toolbox™ objects to implement filters.
Recognize traffic warning signs, such as Stop, Do Not Enter, and Yield, in a color video sequence.
Process surveillance video to select frames that contain motion. Security concerns mandate continuous monitoring of important locations using video cameras. To efficiently record,
Use the From Video Device block provided by Image Acquisition Toolbox™ to acquire live image data from a Hamamatsu C8484 camera into Simulink®. The Prewitt method is applied to find the edges
Create an image processing system which can recognize and interpret a GTIN-13 barcode. The GTIN-13 barcode, formally known as EAN-13, is an international barcode standard. It is a superset
Segment video in time. The algorithm in this example can be used to detect major changes in video streams, such as when a commercial begins and ends. It can be useful when editing video or when
Use the From Video Device block provided by Image Acquisition Toolbox™ to acquire live image data from a Point Grey Flea® 2 camera into Simulink®. The example uses the Computer Vision System
Use sum of absolute differences (SAD) method for detecting motion in a video sequence. This example applies SAD independently to four quadrants of a video sequence. If motion is detected in a
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
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
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
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
Communicate with the FPGA IP core on the Zynq hardware using AXI4®-Lite protocol. AXI4 (Advanced eXtensible Interface 4) is an ARM® standard.
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 Toolbox™ to verify the HDL implementation model.
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.
Open up the "Controller" subsystem. Open the Stateflow® chart named "Control" chart inside it. This chart implements the control logic for starting and stopping the conveyer belt motor
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
Use Xilinx® System Generator for DSP with HDL Coder™.
This model shows how to integrate user defined function blocks, data types and global variables into generated structured text
This model shows how tunable parameters map to Structured Text by specifying them as Simulink.Parameter objects in MATLAB base workspace.
Use HDL Coder™ to check, generate and verify HDL for a fixed-point CORDIC model implementing sin and cos trigonometric functions using the MATLAB Function Block.
This model shows the code generated for a Feedforward PID Controller implemented using Simulink library blocks.
Sample fixed-point implementations of a discrete lead filter and a discrete lag filter along with reference implementations in floating point.
This model shows how to exercise a custom C language S-function written to compute a fixed-point "product and sum" operation. To see the source code for the S-function, use the right-click
In this model, the model solver is set to variable-step continuous (ode45); the sample time of the controller subsystem is set to 0.05. To set the controller sample time, right click on the
This model shows the code generated for a Stateflow chart.
Find the approximation to an ideal function of y = sin(2*pi*x) over an input range [xmin,xmax] using a lookup table approach. Fixed-point applications often need to approximate a function
This model shows the code generated for a MATLAB block implementing tank valve control logic.
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
A real-time filter built using DSP System Toolbox™ and Simulink Desktop Real-Time™. The unfiltered signal is acquired by the analog input, passed through a filter designed by DSP System
Build a simple closed-loop real-time controller using Simulink Desktop Real-Time™. The output of the controlled plant is connected to the analog input of your data acquisition board. This
Produce an analog output signal using Simulink Desktop Real-Time™. Because analog output typically requires less configuration and is easier to connect than analog input, this model is a
Transfer data through CAN bus, utilizing the CAN_MESSAGE data type and the CAN Pack and CAN Unpack blocks available in Vehicle Network Toolbox block library. The CAN_MESSAGE data type can be
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 virtual channels or physical channels on a
Transfer data through TCP communication protocol using ASCII encoding. The model sends data within one computer, from one TCP port to another. You can modify the model to communicate
Measure PWM signal frequency and duty using Simulink Desktop Real-Time™. The measured signal is connected to gate pins of two counter inputs of your data acquisition board. The first
Analyze model execution performance in Simulink Desktop Real-Time™. The example is a multirate multi-tasking model that performs a time-intensive operation of matrix multiplication
Measure input signal frequency using Simulink Desktop Real-Time™. The measured signal is connected to the counter input of your data acquisition board. Counter Input block is configured
Transfer data through UDP communication protocol using binary encoding. The model sends data within one computer, from one UDP port to another. You can modify the model to communicate
A real-time version of the Simulink® Van der Pol simulation model.
Starting from the model template for Simulink Desktop Real-Time provides a new model that has configuration parameters set up for building a real-time application. This example shows how
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 response on the gauges.
A data acquisition target computer that transmits timestamped data to a second target computer that analyzes the data.
Implement a Simulink® algorithm on a Speedgoat FPGA I/O board by using HDL Workflow Advisor to:
A workflow that uses HDL Coder™ to deploy a Simulink® subsystem to a Speedgoat FPGA I/O board that resides in the target computer. A Simulink® Real-Time™ application runs on the target
Read CPU temperature in degrees Celsius (°C).
How Simulink® Real-Time™ can drive a target application not only with interrupts based on its internal timer, but also with interrupts based on an external signal.
Model shows how to send ASCII data over a serial link.
Filtering Ethernet data using MAC addresses.
This model shows the ability of the FIFO Read BINARY block to handle messages that are interrupted and only partially complete. This is a 'worst case' example where every message is
This model shows how to send Binary data over a serial link.
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.
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
This example was authored by the MathWorks community.
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
Model temporal system requirements in a power window controller model for property proving and test case generation using Simulink® Design Verifier™ Temporal Operator blocks.
Verify safety properties in a thrust reverser design model.
Generate test cases that achieve complete model coverage for a flip-flop.
Find a property violation using Simulink Design Verifier property proving analysis.
Perform a Simulink Design Verifier property proof using a Proof Assumption block.
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.
Generate test cases that achieve complete model coverage.
Constrain input values by using Test Condition block.
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.
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.
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
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
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
Illustrates the use of the Simulink® 3D Animation™ with the MATLAB® interface for manipulating complex objects.
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 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
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
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
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
Portal Crane with Control Panel
Choose a web site 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 web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office