Parameter and Signal Conversions

The previous sections of this chapter, together with Chapter 3, Data Types and Scaling, describe how data types, scaling, rounding, overflow handling, and arithmetic operations are incorporated into the Fixed-Point Blockset. With this knowledge, you can define the output of a fixed-point model by configuring fixed-point blocks to suit your particular application.

However, to completely understand the results generated by the Fixed-Point Blockset, you must be aware of these three issues:

  • When numerical block parameters are converted from a double to a Fixed-Point Blockset data type

  • When input signals are converted from one Fixed-Point Blockset data type to another (if at all)

  • When arithmetic operations on input signals and parameters are performed

For example, suppose a fixed-point block performs an arithmetic operation on its input signal and a parameter, and then generates output having characteristics that are specified by the block. The following diagram illustrates how these issues are related.

 

Parameter conversions and signal conversions are discussed below. Arithmetic operations are discussed in Rules for Arithmetic Operations.

Parameter Conversions

Block parameters that accept numerical values are always converted from a double to a Fixed-Point Blockset data type. Parameters can be converted to the input data type, the output data type, or to a data type explicitly specified by the block. For example, the FixPt FIR block converts the Initial condition parameter to the input data type, and converts the FIR coefficients parameter to a data type you explicitly specify via the block dialog box.

Parameters are always converted before any arithmetic operations are performed. Additionally, parameters are always converted offline using round-to-nearest and saturation. Offline conversions are discussed below.

For information about parameter conversions for a specific block, refer to Chapter 9, Block Reference.

Offline Conversions

An offline conversion is a conversion performed by your development platform (for example, the processor on your PC), and not by the fixed-point processor you are targeting. For example, suppose you are using a PC to develop a program to run on a fixed-point processor, and you need the fixed-point processor to compute 

over and over again. If a, b, and c are constant parameters, it is inefficient for the fixed-point processor to compute ab/c every time. Instead, the PC's processor should compute ab/c offline one time, and the fixed-point processor computes only C·u. This eliminates two costly fixed-point arithmetic operations.

Signal Conversions

Consider the conversion of a real-world value from one Fixed-Point Blockset data type to another. Ideally, the values before and after the conversion are equal

where Vb is the input value and Va is the output value. To see how the conversion is implemented, the two ideal values are replaced by the general slope/bias encoding scheme described in Scaling.

Solving for the output data type's stored integer value, Qa

where Fs is the adjusted fractional slope and Bnet is the net bias. The offline conversions and online conversions and operations are discussed below.

Offline Conversions

Both Fs and Bnet are computed offline using round-to-nearest and saturation. Bnet is then stored using the output data type and Fs is stored using an automatically selected data type.

Online Conversions and Operations

The remaining conversions and operations are performed online by the fixed-point processor, and depend on the slopes and biases for the input and output data types. The conversions and operations are given by these steps:

  1. The initial value for Qa is given by the net bias, Bnet.

     

  2. The input integer value, Qb, is multiplied by the adjusted slope, Fs.

     

  3. The result of step 2 is converted to the modified output data type where the slope is one and bias is zero. This conversion includes any necessary bit shifting, rounding, or overflow handling.

     

  4. The summation operation is performed, which includes any necessary overflow handling.

Streamlining Simulations and Generated Code

Note that the maximum number of conversions and operations is performed when the slopes and biases of the input signal and output signal differ (are mismatched). If the scaling of these signals is identical (matched), the number of operations is reduced from the worst (most inefficient) case. For example, when an input has the same fractional slope and bias as the output, only step 3 is required. 

Exclusive use of radix point-only scaling for both input signals and output signals is a common way to eliminate the occurrence of mismatched slopes and biases, and results in the most efficient simulations and generated code.