Fixed-Point Numbers

About Fixed-Point Numbers

Fixed-point numbers are stored in data types that are characterized by their word size in bits, binary point, and whether they are signed or unsigned. The Simulink® Fixed Point™ software supports integers, fractionals, and generalized fixed-point numbers. The main difference among these data types is their default binary point.

A common representation of a binary fixed-point number (either signed or unsigned) is shown in the following figure.

where

Signed Fixed-Point Numbers

Computer hardware typically represents the negation of a binary fixed-point number in three different ways: sign/magnitude, one's complement, and two's complement. Two's complement is the preferred representation of signed fixed-point numbers and is supported by the Simulink Fixed Point software.

Negation using two's complement consists of a bit inversion (translation into one's complement) followed by the addition of a one. For example, the two's complement of 000101 is 111011.

Whether a fixed-point value is signed or unsigned is usually not encoded explicitly within the binary word; that is, there is no sign bit. Instead, the sign information is implicitly defined within the computer architecture.

Binary Point Interpretation

The binary point is the means by which fixed-point numbers are scaled. It is usually the software that determines the binary point. When performing basic math functions such as addition or subtraction, the hardware uses the same logic circuits regardless of the value of the scale factor. In essence, the logic circuits have no knowledge of a scale factor. They are performing signed or unsigned fixed-point binary algebra as if the binary point is to the right of b0.

Within the Simulink Fixed Point software, the main difference between fixed-point data types is the default binary point. For integers and fractionals, the binary point is fixed at the default value. For generalized fixed-point data types, you must either explicitly specify the scaling by configuring dialog box parameters, or inherit the scaling from another block. The sections that follow describe the supported fixed-point data types.

Integers

The default binary point for signed and unsigned integer data types is assumed to be just to the right of the LSB. You specify unsigned and signed integers with the uint and sint functions, respectively.

Fractionals

The default binary point for unsigned fractional data types is just to the left of the MSB, while for signed fractionals the binary point is just to the right of the MSB. If you specify guard bits, then they lie to the left of the binary point. You specify unsigned and signed fractional numbers with the ufrac and sfrac functions, respectively.

Generalized Fixed-Point Numbers

For signed and unsigned generalized fixed-point numbers, there is no default binary point. You specify unsigned and signed generalized fixed-point numbers with the ufix and sfix functions, respectively.

Scaling

The dynamic range of fixed-point numbers is much less than that of floating-point numbers with equivalent word sizes. To avoid overflow conditions and minimize quantization errors, fixed-point numbers must be scaled.

With the Simulink Fixed Point software, you can select a fixed-point data type whose scaling is defined by its default binary point, or you can select a generalized fixed-point data type and choose an arbitrary linear scaling that suits your needs. This section presents the scaling choices available for generalized fixed-point data types.

A fixed-point number can be represented by a general [Slope Bias] encoding scheme

where

The slope is partitioned into two components:

The scaling modes available to you within this encoding scheme are described in the sections that follow. For detailed information about how the supported scaling modes effect fixed-point operations, refer to Recommendations for Arithmetic and Scaling.

Binary-Point-Only Scaling

As the name implies, binary-point-only (or power-of-two) scaling involves moving only the binary point within the generalized fixed-point word. The advantage of this scaling mode is that the number of processor arithmetic operations is minimized.

With binary-point-only scaling, the components of the general [Slope Bias] formula have these values:

That is, the scaling of the quantized real-world number is defined only by the slope S, which is restricted to a power of two.

In the Simulink Fixed Point software, you specify binary-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, the syntax 2^-10 defines a scaling such that the binary point is at a location 10 places to the left of the least significant bit.

[Slope Bias] Scaling

When you scale by slope and bias, the slope S and bias B of the quantized real-world number can take on any value. You specify scaling by slope and bias with the syntax [slope bias], which creates a MATLAB structure with the given slope and bias. For example, a [Slope Bias] scaling specified by [5/9 10] defines a slope of 5/9 and a bias of 10. The slope must be a positive number.

Quantization

The quantization Q of a real-world value V is represented by a weighted sum of bits. Within the context of the general [Slope Bias] encoding scheme, the value of an unsigned fixed-point quantity is given by

while the value of a signed fixed-point quantity is given by

where

bi are called bit multipliers and 2i are called the weights.

Example: Fixed-Point Format

The formats for 8-bit signed and unsigned fixed-point values are shown in the following figure.

Note that you cannot discern whether these numbers are signed or unsigned data types merely by inspection since this information is not explicitly encoded within the word.

The binary number 0011.0101 yields the same value for the unsigned and two's complement representation because the MSB = 0. Setting B = 0 and using the appropriate weights, bit multipliers, and scaling, the value is

Conversely, the binary number 1011.0101 yields different values for the unsigned and two's complement representation since the MSB = 1.

Setting B = 0 and using the appropriate weights, bit multipliers, and scaling, the unsigned value is

while the two's complement value is

Range and Precision

The range of a number gives the limits of the representation, while the precision gives the distance between successive numbers in the representation. The range and precision of a fixed-point number depend on the length of the word and the scaling.

Range

The range of representable numbers for an unsigned and two's complement fixed-point number of size ws, scaling S, and bias B is illustrated in the following figure.

For both the signed and unsigned fixed-point numbers of any data type, the number of different bit patterns is 2ws.

For example, if the fixed-point data type is an integer with scaling defined as S = 1 and B = 0, then the maximum unsigned value is 2ws - 1, because zero must be represented. In two's complement, negative numbers must be represented as well as zero, so the maximum value is 2ws - 1- 1. Additionally, since there is only one representation for zero, there must be an unequal number of positive and negative numbers. This means there is a representation for -2ws - 1 but not for 2ws - 1.

Precision

The precision (scaling) of integer and fractional data types is specified by the default binary point. For generalized fixed-point data types, the scaling must be explicitly defined as either [Slope Bias] or binary-point-only. In either case, the precision is given by the slope.

Fixed-Point Data Type Parameters

The low limit, high limit, and default binary-point-only scaling for the supported fixed-point data types discussed in Binary Point Interpretation are given in the following table. See Limitations on Precision and Limitations on Range for more information.

Fixed-Point Data Type Range and Default Scaling

Name

Data Type

Low Limit

High Limit

Default Scaling (~Precision)

Integer

uint

0

2ws - 1

1

 

sint

-2ws - 1

2ws - 1 - 1

1

Fractional

ufrac

0

1 - 2-ws

2-ws

 

sfrac

-1

1 - 2-(ws - 1)

2-(ws - 1)

Generalized Fixed-Point

ufix

N/A

N/A

N/A

 

sfix

N/A

N/A

N/A

Range of an 8-Bit Fixed-Point Data Type — Binary-Point-Only Scaling

The precision, range of signed values, and range of unsigned values for an 8-bit generalized fixed-point data type with binary-point-only scaling follow. Note that the first scaling value (21) represents a binary point that is not contiguous with the word.

Scaling

Precision

Range of Signed Values (Low, High)

Range of Unsigned Values (Low, High)

21

2.0

-256, 254

0, 510

20

1.0

-128, 127

0, 255

2-1

0.5

-64, 63.5

0, 127.5

2-2

0.25

-32, 31.75

0, 63.75

2-3

0.125

-16, 15.875

0, 31.875

2-4

0.0625

-8, 7.9375

0, 15.9375

2-5

0.03125

-4, 3.96875

0, 7.96875

2-6

0.015625

-2, 1.984375

0, 3.984375

2-7

0.0078125

-1, 0.9921875

0, 1.9921875

2-8

0.00390625

-0.5, 0.49609375

0, 0.99609375

Range of an 8-Bit Fixed-Point Data Type — [Slope Bias] Scaling

The precision and range of signed and unsigned values for an 8-bit fixed-point data type using [Slope Bias] scaling follow. The slope starts at a value of 1.25 and the bias is 1.0 for all slopes. Note that the slope is the same as the precision.

Bias

Slope/Precision

Range of Signed Values (low, high)

Range of Unsigned Values (low, high)

1

1.25

-159, 159.75

1, 319.75

1

0.625

-79, 80.375

1, 160.375

1

0.3125

-39, 40.6875

1, 80.6875

1

0.15625

-19, 20.84375

1, 40.84375

1

0.078125

-9, 10.921875

1, 20.921875

1

0.0390625

-4, 5.9609375

1, 10.9609375

1

0.01953125

-1.5, 3.48046875

1, 5.98046875

1

0.009765625

-0.25, 2.240234375

1, 3.490234375

1

0.0048828125

0.375, 1.6201171875

1, 2.2451171875

Constant Scaling for Best Precision

The following fixed-point Simulink® blocks provide a mode for scaling parameters whose values are constant vectors or matrices:

This scaling mode is based on binary-point-only scaling. Using this mode, you can scale a constant vector or matrix such that a common binary point is found based on the best precision for the largest value in the vector or matrix.

Constant scaling for best precision is available only for generalized fixed-point data types. All other fixed-point data types use their default scaling. You can use the Data Type Assistant (see Using the Data Type Assistant) on a block's dialog box to enable the constant scaling mode:

  1. Click the Show data type assistant button on a block dialog box.

    The Data Type Assistant appears.

  2. In the Data Type Assistant, set the Mode field to Fixed point.

    The Data Type Assistant displays additional options associated with fixed-point data types.

  3. Set the Scaling option to Best precision.

To understand how you might use this scaling mode, consider a 5-by-4 matrix of doubles, M, defined as

  3.3333e-005  3.3333e-006  3.3333e-007  3.3333e-008
  3.3333e-004  3.3333e-005  3.3333e-006  3.3333e-007
  3.3333e-003  3.3333e-004  3.3333e-005  3.3333e-006
  3.3333e-002  3.3333e-003  3.3333e-004  3.3333e-005
  3.3333e-001  3.3333e-002  3.3333e-003  3.3333e-004

Now suppose you specify M as the value of the Gain parameter for a Gain block. The results of specifying your own scaling versus using the constant scaling mode are described here:

Fixed-Point Data Type and Scaling Notation

The following table provides a key for various symbols that may appear in Simulink products to indicate the data type and scaling of a fixed-point value.

Symbol

Description

uint

Unsigned integer fixed-point data type

sint

Signed integer fixed-point data type

ufrac

Unsigned fraction fixed-point data type

sfrac

Signed fraction fixed-point data type

ufix

Unsigned generalized fixed-point data type

sfix

Signed generalized fixed-point data type

fltu

Doubles override of an unsigned fixed-point data type

flts

Doubles override of a signed fixed-point data type

B

Bias

E

2^

e

10^

F

Fractional slope

n

Negative

p

Decimal point

S

Slope

Example: Port Data Type Display

For example, to display the data types of ports in your model, select Port/Signal Displays > Port Data Types from the Simulink Format menu.

The port display for fixed-point signals consists of three parts: the data type, the number of bits, and the scaling. These three parts reflect the block's Output data type parameter value or the data type and scaling that is inherited from the driving block or through backpropagation.

The following model displays its port data types:

The data type display associated with the In1 block in the model indicates that the output data type is sfix(16) (a signed, 16-bit, generalized fixed-point number) with [Slope Bias] scaling of [0.2 10]. Note that this scaling is not the block's default scaling. The data type display associated with the In2 block indicates that the output data type is sfix(16) with binary-point-only scaling of 2^-6.

  


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