Explore Multiple Floating-Point to Fixed-Point Conversions

In this example, use the Fixed-Point Tool and the ex_fixed_point_workflow model to explore different word length choices. After you simulate your model using embedded types, and compare the floating point and fixed-point behavior of your system, determine if the new behavior is satisfactory. If the behavior of the system using the newly applied fixed-point data types is not acceptable, you can iterate through the process until you find settings that work for your system.

Open Model and Fixed-Point Tool

Open the ex_fixed_point_workflow model. At the MATLAB® command line, enter:

addpath(fullfile(docroot,'toolbox','fixpoint','examples'));
ex_fixed_point_workflow

Convert to Fixed-Point Using Default Proposal Settings

  1. To compare the floating-point behavior of the model with the fixed-point behavior after conversion, you must enable signal logging for at least one signal. In the Controller Subsystem, select the signals at the outputs of the Discrete Filter and Gain blocks.

    Click the Simulation Data Inspector button arrow and select Log Selected Signals.

  2. In the ex_fixed_point_workflow model menu, select Analysis > Data Type Design > Fixed-Point Tool.

  3. In the Fixed-Point Tool, in the Prepare System section of the toolstrip, under System Under Design, select the subsystem you want to convert to fixed point. In this example, select Controller Subsystem.

  4. In the Collect Ranges section, select Simulation Ranges as the range collection method.

  5. Click Prepare. The Fixed-Point Tool checks the system under design and the model containing the system under design for compatibility with the conversion process.

  6. Click the Collect Ranges button to start the simulation.

  7. In the Convert Data Types section, click the Propose Data Types button .

    The Fixed-Point Tool uses the default proposal settings to propose data types with 16-bit word length and best-precision fraction length and updates the results in the spreadsheet.

  8. Click the Apply Data Types button to write the proposed data types to the model.

  9. In the Verify section of the toolstrip, click the Simulate with Embedded Types button . The Fixed-Point Tool simulates the model using the new fixed-point data types and stores the run information in a new run titled Embedded.

  10. Click the Compare Results button to open the Simulation Data Inspector and compare the floating-point and fixed-point behavior.

Return to the Fixed-Point Tool to update the proposal settings and generate new data type proposals.

Convert Using New Proposal Settings

Note

You do not need to collect ranges again. Collecting ranges after you apply proposed data types will reset the workflow. You will no longer be able to easily propose and apply new default data types after collecting ranges.

  1. In the Fixed-Point Tool, in the Convert Data Types section of the toolstrip, click the Settings button .

    Edit the proposal settings to determine if a larger word length improves the fixed-point behavior of the system. Set the Default Word Length to 32.

  2. To generate new proposals, click the Propose Data Types button.

  3. Click the Apply Data Types button to write the proposed data types to the model.

  4. In the Verify section of the toolstrip, click the Simulate with Embedded Types button. The Fixed-Point Tool simulates the model using the new fixed-point data types. The tool overwrites the information in the previous Embedded run.

  5. Click the Compare Results button to open the Simulation Data Inspector.

You can continue to adjust the proposal settings, propose, and apply data types to your model until you find settings for which the fixed-point behavior of your system is acceptable.

Related Topics