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.

Set up the Model

Open the model and configure it for fixed-point conversion.

open_system('ex_fixed_point_workflow')

In this example, you convert the Controller Subsystem to fixed-point. To compare the behavior before and after conversion, enable signal logging at the outputs of the system under design.

ph = get_param('ex_fixed_point_workflow/Controller Subsystem','PortHandles');
set_param(ph.Outport(1),'DataLogging','on')
set_param(ph.Outport(2),'DataLogging','on')

Convert to Fixed-Point Using Default Proposal Settings

  1. In the Apps gallery of the ex_fixed_point_workflow model, select Fixed-Point Tool.

  2. In the Fixed-Point Tool, under System Under Design, select the subsystem you want to convert to fixed point. In this example, select Controller Subsystem.

  3. Under Range Collection Mode, select Simulation Ranges as the range collection method.

  4. Under Simulation Inputs, you can specify Simulink.SimulationInput objects to exercise your design over its full operating range. In this example, set Simulation inputs to Use default model inputs.

  5. To specify tolerances for the system, under Signal Tolerances (Optional) in the table, specify tolerances for any signal in the model with signal logging enabled.

    Set the relative tolerance (Rel Tol) of the signals that you logged to 5%.

  6. In the toolstrip, click Prepare. The Fixed-Point Tool checks the system under design for compatibility with the conversion process and reports any issues found in the model. When possible, the Fixed-Point Tool automatically changes settings that are not compatible. For more information, see Use the Fixed-Point Tool to Prepare a System for Conversion.

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

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

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

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

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