Implement your algorithm in MATLAB®.
Write a test file that calls your original MATLAB algorithm to validate the behavior of your algorithm.
Create a test file to validate that the algorithm works as expected in floating point before converting it to fixed point. Use the same test file to propose fixed-point data types. After the conversion, use this test file to compare fixed-point results to the floating-point baseline.
Prepare algorithm for instrumentation.
Write an entry-point function.
For instrumentation and code generation, it is convenient to have an entry-point function that calls the function to be converted to fixed point. You can cast the function inputs to different data types, and add calls to different variations of the algorithm for comparison. By using an entry-point function, you can run both fixed-point and floating-point variants of your algorithm. You can also run different variants of fixed-point. This approach allows you to iterate on your code more quickly to arrive at the optimal fixed-point design.
Build instrumented MEX for original MATLAB algorithm.
Run your original MATLAB algorithm to log min/max data. View this data in the instrumentation report.
Separate data types from algorithm.
Convert functions to use types tables and update entry-point function.
Validate modified function.
Create fixed-point types table based on proposed data types.
Build MEX function.
Run and compare MEX function behavior against baseline.
Use proposed fixed-point data types.
Create fixed-point types table based on proposed data types, build mex, run, and then compare against baseline.
Optionally, if have a MATLAB Coder™ license, generate code.
Start by testing native C-types.
Iterate, tune algorithm.
For example, tune the algorithm to avoid overflow or eliminate bias.