Академический Документы
Профессиональный Документы
Культура Документы
Figure 1. Source code for the euclidean.m function. Figure 2. Visualizing the computation of Euclidean distances by
the plot_distances function.
hyperlinks to C source files and header files many difficulties encountered in manual Accommodating Changes in Variable
generated from the MATLAB function. The MATLAB to C conversion are eliminated Dimensions
generated C code is created in a file named through automatic translation. In the MATLAB language, all data can vary
euclidean.c (Figure 3). in size. Embedded MATLAB supports vari-
Design Patterns for a MATLAB able-sized arrays and matrices with known
By using the example option, we declare to C Workflow upper bounds. This means you can accom-
the data type, size, and complexity of the In an embedded system, the size and data modate the use of variable-sized data for
variables x and cb in the function interface, type of each variable must be set before embedded implementations by using buffers
enabling the Embedded MATLAB engine implementation. In addition, if the per- of a constant maximum size and by address-
to assign data type and sizes automatically formance requirements are not met, the ing subportions of the constant-size buffers.
to all the local variable in the generated C algorithm’s memory and computational Within your Embedded MATLAB func-
program. The generated C code correctly footprint must be optimized. The following tions you can define variable-size inputs,
maps to zero-based indexing for access- sections examine design patterns that use outputs, and local variables, with known
ing array elements, and the vector opera- supported Embedded MATLAB features to upper bounds. For inputs and outputs,
tions are automatically mapped to scalar ensure that the generated C code adheres to you must specify the upper bounds explic-
computations with for loops. As a result, these requirements. itly at the function interface. For local data,
It may be desirable to reduce memo- tion. You can use Fixed-Point Toolbox™ to
Using Fixed-Point and Native Integer
ry footprint of the generated C code. In Data Types create fixed-point variables and perform
some cases, the initialization of new vari- By default, MATLAB uses 64-bit double- fixed-point computations. Since the
ables in your Embedded MATLAB func- precision numerical representation for Embedded MATLAB language subset sup-
tion may produce redundant copies in the variables created in the workspace. As con- ports the fixed-point data object (fi), by
generated C code. Although Embedded venient as this choice is for design explora- using Real-Time Workshop you can gener-
MATLAB technology eliminates many tion, it is not memory-efficient for real- ate pure integer C code from your Embed-
copies automatically, you can eliminate time processing of many common signals, ded MATLAB code. This usually involves
data copies that are not automatically such as image or audio signals represented modifying your original MATLAB func-
handled by declaring uninitialized vari- natively with word lengths of 8 or 16 bits. tion to declare variables based on integer
ables using the eml.nullcopy function. In To handle these types of signals and to or fixed-point representations.
Figure 7, the variable Y is initialized with implement your MATLAB algorithm on Our euclidean _ optimized.m func-
such a construction. target processors with limited word tion can process integer data types or fixed-
lengths, you must convert the design to a point data types as its input variables. To
fixed-point or integer-based representa- generate C code we only need to compile the
same function with integer or fixed-point
Technical Support
www.mathworks.com/support
Demos
www.mathworks.com/demos
Training Services
www.mathworks.com/training
Third-Party Products
and Services
www.mathworks.com/connections
Worldwide CONTACTS
www.mathworks.com/contact
Figure 8. C code for euclidean _ optimized.m compiled with integer input variables. Computa- e-mail
tions are purely integer-based. info@mathworks.com
variables in the example option of the emlc data and fixed-point numerical represen-
command. The command syntax for input tations, are automatically translated to C © 2009 The MathWorks, Inc. MATLAB and Simulink
are registered trademarks of The MathWorks, Inc. See
variables of 16-bit signed integer type, for code, enabling you to focus on improving www.mathworks.com/trademarks for a list of additional
trademarks. Other product or brand names may be trade-
example, will be your design rather than maintaining mul- marks or registered trademarks of their respective holders.
>> emlc -eg {int16(x),int16(cb)} –re- tiple copies of the source code written in
port euclidean _ optimized.m different languages. ■
91768v00 10/09
The resulting generated C code contains
only integer C data types, and can be
readily compiled into fixed-point processors
(Figure 8). For More Information