Fixed-Point Blockset Features
Configuring Fixed-Point Blocks
You configure fixed-point blocks with a parameter dialog box. Block configuration consists of supplying values for parameters via editable text fields, check boxes, and parameter lists. The dialog box for the FixPt Gateway In block is shown below.

Real-World vs. Integer Values
You can configure the fixed-point gateway blocks to treat signals as real-world values or as stored integers with the Treat input as parameter list. The possible values are Real World Value and Stored Integer.
In terms of the variables defined in The General Slope/Bias Encoding Scheme, the real-world value is given by \(V\) and the stored integer value is given by \(Q\). You may want to treat numbers as stored integer values if you are modeling hardware that produces integers as output.
Output Data Type
For many fixed-point blocks, you have the option of specifying the output data type via the block dialog box, or inheriting the output data type from another block. You control how the output data type is selected with the Output data type and scaling parameter list. The possible values are Specify via dialog, Inherit via internal rule, and Inherit via back propagation. Some blocks support only two of these values.
The Fixed-Point Blockset supports several fixed-point and floating-point data types. Fixed-point data types are characterized by their word size in bits and radix (binary) point. The radix point is the means by which fixed-point values are scaled. Additionally:
- Unsigned and two's complement formats are supported.
- The fixed-point word size can range from 1 to 128 bits.
- The radix point is not required to be contiguous with the fixed-point word.
Floating-point data types are characterized by their sign bit, fraction (mantissa) field, and exponent field. The Fixed-Point Blockset supports IEEE singles, IEEE doubles, and a nonstandard IEEE-style floating-point data type.
Note
You can create Fixed-Point Blockset data types directly in the MATLAB workspace and then pass the resulting structure to a fixed-point block, or you can specify the data type directly with the block dialog box.
Output Scaling
Most data types supported by the Fixed-Point Blockset have a default scaling that you cannot change. However, for generalized fixed-point data types, you have the option of specifying the output scaling via the block dialog box, or inheriting the output scaling from another block. You control how the output scaling is selected with the Output data type and scaling parameter list.
The Fixed-Point Blockset supports two general scaling modes: radix point-only scaling and slope/bias scaling. In addition to these general scaling modes, the blockset provides you with additional block-specific scaling choices for constant vectors and constant matrices. These scaling choices are based on radix point-only scaling and are designed to maximize precision. Refer to Example: Constant Scaling for Best Precision in Chapter 3 for more information.
To help you understand the supported scaling modes, the general slope/bias encoding scheme is presented in the next section.
General Slope/Bias Encoding Scheme
When representing an arbitrarily precise real-world value with a fixed-point number, it is often useful to define a general slope/bias encoding scheme.
\(V \approx \tilde{V}=SQ+B\)
where:
- \(V\) is the real-world value.
- \(\tilde{V}\) is the approximate real-world value.
- \(Q\) is an integer that encodesV.
- \(B\) is the bias.
- \(S = F2^{E}\) is the slope.
The slope is partitioned into two components:
- \(2^{E}\) specifies the radix point. \(E\) is the fixed power-of-two exponent.
- \(F\) is the fractional slope. It is normalized such that \(1 \le F \le 2\).
Radix Point-Only Scaling
This is "powers-of-two" scaling since it involves moving only the radix point. Radix point-only scaling does not require the radix point to be contiguous with the data word. The advantage of this scaling mode is the number of processor arithmetic operations is minimized.
You specify radix point-only scaling with the syntax \(2^{-E}\) where \(E\) is unrestricted. This creates a MATLAB structure with a bias \(B\) = 0 and a fractional slope \(F\) = 1.0.
For example, if you specify the value \(2^{-10}\) for the Output scaling parameter, the generalized fixed-point number has a power-of-two exponent \(E\) = -10. This value defines the radix point location to be 10 places to the left of the least significant bit.
Slope/Bias Scaling
With this scaling mode, you can provide a slope and a bias. The advantage of slope/bias scaling is that it typically provides more efficient use of a finite number of bits.
You specify slope/bias scaling with the syntax [slope bias], which creates a MATLAB structure with the given slope and bias.
For example, if you specify the value [5/9 10] for the Output scaling parameter, the generalized fixed-point number has a slope of 5/9 and a bias of 10. The blockset would automatically store \(F\) as 1.1111 and \(E\) as -1 due to the normalization condition \(1 \le F \le 2\).
Rounding
You specify how fixed-point numbers are rounded with the Round toward parameter list. These rounding modes are supported:
Zero- Rounds toward zero and is equivalent to MATLAB'sfixfunction.Nearest- Rounds toward the nearest representable number, with the exact midpoint rounded toward positive infinity. It's equivalent to MATLAB'sroundfunction.Ceiling- Rounds toward positive infinity and is equivalent to MATLAB'sceilfunction.Floor- Rounds toward negative infinity and is equivalent to MATLAB'sfloorfunction.
Overflow Handling
You control how overflow conditions are handled for fixed-point operations with the Saturate to max or min when overflows occur check box.
If checked, then overflows saturate to either the maximum or minimum value represented by the data type. For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127. If unchecked, then overflows wrap to the appropriate value that is representable by the data type. For example, the number 130 does not fit in a signed 8-bit integer, and would wrap to -126.
Locking the Output Scaling
If the output data type is a generalized fixed-point number, then you have the option of locking its scaling by checking Lock output scaling. When locked, the automatic scaling script autofixexp will not change the output scaling. Otherwise, the script is free to adjust the scaling.
Overriding with Doubles
By checking the Override data type(s) with doubles check box, you can override any data type with doubles. This feature is useful when debugging a simulation. For example, if you are simulating hardware that is constrained to output integers, you can override the constraint to determine whether the hardware warrants modification or replacement.
Logging Simulation Values
By checking the Log minimums and maximums check box, you can save the maximum and minimum values encountered during a simulation to the MATLAB workspace. You can then access these values with the autofixexp automatic scaling script.
Compatibility with Simulink
You can connect Simulink blocks to Fixed-Point Blockset blocks provided the signals use built-in Simulink data types. The built-in data types include uint8, uint16, uint32, int8, int16, int32, single, double, and boolean. A fixed-point signal consisting of 8-, 16-, or 32-bit integers is compatible with Simulink only when its scaling is given by a slope of 1 and a bias of 0.
Some Simulink blocks impose restrictions on the data type of the signals they can handle. For example, some blocks accept only doubles. To incorporate these blocks into your fixed-point model, you must configure the driving block(s) to use doubles. Some Simulink blocks can accept signals of any data type. For these blocks, you can input any of the built-in data types or any of the blockset-specific data types. Examples of blockset-specific data types include 32-bit signed integers with a scaling of \(2^{-8}\), and 18-bit unsigned integers with a scaling of \(2^{0}\).
Note
If you want to connect Simulink blocks to fixed-point blocks that output blockset-specific data types, then you must use the fixed-point gateway or data type conversion blocks to convert to a built-in data type.
Most Simulink blocks that accept any Fixed-Point Blockset data type have these characteristics:
- Their only function is to rearrange the signal (for example, the Selector or Mux blocks).
- They do not perform calculations such as addition or relational operations.
- They do not have initial conditions (for example, the Unit Delay block). However, in some cases the block may support any fixed-point data type if the initial condition is set to zero.
Some useful Simulink blocks that can accept any Fixed-Point Blockset data type are listed below.
| Block Name | Description |
|---|---|
| Bus Selector | elect signals from an incoming bus. |
| Demux | Separate a vector signal into output signals. |
| Display | Show the value of the input. |
| Enable | Add an enabling port to a subsystem. |
| Merge | Combine input lines into a scalar output line. |
| Mux | Combine several input signals into a single vector or composite output signal. |
| Scope | Display signals generated during a simulation. |
| Selector | Select input elements. |
| To Workspace | Write data to the workspace. |
| Trigger | Add a trigger port to a subsystem. |
In some cases, fixed-point signals that are not built-in data types are converted to a real-world value as it enters the block. For example, the To Workspace block will output a 32-bit signed integer with a scaling of \(2^{-8}\) as a double.
Example: Converting Doubles to Fixed Point
The purpose of this example is to show you how to simulate a continuous real- world signal using a generalized fixed-point data type. The model used is the simplest possible model and employs only two fixed-point blocks. Although simple in design, the model gives you the opportunity to explore many of the important features of the Fixed-Point Blockset including:
- Data types
- Scaling
- Rounding
- Logging minimum and maximum simulation values to the workspace
- Overflow handling
The model used in this example is given by the fxpdemo_dbl2fix demo. You can launch this demo by typing its name at the MATLAB command line.
fxpdemo_dbl2fix
The model is shown below.

Block Descriptions
The Signal Generator block is configured to output a sine wave with an amplitude defined on the interval [-5 5]. It always outputs double-precision numbers.
- FixPt Gateway In - Used as the interface between Simulink and the Fixed-Point Blockset. Its function is to convert the double-precision numbers from the Signal Generator block into one of the Fixed-Point Blockset data types. For simplicity, its output signal is limited to 5 bits in this example.
- The FixPt Gateway - Used as the interface between the Fixed-Point Blockset and Simulink. Its function is to convert one of the Fixed-Point Blockset data types into a Simulink data type. In this example, it outputs double-precision numbers.
- The FixPt GUI - Launches the Fixed-Point Blockset Interface tool. This tool provides convenient access to the global override and logging parameters, the logged minimum and maximum simulation data, the automatic scaling script, and the plot interface tool. It is not used in this example. However, if you have many fixed-point blocks whose scaling must be optimized, you should use this tool.
Note
You can eliminate the gateway blocks from your fixed-point model if all signals use built-in data types.
Simulation Results
The results of two simulation trials are given below. The first trial uses radix point-only scaling while the second trial uses slope/bias scaling.
Radix Point-Only Scaling
When using radix point-only scaling, your goal is to find the optimal power-of-two exponent \(E\), as defined in Selecting the Output Scaling. For this scaling mode, the fractional slope \(F\) is set to 1 and no bias is required.
The FixPt Gateway In block is configured in this way:
- Output data type - The output data type is given by
sfix(5). This creates a MATLAB structure that is a 5-bit, signed generalized fixed-point number. - Output scaling - The output scaling is given by \(2^{-2}\), which puts the radix point two places to the left of the rightmost bit. This gives a maximum value of 011.11 = 3.75, a minimum value of 100.00 = -4.00, and a precision of \((1/2)^{2}\) = 0.25.
- Rounding - The rounding mode is given by
Nearest. This rounds the fixed-point result to the nearest representable number, with the exact midpoint rounded towards positive infinity. - Overflows - Fixed-point values that overflow will saturate to the maximum or minimum value represented by the word.
The resulting real-world and fixed-point simulation results are shown below.

The simulation clearly demonstrates the quantization effects of fixed-point arithmetic. The combination of using a 5-bit word with a precision of \((1/2)^{2}\) = 0.25 produces a discretized output that does not span the full range of the input signal.
To span the complete range of the input signal with 5 bits using radix point-only scaling, your only option is to sacrifice precision. Hence, the output scaling would be given by \(2^{-1}\), which puts the radix point one place to the left of the rightmost bit. This scaling gives a maximum value of 0111.1 = 7.5, a minimum value of 1000.0 = -8.0, and a precision of \((1/2)^{1}\) = 0.5.
Slope/Bias Scaling
When using slope/bias scaling, your goal is to find the optimal fractional slope \(F\) and fixed power-of-two exponent \(E\). No bias is required for this example since the sine wave is defined on the interval [-5 5]. The FixPt Gateway In block configuration is the same as that of the previous trial except for the scaling.
To arrive at a value for the slope, begin by assuming a fixed power-of-two exponent of -2. In the previous trial, this value defined the radix point-only scaling and resulted in a precision of 0.25. To find the fractional slope, you divide the maximum value of the sine wave by the maximum value of the scaled 5-bit number. The result is 5.00/3.75 = 1.3333. The slope (and precision) is 1.3333x(0.25) = 0.3333. You specify this value as [0.3333] for the Output scaling parameter.
You could also have specified a fixed power-of-two exponent of -1 and a corresponding fractional slope of 0.6667. The resulting slope is the same since \(E\) was reduced by one bit but \(F\) was increased by one bit. In this case, the blockset would automatically store \(F\) as 1.3332 and \(E\) as -2 due to the normalization condition of \(1 \le F \le 2\).
The resulting real-world and fixed-point simulation results are shown below.

The process used to find the slope in this example is not necessary. All that is required is the data range you are simulating and the fixed-point word size used in the simulation. In general, you can achieve reasonable simulation results by selecting your scaling based on the formula:
\(\text{scaling} = \dfrac{max-min}{2^{ws}-1}\)
where:
- \(max\) is the maximum value to be simulated.
- \(min\) is the minimum value to be simulated.
- \(ws\) is the word size in bits.
- \(2^{ws}-1\) is the largest value of a word with whose size is given by \(ws\).
For this example, the formula produces a slope of 0.32258.