Fixed-Point Blockset | ![]() ![]() |
Design Rules
The important design rules that you should be aware of when modeling dynamic systems with fixed-point math follow.
Design Rule 1: Only Multiply Base Data Types
It is best to multiply only inputs of the base data type. Embedded processors typically provide an instruction for the multiplication of base-type inputs, but not for the multiplication of accumulator-type inputs. If necessary, you can combine several instructions to handle multiplication of accumulator-type inputs. However, this can lead to large, slow embedded code.
You can insert blocks to convert inputs from the accumulator-type to the base-type prior to multiply or gain blocks, if necessary.
Design Rule 2: Delays Should Use the Base Data Type
There are two general reasons why a unit delay should use only base-type numbers:
Design Rule 3: Temporary Variables Can Use the Accumulator Data Type
Except for unit delay signals, most signals are not needed from one time step to the next. This means that the signal values can be temporarily stored in shared and reused memory. This shared and reused memory can be RAM or it can simply be registers in the CPU. In either case, storing the value as an accumulator data type is not much more costly than storing it as a base data type.
Design Rule 4: Summation Can Use the Accumulator Data Type
Addition and subtraction can use the accumulator data type if there is justification. The typical justification is reducing the buildup of errors due to round-off or overflow.
For example, a common filter operation is a weighted sum of several variables. Multiplying a variable by a weight naturally produces a product of the accumulator type. Before summing, each product can be converted back to the base data type. This approach introduces round-off error into each part of the sum.
Alternatively, the products can be summed using the accumulator data type, and the final sum can be converted to the base data type. Round-off error is introduced in just one point and the precision is generally better. The cost of doing an addition or subtraction using accumulator-type numbers is slightly more expensive, but if there is justification, it is usually worth the cost.
![]() | Targeting an Embedded Processor | Canonical Forms | ![]() |