Question? Leave a message!




MATLAB and C/C++

MATLAB and C/C++ 31
MATLAB and C/C++ The perfect combination for signal processing © 2013 The MathWorks, Inc. 1 Signal Processing Algorithm Design with C/C++ Algorithm Testing Deployment Specification Development Debugging C/C++ Specialized Libraries 2 You can enhance your C and C++ development process using the data analysis, visualization, algorithm development, code generation, deployment, test and verification capabilities of MATLAB 3 Signal Processing Algorithm Design with C/C++ and MATLAB Algorithm Algorithm Testing Deployment Specification Development Development Debugging C/C++ C/C++ MATLAB Specialized Libraries Algorithm Test Implementation Development Verification Deployment 4 In This Presentation  Combining MATLAB and C/C++ for – Test and verification – Algorithm development, research, design – Implementation and deployment  Examples from – Wireless communications – Image processing and computer vision – Audio and digital signal processing 5 MATLAB and C/C++ Use Case 1: Call MATLAB from C/C++ C/C++  MATLAB Engine Interface – Interactive Algorithm Development – Debugging of C or MATLAB Code – Plotting / Visualization – Connect to Data Acquisition, Test and Measurement Systems 6 Bluetooth Example  Find Engineering Defects in C with MATLAB  Plot and Visualize Data in MATLAB Example 7 Bluetooth Example Test and Debug Your C Project and Visualize Data/Results  Add header file and libraries to your project  Package data into MATLAB data structure (mxArray)  Use engine routines to: – Send data to MATLAB – Perform computations in MATLAB – Plot data in MATLAB  For C++ example, see: – www.codeproject.com/samples/matlabeng.asp 8 MATLAB and C/C++ Use Case 2: Generate C code from MATLAB  MATLAB Coder – Generate C from MATLAB C/C++ – Integrate with your C/C++ source – Build and deploy complete applications  No royalty or deployment restrictions on code generated with MATLAB Coder MATLAB C Coder 12 Simple C Code Generation Example MATLAB: a=bc; C: Example 13 Implementation Considerations  MATLAB  C – Polymorphic datatypes – Explicit datatype declaration handling – Automatic memory management – Define and manage: Data size, memory, matrices, arrays,… – Builtin matrix array support Kalman Filter Example MATLAB Code: 7 lines C Code: 107 lines 14 Lane Markings Example  Generate C from MATLAB and integrate with C/C++ Example 15 Lane Markings Example Generate C from MATLAB  Prepare your MATLAB algorithm – Make implementation choices – Use supported language features  Test if your MATLAB code is compliant – Validate that MATLAB program generates code – Accelerate execution of userwritten algorithm  Generate source code or MEX – Iterate your MATLAB code to optimize – Implement as source, executable or library 16 MATLAB Language Support for Code Generation  Broad set of language features and functions/system objects supported for code generation Programming Matrices and Arrays Data Types Functions Constructs • Matrix operations • Complex numbers • Arithmetic, relational, and • MATLAB functions and subfunctions • Ndimensional arrays • Integer math logical operators • Variable length argument lists • Subscripting • Double/singleprecision • Program control • Function handles • Frames • Fixedpoint arithmetic (if, for, while, switch ) • Persistent variables • Characters Supported algorithms • Global variables • Structures • 400 MATLAB operators and functions • Numeric classes • 200 System objects for • Variablesized data • System objects • Signal processing • Communications • Computer vision 17 MATLAB and C/C++ Use Case 3: Reuse MATLAB IP in Your C/C++ Code  Create specialized algorithm libraries in MATLAB C/C++ – Generate C with MATLAB Coder – Or, automatically create shared libraries with MATLAB Compiler or MATLAB Coder dll MATLAB  DLL, LIB Compiler exe – Access MATLAB algorithms from C/C++ with DLLs or LIBs lib MATLAB dll C Coder exe  No royalty or deployment restrictions 18 Deploying Applications with MATLAB Toolboxes MATLAB EndUser 1 Desktop Machine MATLAB Compiler 2 3 ..dll dll 19 Deploying Applications with MATLAB  Give MATLAB code to other users MATLAB Compiler MATLAB MATLAB MATLAB Builder EX Builder JA Builder NE  Share applications with end users who do not need MATLAB .dll .exe Excel Java .NET – Standalone executables Web .lib – Shared libraries – Software components 20 MATLAB Compiler and MATLAB Coder MATLAB Coder MATLAB Compiler .dll .exe .exe .lib .dll 21 MATLAB Compiler and MATLAB Coder MATLAB Coder MATLAB Compiler Executable or software Portable and readable Output component/library C source code Full Subset MATLAB language support MATLAB Compiler Runtime (MCR) None Additional libraries Most toolboxes Some toolboxes Supported toolboxes Royaltyfree Royaltyfree License model Builder Products Embedded Coder Extensions 22 MATLAB and C/C++ Use Case 4: Reuse your C/C++ libraries in MATLAB  loadlibrary – Load your library functions C/C++ – Access your IP as custom libraries in MATLAB – Combine with standard MATLAB functions, scripts, System objects lib 23 MATLAB and C/C++ Use Case 5+: Reuse your C/C++ code in MATLAB  mex – Compile and reuse your C/C++ code in C/C++ MATLAB – Combine with standard MATLAB functions, scripts, System objects mex 24 MATLAB and C/C++: Summary of Use Cases  Call MATLAB from C C/C++  Generate C from MATLAB  Use C Libraries in dll MATLAB MATLAB mex Compiler exe  Use C Code in MATLAB  Generate IP libraries or lib MATLAB deploy applications from dll lib C Coder exe MATLAB 25 You can enhance your C and C++ development process using the data analysis, visualization, algorithm development, code generation, deployment, test and verification capabilities of MATLAB MATLAB and C/C++: The Perfect Combination for Signal Processing 26 Summary  Develop algorithms in C/C++ and MATLAB – MATLAB enhances your C/C++ environment – Wide variety of functions and tools available within MATLAB product family  Move quickly to implementation – MATLAB Coder: ANSI C Code – MATLAB Compiler and Builders: Deployable Applications – FixedPoint support  Integrate with hardware and your C/C++. Distribute freely. – No need for a MATLAB license – No royalties for generated code 27 Next Steps  For more information please contact me: giorgia.zucchellimathworks.com  For an evaluation or trial please contact your account manager  Thank you for your interest 28
Website URL
Comment