From MATLAB To Embedded C: News&Notes
From MATLAB To Embedded C: News&Notes
From MATLAB To Embedded C: News&Notes
w w w. m a t h w o r k s .c o m
TheMathWorks News&Notes
MATLAB code for a Kalman filter with three states (inset) and
equivalent C code generated with the Embedded MATLAB subset.
The 17 lines of MATLAB code translate to 144 lines of C code,
including comments.
w w w. m a t h w o r k s .c o m
They are used in a wide range of applications, including control, signal and image
processing, radar and sonar, and financial
modeling.
The simple tracking algorithm is developed in MATLAB in a file named kalmanf.m
(Figure 1).
This algorithm can be automatically
translated to C using emlc, a command-line
tool in Real-Time Workshop that generates
C code from Embedded MATLAB code.
Typical syntax for translation is
>> emlc -s cfg -eg {A,B,C,Q,R,u,t,yv}...
kalmanf.m
Figure 2. The Real-Time Workshop GUI for configuring code generation properties from Embedded
MATLAB code.
w w w. m a t h w o r k s .c o m
Figure 3. Output from the MATLAB and C-code versions of the Kalman filter.
Figure 4. Simulink radar system model with the Embedded MATLAB function block
referencing the Kalman tracking filter.
Resources
Webinar: Algorithm Design and
Code Generation with Embedded MATLAB
www.mathworks.com/nn9/wbnr30822
2009 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be
trademarks or registered trademarks of their respective holders.
91786v00 11/09