Manual Fixed-Point Conversion Workflow

  1. Implement your algorithm in MATLAB®.

  2. 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.

  3. Prepare algorithm for instrumentation.

  4. 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.

  5. Build instrumented MEX for original MATLAB algorithm.

  6. Run your original MATLAB algorithm to log min/max data. View this data in the instrumentation report.

  7. Separate data types from algorithm.

    Convert functions to use types tables and update entry-point function.

  8. Validate modified function.

    1. Create fixed-point types table based on proposed data types.

    2. Build MEX function.

    3. Run and compare MEX function behavior against baseline.

  9. Use proposed fixed-point data types.

    Create fixed-point types table based on proposed data types, build mex, run, and then compare against baseline.

  10. Optionally, if have a MATLAB Coder™ license, generate code.

    Start by testing native C-types.

  11. Iterate, tune algorithm.

    For example, tune the algorithm to avoid overflow or eliminate bias.

Was this topic helpful?