《matlab coder自动生成c c++代码》由会员分享,可在线阅读,更多相关《matlab coder自动生成c c++代码(20页珍藏版)》请在金锄头文库上搜索。
1、Automatic C Code Generation from MATLAB Marc Barberis Application Engineering Group, MathWorks Inc. AGENDA Quick Demo Benefits of Automatic C Code Generation In-Depth Example Comparison between MATLAB Coder and MATLAB CompilerComparison between MATLAB Coder and MATLAB Compiler Fixed-Point Design Con
2、clusion Demo: Using Generated C Code in a Stand-Alone C Project Why translate MATLAB to C? Integrate MATLAB algorithms w/ existing C environment using source code or static libraries Prototype MATLAB algorithms on desktops as standalone executablesPrototype MATLAB algorithms on desktops as standalon
3、e executables Accelerate user-written MATLAB algorithms Implement C/C+ code on processors or hand-off to software engineers Challenges with Manual Translation from MATLAB to C/C+ Separate functional and implementation specification Leads to multiple implementations that are inconsistent Hard to modi
4、fy requirements during developmentHard to modify requirements during development Difficult to keep reference MATLAB code and C code in-sync Manual coding errors Time consuming and expensive Automatic Translation of MATLAB to C With MATLAB Coder, design engineers can Maintain one design in MATLAB Wit
5、h MATLAB Coder, design engineers can Maintain one design in MATLAB Maintain one design in MATLAB Design faster and get to C/C+ quickly Test more systematically and frequently Spend more time improving algorithms in MATLAB Maintain one design in MATLAB Design faster and get to C/C+ quickly Test more
6、systematically and frequently Spend more time improving algorithms in MATLAB Implementation Constraints Element by element multiply Element by element multiply Element by element multiply logical integer function a= foo(b,c) a = b * c; void foo(const double b15, Element by element multiply Dot produ
7、ct Matrix multiply Element by element multiply Dot product Matrix multiply Element by element multiply Dot product Matrix multiply integer real complex C double foo(double b, double c) return b*c; void foo(const double b15, const double c30, double a18) int i0, i1, i2; for (i0 = 0; i0 400 MATLAB ope
8、rators and functions 200 System objects for Signal processingVariable-sized data System objects Classes Signal processing Communications Computer vision Code Generation Readiness Tool Instant feedback on code generation compliance of your MATLAB codecompliance of your MATLAB code ? Provides estimate
9、 of effort needed to generate C code from your MATLAB code on a scale of 1 to 5 ? Provides a list of issues that need to be resolved in one report ? Gives detailed information on unsupported functions Other Deployment Options Deploying Applications with MATLAB Compiler Share applications Share appli
10、cations Desktop or Web software components MATLABCompiler MATLAB Builder NE MATLAB Builder EX MATLAB Builder JA Supports full MATLAB language and most toolboxes Requires MCR Free run-time library JavaExcel.NET Web COM .exe.dll Builder NEBuilder EXBuilder JA Free run time library Royalty-free deploym
11、ent Choosing the Right Deployment Solution MATLAB Coder and MATLAB Compiler Output Portable and readable C source code Executable or software component/library MATLAB CompilerMATLAB Coder C source codecomponent/library MATLAB support Subset of language Some toolboxes Full language Most toolboxes Gra
12、phics Runtime requirementNoneMATLAB Compiler Runtime (MCR) License modelRoyalty-freeRoyalty-free Fixed Point Design: Motivation ConsiderationFixed PointFloating Point RAM and ROM consumptionSmallLarge Execution timeFasterSlower Hardware power consumptionLowHigh Development timeLongShortDevelopment t
13、imeLongShort Implementation complexityMore complex. Control of word length, rounding mode, saturation. Less Error ProneHarder to develop. More prone to programming errors Easier to develop Fixed Point Design: Pitfalls ?Arithmetic PitfallsArithmetic Pitfalls Introduces quantization errors Word length
14、 and Fraction Length must be specified ?For every variable Degradation must be analyzed Integer + signfractional L-NN QuantizationoverflowInteger + signfractional L Quantizationoverflow Fixed Point Design: Pitfalls Fixed Point C PitfallsFixed Point C Pitfalls No native fixed-point math libraries No
15、built-in overflow/ underflowchecks No tools to determine optimal integerand fractionalbits No visualization of floating and fixed-point representations Integer + signfractional L-NN QuantizationoverflowInteger + signfractional L Quantizationoverflow Fixed-Point Toolbox: MATLAB Fixed-Point Object Fi
16、Object Value NumericType Signed: true WordLength: 16 FractionLength: 13 Fimath RoundMode: round OverflowMode: saturate ProductMode: FullPrecision1. Controls output type of operations A*B, A+B, pow2(A,3) ProductMode: FullPrecision MaxProductWordLength: 128 SumMode: FullPrecision MaxSumWordLength: 128 CastBeforeSum: true 1. Controls output type of operations 2. Allows natural operator syntax Fixed Point D