Explore Multiple Floating-Point to Fixed-Point Conversions

In this example, you 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')

The model consists of a source, a Controller Subsystem that you want to convert to fixed point, and a scope to visualize the subsystem outputs. Configuring a model in this way helps you to determine the effect of fixed-point data types on a system. Using this approach, you convert only the subsystem because this is the system of interest. There is no need to convert the source or scope to fixed point.

This configuration allows you to modify the inputs and collect simulation data for multiple stimuli. You can then examine the behavior of the subsystem with different input ranges and scale your fixed-point data types to provide maximum precision while accommodating the full simulation range.

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, in the table under Signal Tolerances, 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 15%.

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

  11. Right-click on EmbeddedRun and select OpenSDI 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

  1. In the Fixed-Point Tool, in the Convert 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 newly 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 and stores the run information in a new run titled EmbeddedRun_2.

  5. Right-click on EmbeddedRun_2 and select OpenSDI to open the Simulation Data Inspector and compare the floating-point and fixed-point behavior.

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

Related Topics