Hauptinhalt

Data Type Conversion Overview

At a high level, the process of converting data types in a system from floating-point to fixed-point data types consists of several steps:

  1. Identify system requirements.

  2. Model ideal behavior of the system.

  3. Convert data types of system to data types that are efficient on target hardware.

  4. Verify numeric behavior and performance of the converted system.

  5. Further optimize performance of the system based on intended target hardware.

  6. Generate code.

  7. Deploy code onto hardware.

The Fixed-Point Designer™ software provides several tools for analyzing the numerical behavior of a system and converting a system to use fixed-point data types.

Identify System Requirements

Regardless of the conversion workflow, the first step to a successful data type conversion is understand your system requirements. Better specified system requirements help the better the Fixed-Point Tool to provide accurate range statistics and data type proposals. Behavioral constraints and requirements on signal tolerances in your system also aid in verification of system accuracy and performance after conversion to fixed point. For more information, see Specify Behavioral Constraints.

Choose Between Fixed-Point Tool Workflows for Analyzing and Converting a System to Fixed Point

The Fixed-Point Tool automates many of the data type analysis and conversion steps, including modeling of ideal system behavior using data type override, converting to embedded-efficient data types, and verifying numeric behavior of the converted system.

Depending on your needs, the Fixed-Point Tool provides three workflows for data type analysis and automated data type conversion:

  • Range Collection — Explore the numerical behavior of your model before or after data type conversion.

  • Iterative Fixed-Point Conversion — Automatically propose fixed-point data types and manually select which data types to apply to your model.

  • Optimized Fixed-Point Conversion — Automatically convert your model to use optimized fixed-point data types.

The table provides a summary of the differences between these three workflows. In addition to the app workflow, the Fixed-Point Designer software also includes command-line alternatives for many of these workflows. For a detailed comparison, see Command-Line Interface for the Fixed-Point Tool.

WorkflowChanges Model Data TypesEase of UseAmount of Control Over Data Types Applied to ModelRequires Knowledge of System Behavior TolerancesCommand-Line Workflow
Range CollectionNoOne stepN/ARecommendedN/A
Iterative Fixed-Point ConversionYesMultiple iterationsHighRecommendedDataTypeWorkflow.Converter
Optimized Fixed-Point ConversionYesOne stepLowYesfxpopt

Range Collection Workflow

The Range Collection workflow in the Fixed-Point Tool is an analysis and troubleshooting tool that does not change your model. This workflow provides independent access to the same range collection step found in the data type conversion workflows.

Rich visualizations allow you to explore the ranges of objects in your model and quickly spot sources of overflow, underflow, and other numerical issues, either before or after conversion to fixed point. Signals that do not meet the specified tolerances are highlighted in the results.

You can choose to specify additional simulation inputs and tolerances on logged signals in your model. The tool individually collects ranges for all specified simulation inputs and also merges the results for a combined view. If you want to explore the ideal floating-point behavior of your system, you can choose to collect ranges with data type override enabled. You can compare the results of simulation runs using the Simulation Data Inspector.

This workflow provides insight to the behavior of your system and where improvements can be made without the risk of changing your model. After exploring the statistics collected on your model, you can choose to proceed with one of the automated fixed-point conversion workflows or use the range collection workflow as an aid to a more manual fixed-point conversion process.

For an example of the range collection workflow, see Use the Fixed-Point Tool to Explore Numerical Behavior.

Iterative Fixed-Point Conversion Workflow

The Iterative Fixed-Point Conversion workflow in the Fixed-Point Tool is an interactive, automatic means of specifying fixed-point data types in a Simulink® model. The tool collects ranges for model objects and then proposes fixed-point data types that maximize precision and cover the range. You can then review the data type proposals and apply them selectively to objects in your model.

The tool allows you to propose word lengths or fraction lengths, giving you the option to have a fixed-precision design. The tool also takes into account limitations of target hardware you specify. You can also specify a safety margin to increase the bounds of the ranges collected by a specified amount. Rich visualizations allow you to explore the ranges of objects in your model and quickly spot sources of overflow and other numerical issues, both before and after converting your model to fixed point. If the proposed data types do not meet your needs, you can continue iterating through this process. You can compare the results of different fixed-point implementations in the Simulation Data Inspector.

This workflow gives you full control over which proposed data types are applied to your model, if any. If you complete the recommended preparation step of conversion, you can automatically restore your model to its original state.

This workflow does not require you to specify the desired behavior of your system. However, to achieve more accurate data type proposals and to be able to evaluate whether proposed data types meet the specified requirements of the design, you should specify any known ranges, simulation inputs, and signal tolerances.

If you have never used the automated fixed-point conversion workflows before, the iterative workflow is a good place to start to build an understanding of how the Fixed-Point Tool works. This workflow requires relatively few inputs regarding system requirements and tolerances and allows you flexibility to iterate on the proposed data types. However, automated data type proposals are limited to proposing fraction lengths for a fixed word length, or vice versa.

To get started with the iterative fixed-point conversion workflow, see Iterative Fixed-Point Conversion Using the Fixed-Point Tool.

Optimized Fixed-Point Conversion Workflow

The Optimized Fixed-Point Conversion workflow in the Fixed-Point Tool provides a fully automated means of converting a Simulink model to fixed point. If you know the desired behavior of your system and can specify acceptable tolerances on this behavior, you can use this workflow to find the optimal data types for your system. The tool provides better results if you specify any known ranges or supply additional simulation inputs.

You can specify allowable word lengths, and the tool also takes into account limitations of target hardware you specify. You can also specify a safety margin to increase the bounds of the ranges collected by a specified amount. Optimized data types stay within specified behavioral tolerances and minimize the cost of the design. If more than one feasible solution is found, you can apply and explore different solutions to your model to find one that fits your needs. You can explore the ranges and statistics collected in your baseline model using rich visualizations to quickly spot sources of overflow and other numerical issues. You can compare the results of different fixed-point implementations in the Simulation Data Inspector.

After optimizing data types in the Fixed-Point Tool, you can export the workflow to a MATLAB® script. You can then continue data type optimization using fxpopt at the command line, which has advanced options for further customizing the optimization process.

This workflow automatically changes the data types on your model in addition to some model configuration parameters at completion of the optimization process. If you complete the recommended preparation step before starting optimization, you can automatically restore your model to its original state.

This workflow requires the most up-front knowledge of system requirements and tolerances in order to produce a good result. The optimization workflow is fully automated and does not give you control over individual data type proposals. You can optimize the data types to meet your chosen objective function, signal tolerances, and behavioral constraints. The optimization solver can fine-tune both word length and fraction length independently, resulting in heterogeneous data type proposals and potentially resulting in more optimal data types, depending on your system

For an example of the optimized fixed-point conversion workflow, see Optimize the Fixed-Point Data Types of a System Using the Fixed-Point Tool.

Further Optimize System Based on Target Hardware

After using the Fixed-Point Tool to convert your system under design to use fixed-point data types, you can further optimize performance of the system based on target hardware.

If your model contains constructs not supported for automated fixed-point conversion that were isolated during the preparation step in the Fixed-Point Tool, you can replace these constructs with equivalent CORDIC implementations or use the Lookup Table Optimizer app to replace parts of your model with an embedded-efficient lookup table implementation. For an example, see Convert Floating-Point Model to Fixed Point.

You can use the Model Advisor to help you configure your fixed-point model to achieve a more efficient design and optimize your generated code. For more information, see Optimize Generated Code with the Model Advisor.

Generate Code and Deploy to Hardware

After converting to embedded-efficient data types and optimizing your system for your intended target, generate code and deploy to hardware, for example, by using Embedded Coder® or HDL Coder™.

See Also

Topics