Professional Documents
Culture Documents
Embedded MATLAB
SahngHoh Kwon
1
Agenda
Introduction
– Challenges of the MATLAB-to-C workflow
What is Embedded MATLAB?
– Benefits of the Embedded MATLAB workflow
How to use Embedded MATLAB?
– Demonstration
– Tracking a moving object with a Kalman filter
Summary
2
Traditional Concept to Implementation
Assembly code
MATLAB code C/C++ code
HDL
Re-implement
as you go down the level of abstraction
This workflow requires you to:
maintain multiple copies of the same algorithm
fix and test across implementation boundaries
Workflow challenges:
time-consuming and error-prone
not scalable to the system level
3
A better workflow would be…
One language
– No multiple copies of source code
– No redundant debugging and testing
One integrated design environment
– Integrated real-world design constraints in MATLAB
– Integrated visualization, analysis, and debugging
– Ease of porting individual algorithm IPs in MATLAB
Automatic code generation
– Path to embedded software ( MATLAB to C)
4
What Is Embedded MATLAB?
Embedded MATLAB is the subset of MATLAB for embedded algorithm
development
objects
java
variable-sized data sparse
struct visualization
functions
Embedded
numeric arrays analysis
complex cellarrays
fixed-point
nested functions
5
Features of Embedded MATLAB
6
Generating C Code Automatically
with Embedded MATLAB Subset
1. Examine your original MATLAB algorithm.
2. If necessary, modify it to conform with the Embedded MATLAB subset.
3. Generate C code using the emlc command.
4. If necessary, iterate to optimize the MATLAB code for memory and
speed.
5. Verify easily within MATLAB.
MEX
8
Kalman Demonstration Workflow
9
Variable-Size Data Supported in
MATLAB-to-C Code Generation
Define variable-size inputs, outputs, and local variables, with known
upper bounds.
Expands the scope of automatic C code generation for typical MATLAB
algorithm
Ensures static memory allocation in generated C code for variables that
change in size during execution
10
Fixed-Point Acceleration:
Introducing emlmex Function
Automatically generates C-MEX
function from MATLAB function
(MATLAB algorithm must
conform to Embedded MATLAB
language subset.)
11
C Code Generation from MATLAB:
Introducing emlc Function
Automatically generates C source
code from your Embedded
MATLAB code, from the MATLAB
command line
12
Product Licensing Requirements
Capability Required Product
Generate embeddable C code using emlc MATLAB, Simulink, and
command Real-Time Workshop
13
Domains
MATLAB® Simulink®
• Algorithm development • Graphical models
Embedded MATLAB™ Embedded MATLAB™ • Time-based simulation
• Data analysis
• Advanced visualization
code functions • Multi domain modeling
• System verification
14
Embedded MATLAB™ functions
in Simulink®
Power of MATLAB in Simulink Embedded MATLAB
runtime library
Math-intensive algorithm
15
Demo: Inverse Kinematics of Robot
Manipulator
16
Calling External C Code from an
Embedded MATLAB™ Function
pythagoras_lct.c
17
Summary(1)
Embedded MATLAB is the subset of the MATLAB
language for embedded implementation
– 300 MATLAB operators and functions
– 110 Fixed-Point Toolbox functions
– 40 Signal Processing Toolbox functions
18
Summary(2)
emlc command
– Automatically generate C source code from your compliant
MATLAB code directly from the MATLAB desktop
19
For More Information
Embedded MATLAB Web page
– Description, demos, customer testimonials, technical info
– Links to related MathWorks products
– www.mathworks.com/products/featured/embeddedmatlab/
20