Fixed-Point Designer

Key Features

  • Fixed-point data type specification in MATLAB, Simulink, and Stateflow
  • Bit-true, accelerated simulation of fixed-point algorithms
  • Automated conversion from floating point to fixed point based on range data
  • Floating-point and fixed-point results comparison
  • Fixed-point data type override to double or single precision
  • Support for C, HDL, and PLC code generation
Using Fixed-Point Designer to specify and view data types and scaling for MATLAB, Simulink, and Stateflow.
Using Fixed-Point Designer to specify and view data types and scaling for MATLAB, Simulink, and Stateflow.

Fixed-Point Specification

Fixed-Point Designer enables you to specify all the fixed-point properties of your MATLAB code, Simulink models, and Stateflow charts. It provides full control of signedness, word length, and scaling. It supports application-specific word lengths from 1 bit to 128 bits or more. Binary-point scaling and arbitrary slope and bias scaling needed by sensors and actuators are also supported. You can control the details of the mathematical operations, such as how to deal with rounding and overflow.

Simulink model demonstrating the effect of limited range and precision on a signal.
Simulink model demonstrating the effect of limited range and precision on a signal, as shown on the scope (top right). The parameter dialog box (top left) supports full control of block parameters, including all fixed-point attributes. (See example)

Fixed-Point Designer provides a large number of functions such as math and bitwise operations, array and matrix operations, CORDIC implementations, and trigonometric functions to support fixed-point computation.

With Fixed-Point Designer, you can control the fixed-point arithmetic. In MATLAB, fixed-point variables can either share a single set of arithmetic attributes or have their own specified arithmetic attributes.

A data-type-independent MATLAB algorithm that provides both a floating-point response and a fixed-point response.
A data-type-independent FIR filter algorithm in MATLAB that provides both a floating-point response and a fixed-point response. The plot shows a comparison of the output signal of the original floating-point baseline with the output signal from the algorithm implemented with data types using a 16-bit word length and the proposed fraction length. Both signals are shown overlapped (left) and differences are in the order of 10-6 (right). (See example)

Bit-True Design Workflow

Fixed-Point Designer provides bit-true agreement across a workflow that uses Model-Based Design. The response of a fixed-point algorithm is bit-true for all forms of simulation and code generation, including acceleration and software-in-the-loop. Analysis and verification of a fixed-point algorithm are based on bit-true representations. Bit-true agreement maximizes many benefits of Model-Based Design, such as the ability to discover issues early in the workflow, when they are easier and less costly to fix.

Comparison of output with original baseline output using Fixed-Point Designer.
Using the Simulation Data Inspector to compare the results of a floating-point simulation with the results of a fixed-point simulation. (See example)

Once your design has been configured with fixed-point data types, you can simulate its performance to explore implementation tradeoffs between limited range and precision for fixed-point embedded systems.

Using the tools in Fixed-Point Designer, you can access these values and change the data types of signals, optimizing precision while ensuring that their range is covered. You can specify data type ranges using design minimums and maximums, simulation results, or derived minimum and maximum results. For Simulink models, you can lock output data types to prevent them from being changed.

Fixed-point simulation of a fuel rate control system designed using Simulink and Stateflow.
Fixed-point simulation of a fuel rate control system designed using Simulink and Stateflow. The Fixed-Point Tool lets you trade off range and precision for data in Simulink models (bottom).

Floating-Point to Fixed-Point Conversion

Fixed-Point Designer provides analysis tools for efficiently converting a design from floating-point to fixed-point representation. The tools let you record minimum and maximum data values and pinpoint when overflows occur during fixed-point operations. The data type override feature lets you analyze a fixed-point algorithm by switching the data types between fixed point and floating point. With this analysis, you can observe the dynamic range of variables involved in your design and ensure that the algorithm behaves consistently in floating-point and fixed-point representations.

In MATLAB, you can use the Fixed-Point Converter app to collect minimum and maximum values through simulation or range analysis and get proposed data types. A histogram is generated for each named and intermediate variable and for each expression in your code. You can use this histogram to optimize the word and fraction lengths for your fixed-point variables. Using the Fixed-Point Converter app, you can replace any function not supported for fixed-point conversion with a lookup table approximation function.

Fixed-Point Converter app showing range of proposed data type and percentage of simulation values.
Fixed-Point Converter app showing a histogram of the range of the proposed data type and the percentage of simulation values that the proposed data type covers. You can use this app to instrument your code for logging, collect minimum and maximum values, plot a histogram from the simulation, and get proposed data types.
For Simulink models, you can automatically convert a floating-point design built in Simulink, Stateflow, and system toolboxes including Communications System Toolbox™ and DSP System Toolbox™ into a fixed-point design using the Fixed-Point Tool. You can also script the conversion process using the command-line interface of the Fixed-Point Tool.

Derived Range Analysis for Float-to-Fixed Conversion
The Fixed-Point Tool in Fixed-Point Designer™ can collect range data either by performing simulation and logging range information or by derived range analysis.

Fixed-Point Designer provides debugging capabilities that let you switch to a floating-point representation of your model to perform benchmarking of the design, identify modeling errors, and determine ideal minimum and maximum values. Fixed-Point Designer supports workflows based on either MATLAB or Simulink, as well as integrated workflows based on both MATLAB and Simulink with MATLAB Function blocks.

Fixed-Point Conversion of MATLAB Function Blocks in Simulink
Collect and display simulation ranges for variables inside a MATLAB® Function block using the Fixed-Point Tool. Use this simulation range analysis to propose data types for the variables based on the simulation data

Use the Fixed-Point Tool to collect and display ranges for variables inside a MATLAB Function block and get proposed data types for the variables based on the range information.

Accelerated Simulation

Fixed-Point Designer lets you accelerate fixed-point algorithms through MEX-file generation. It does this by providing the fiaccel function to convert your MATLAB code to a MEX-function, which can reduce execution time of your fixed-point algorithms.

Code showing how to accelerate a numerical filter fixed-point algorithm.
Code showing how to accelerate a numerical filter fixed-point algorithm using the fiaccel function.

Code Generation

Using Fixed-Point Designer with MATLAB Coder™ or Embedded Coder®, you can generate pure integer C code from your fixed-point MATLAB code. You can identify potential data type issues in the generated HTML report. The report highlights MATLAB code that requires single-precision, double-precision, or expensive fixed-point operations.

Fixed-point MATLAB code for a FIR filter and efficient C code generated using MATLAB Coder with Fixed-Point Designer.
Fixed-point MATLAB code for a FIR filter (top) and efficient C code generated using MATLAB Coder with Fixed-Point Designer (bottom).

Using Fixed-Point Designer with Simulink Coder™ or Embedded Coder, you can generate pure integer C code from your fixed-point Simulink models and Stateflow charts.

Model incorporating wide integer and fixed-point operations and generated multiword C code.
Model incorporating wide integer and fixed-point operations (top) and generated multiword C code (bottom). Generation of multiword code is normally triggered by using parameters or signals with data types wider than C long.

The generated code is in bit-true agreement with your model, enabling your design to perform as it did in simulation. The generated code automatically handles all the details of implementing fixed-point designs, such as scaling adjustment, rounding, and advanced fixed-point math. You can generate code for signals and parameters with word sizes from 1 to 128 bits. You can use the generated code for a variety of applications, including accelerated simulation, rapid prototyping, and production deployment. The Model Advisor can help you configure your fixed-point models to achieve a more efficient design and optimize your generated code.

Using Fixed-Point Designer with HDL Coder™, you can generate bit-true synthesizable Verilog® and VHDL® code from your fixed-point MATLAB code, Simulink models, and Stateflow charts.

Integrating MATLAB into your C/C++ Product Development Workflow

View webinar