Skip to Main Content Skip to Search
Product Documentation

Recommendations for Arithmetic and Scaling

Introduction

The sections that follow describe the relationship between arithmetic operations and fixed-point scaling, and offer some basic recommendations that may be appropriate for your fixed-point design. For each arithmetic operation,

In embedded systems, the scaling of variables at the hardware interface (the ADC or DAC) is fixed. However for most other variables, the scaling is something you can choose to give the best design. When scaling fixed-point variables, it is important to remember that

Addition

Consider the addition of two real-world values:

These values are represented by the general [Slope Bias] encoding scheme described in Scaling:

In a fixed-point system, the addition of values results in finding the variable Qa:

This formula shows

Inherited Scaling for Speed

In the process of finding the scaling of the sum, one reasonable goal is to simplify the calculations. Simplifying the calculations should reduce the number of operations, thereby increasing execution speed. The following choices can help to minimize the number of arithmetic operations:

The resulting formula is

or

These equations appear to be equivalent. However, your choice of rounding and precision may make one choice stand out over the other. To further simplify matters, you could choose Ea = Ec or Ea = Eb. This will eliminate some bit shifting.

Inherited Scaling for Maximum Precision

In the process of finding the scaling of the sum, one reasonable goal is maximum precision. You can determine the maximum-precision scaling if the range of the variable is known. Example: Maximizing Precision shows that you can determine the range of a fixed-point operation from max(Va) and min(Va). For a summation, you can determine the range from

You can now derive the maximum-precision slope:

In most cases the input and output word sizes are much greater than one, and the slope becomes

which depends only on the size of the input and output words. The corresponding bias is

The value of the bias depends on whether the inputs and output are signed or unsigned numbers.

If the inputs and output are all unsigned, then the minimum values for these variables are all zero and the bias reduces to a particularly simple form:

If the inputs and the output are all signed, then the bias becomes

Binary-Point-Only Scaling

For binary-point-only scaling, finding Qa results in this simple expression:

This scaling choice results in only one addition and some bit shifting. The avoidance of any multiplications is a big advantage of binary-point-only scaling.

Accumulation

The accumulation of values is closely associated with addition:

Finding Qa_new involves one multiplication of a constant and a variable, two additions, and some bit shifting:

The important difference for fixed-point implementations is that the scaling of the output is identical to the scaling of the first input.

Binary-Point-Only Scaling

For binary-point-only scaling, finding Qa_new results in this simple expression:

This scaling option only involves one addition and some bit shifting.

Multiplication

Consider the multiplication of two real-world values:

These values are represented by the general [Slope Bias] encoding scheme described in Scaling:

In a fixed-point system, the multiplication of values results in finding the variable Qa:

This formula shows

Inherited Scaling for Speed

The number of arithmetic operations can be reduced with these choices:

The resulting formula is

Inherited Scaling for Maximum Precision

You can determine the maximum-precision scaling if the range of the variable is known. Example: Maximizing Precision shows that you can determine the range of a fixed-point operation from

and

For multiplication, you can determine the range from

where

Binary-Point-Only Scaling

For binary-point-only scaling, finding Qa results in this simple expression:

Gain

Consider the multiplication of a constant and a variable

where K is a constant called the gain. Since Va results from the multiplication of a constant and a variable, finding Qa is a simplified version of the general fixed-point multiplication formula:

Note that the terms in the parentheses can be calculated offline. Therefore, there is only one multiplication of a constant and a variable and one addition.

To implement the above equation without changing it to a more complicated form, the constants need to be encoded using a binary-point-only format. For each of these constants, the range is the trivial case of only one value. Despite the trivial range, the binary point formulas for maximum precision are still valid. The maximum-precision representations are the most useful choices unless there is an overriding need to avoid any shifting. The encoding of the constants is

resulting in the formula

Inherited Scaling for Speed

The number of arithmetic operations can be reduced with these choices:

If the number of bits is different, then either handling potential overflows or performing sign extensions is the only possible operation involved.

Inherited Scaling for Maximum Precision

The scaling for maximum precision does not need to be different from the scaling for speed unless the output has fewer bits than the input. If this is the case, then saturation should be avoided by dividing the slope by 2 for each lost bit. This prevents saturation but causes rounding to occur.

Division

Division of values is an operation that should be avoided in fixed-point embedded systems, but it can occur in places. Therefore, consider the division of two real-world values:

These values are represented by the general [Slope Bias] encoding scheme described in Scaling:

In a fixed-point system, the division of values results in finding the variable Qa:

This formula shows

Inherited Scaling for Speed

The number of arithmetic operations can be reduced with these choices:

The resulting formula is

If Bc ≠ 0, then no clear recommendation can be made.

Inherited Scaling for Maximum Precision

You can determine the maximum-precision scaling if the range of the variable is known. Example: Maximizing Precision shows that you can determine the range of a fixed-point operation from

and

For division, you can determine the range from

where for nonzero denominators

Binary-Point-Only Scaling

For binary-point-only scaling, finding Qa results in this simple expression:

Summary

From the previous analysis of fixed-point variables scaled within the general [Slope Bias] encoding scheme, you can conclude

Note that the previous formulas don't show the following:

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS