The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or
reproduced in any form without prior written consent from The MathW orks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation
by, for, or through the federal government of the United States. By accepting delivery of the Program
or Documentation, the government hereby agrees that this software or documentation qualifies as
commercial computer software or commercial computer software documentation as such terms are used
or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and
conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern
theuse,modification,reproduction,release,performance,display,anddisclosureoftheProgramand
Documentation by the federal government (or other entity acquiring for or through the federal government)
and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the
government’s needs or is inconsistent in any respect with federal procurement law, the government agrees
to return the Program and Docu mentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand
names may be trademarks or registered trademarks of their respective holders.
Patents
The MathWorks products are protected by one or more U.S. patents. Please see
www.mathworks.com/patents for more information.
Revision History
March 2009Online onlyNew for Version 6.1 (Release 2009a)
September 2009 Online onlyRevised for Version 6.2 (Release 2009b)
March 2010Online onlyRevised for Version 6.3 (Release 2010a)
Fixed Point™ Reference
1
A
Contents
Function Reference
Selected Bibliography
Glossary
Index
iii
ivContents
Function Reference
1
autofixexp
PurposeAutomatically change scaling of fixed-point data types
Syntaxautofixexp
DescriptionThe autofixexp script automatically changes the scaling for model
objects that specify fixed-point data types. However, if an object’s Lock
output data type setting against changes by the fixed-point tools
parameter is selected, the script refrains from scaling that object.
This script collects range data for model objects, either from design
minimum and maximum values that objects specify explicitly, or from
logged minimum and maximum values that occur during simulation.
Based on these values, the tool changes the scaling of fixed-point data
typesinamodelsoastomaximizeprecisionandcovertherange.
You can specify design minimum and maximum values for m odel objects
using parameters typically titled Output minimum and Outputmaximum. See “Blocks That Allow Signal Range Specification” in
Simulink
specify these values. In the autoscaling procedure that the
script executes, design minimum and maximum values take precedence
over the simulation range.
®
User’s Guide for a list of Simulink blocks that permit you to
autofixexp
1-2
If yo u intend to scale fixed-point data t ypes using simulation minimum
and maximum values, the script yields meaningful results when
exercising the full range of values over which your design is meant
to run. Therefore, the simulation you run prior to using
must simulate your design over its full intended operating range. It is
especially important that you use simulation inputs with appropriate
speed and amplitude profiles for dynamic systems. The response of
a linear dynamic system is frequency dependent. For example, a
bandpass filter will show almost noresponsetoveryslowandvery
fast sinusoid inputs, whereas the signal of a sinusoid input with a
frequency in the passband will be passed or even significantly amplified.
The response of nonlinear dynamic systems can have complicated
dependence on both the signal speed and amplitude.
autofixexp
Note If you already know the simulation range you need to cover,
you can use an alternate autoscaling technique described in the
fixptbestprec reference page in the Simulink Reference.
To control the parameters associated with automatic scaling, such as
safety margins, use the Fixed-Point Tool.
For more information, see “Overview of the Fixed-Point Tool”.
To learn how to use the Fixed-Point Tool, refer to “Tutorial: Feedback
Controller”.
See Alsofxptdlg
autofixexp
1-3
fixpt_instrument_purge
PurposeRemove corrupt fixed-point instrumentation from model
Note fixpt_instrument_purge will be removed in a future release.
Syntaxfixpt_instrument_purge
fixpt_instrument_purge(modelName, interactive)
DescriptionThe fixpt_instrument_purge script finds and removes fixed-point
instrumentation from a model left by the Fixed-Point Tool and the
fixed-point autoscaling script. The Fixed-Point Tool and the fixed-point
autoscaling script each add callbacks to a model. For example, the
Fixed-Point Tool appends commands to model-level callbacks. These
callbacks make the Fixed-Point Tool respond to simulation events.
Similarly, the autoscaling script adds instrumentation to some
parameter values that gathers information required by the script.
Normally, these types of instrumentation are automatically removed
from a model. The Fixed-Point Tool removes its instrumentation when
the model is closed. The autoscaling script removes its instrumentation
shortly after it is added. However, there are cases where abnormal
termination of a model leaves fix ed -point instrumentation behind . The
purpose of
instrumentation left over from abnormal termination.
fixpt_instrument_purge is to find and remove fixed-point
instrumentation from model
default, w hich prompts you to make each change. When
is set to false, all found instrumentation is automatically removed
from the model.
See Alsoautofixexp, fxptdlg
1-4
modelName. interactive is true by
interactive
showfixptsimerrors
PurposeShow overflows from most recent fixed-point simulation
Note showfixptsimerrors will be removed in a future release. Use
fxptdlg instead.
Syntaxshowfixptsimerrors
DescriptionThe showfixptsimerrors script displays any overflows from the most
recent fixed-point simulation. This information is also visible in the
Fixed-Point Tool.
See Alsoautofixexp, fxptdlg
1-5
showfixptsimranges
PurposeShow logged maximum values, minimum values, and overflow data
from fixed-point simulation
Note showfixptsimranges will be removed in a future release. Use
fxptdlg instead.
Syntaxshowfixptsimranges
showfixptsimranges(action)
Descriptionshowfixptsimranges displays the l ogged maximum values, minimum
values, and overflow data from the most recent fixed-point simulation
in the MATLAB
showfixptsimranges(action) stores the l ogge d maximum values,
minimum values, and overflow data from the most recent fixed-point
simulation in the workspace variable
'verbose', the logged data also appears in the MATLAB Command
Window. If
®
Command Window.
FixPtSimRanges.Ifaction is
action is 'quiet', no data appears.
See Alsoautofixexp, fxptdlg
1-6
Selected Bibliography
[1] Burrus,C.S.,J.H.McClellan,A.V.Oppenheim,T.W.Parks,R.W.Schafer,
and H.W. Schuessler, C omputer-Based Exercises for Signal Processing UsingMATLAB, Prentice Hall, Englewood Cliffs, New Jersey, 1994.
[2] Franklin, G.F., J.D. Powell, and M.L. Workman, Digital Control ofDynamic Systems, Second Edition, Addison-Wesley P ub li shing Company,
Reading, Massachusetts, 1990.
[3] Handbook For Digital Signal Processing,editedbyS.K.MitraandJ.F.
Kaiser, John Wiley & Sons, Inc., New York, 1993.
A
[4] Hanselmann, H., “Implementation of Digital Controllers — A Survey,”
Automatica, Vol. 23, No. 1, pp. 7-32, 1987.
[5] Jackson, L.B., Digital Filters and Signal Processing, Second Edition,
Kluwer Academic Publishers, Seventh Printing, Norwell, Massachusetts,
1993.
[6] Middleton, R. and G. Goodwin, Digital Control and Estimation — AUnified Approach, Prentice Hall, Englewood Cliffs, New Jersey. 1990.
[7] Moler, C., “Floating points: IEEE Standard unifies arithmetic model,”
Cleve’s Corner, The MathWorks, Inc., 1996. You can find this article at
[8] Ogata, K., Discrete-Time Control Systems, Second Edition,PrenticeHall,
Englewood Cliffs, New Jersey, 1995.
[9] Roberts, R.A. and C.T. Mullis, Digital Signal Processing, Addison-Wesley
Publishing Company, Reading, Massachusetts, 1987.
A Selected Bibliography
A-2
Glossary
Glossary
This glossary defines terms related to fixed-point data types and numbers.
These terms may appear in some or all of the documents that describe
products from The MathWorks™ that have fixed-point support.
arithmetic shift
Shift of the bits of a binary word for which the sign bit is recycled for
each bit shift to the right. A zero is incorporated into the least significant
bit of the word for each bit shift to the left. In the absence of overflows,
each arithmetic sh if t to the right is equivalent to a division by 2, and
each arithmetic shift to the left is equivalent to a multiplication by 2.
See also binary point, binary word, bit, logical shift, most significant bit
bias
Part of the numerical representation used to interpret a fixed-point
number. Along with the slope, the bias forms the scaling of the number.
Fixed-point numbers can be represented as
real world valueslope stored integerbias-=×+()
wheretheslopecanbeexpressedas
slopefractional slope
=×2
See also fixed-point representation, fractional slope, integer, scaling,
slope, [Slope Bias]
binary number
Value represented in a system of numbers that has two as its base and
that uses 1’s and 0’s (bits) for its notation.
See also bit
exponent
Glossary-1
Glossary
binary point
Symbol in the shape of a period that separates the integer and fractional
parts of a binary number. Bits to the left of the binary point are
integer bits and/or sign bits, and bits to the right of the binary point
are fractional bits.
See also binary number, bit, fraction, integer, radix point
binary point-only scaling
Scaling of a binary number that results from shifting the binary point of
the number right or left, and which therefore can only occur by powers
of two.
See also binary number, binary point, scaling
binary word
Fixed-length sequence of bits (1’s and 0’s). In digital hardware, numbers
are stored in binary words. The way in which hardware components or
software functions interpret this sequence of 1’s and 0’s is described
by a data type.
Glossary-2
See also bit, data type, word
bit
Smallest unit of information in computer software or hardware. A bit
canhavethevalue0or1.
ceiling (round toward)
Rounding mode that rounds to the closest representable number in the
direction of positive infini t y. This is equivalent to the
ceil mode in
Fixed-Point Toolbox™ software.
See also convergent rounding, floor (round toward), nearest (round
toward), rounding, truncation, zero (round toward)
contiguous binar y point
Binary point that occurs within the word length of a data type. For
example, if a data type has four bits, its contiguous binary point must
be understood to occur at one of the following five positions:
.
0000
.
0 000
.
00 00
.
000 0
.
0000
See also data type, noncontiguous binary point, word length
convergent rounding
Rounding mode that rounds to the nearest allowable quantized value.
Numbers that are exactly halfw ay between the two nearest allowable
quantized values are rounded up only if the least significant bit (after
rounding) would be set to
0.
Glossary
See also ceiling (round toward), floor (round toward), nearest (round
toward), rounding, truncation, zero (round toward)
data type
Set of characteristics that define a group of values. A fixed-point data
type is defined by its word length, its fraction length, and whether it
is signed or unsigned. A floating-point data type is defined by its word
length and whether it is signed or unsigned.
See also fixed-point representation, floating-point representation,
fraction length, signedness, word length
data type override
Parameter in the Fixed-Point Tool that allows you to set the output data
type and scaling of fixed-point blocks on a system or subsystem level.
See also data type, scaling
exponent
Part of the numerical representation used to express a floating-point or
fixed-point number.
Glossary-3
Glossary
1. Floating-point numbers are typically represented as
real - world valuemantissa
=×2
exponent
2. Fixed-point numbers can be represented as
real world valueslope stored integerbias-=×+()
wheretheslopecanbeexpressedas
slopefractional slope
=×2
exponent
The exponent of a fixed-point number is equal to the negative of the
fraction length:
exponentfraction length=− ×1
See also bias, fixed-point representation, floating-point representation,
fraction length, fraction al slope, integer, mantissa, slope
fixed-point representation
Method for representing numerical values and data types that have
a set range and precision.
1. Fixed-point numbers can be represented as
Glossary-4
real world valueslope stored integerbias-=×+()
wheretheslopecanbeexpressedas
slopefractional slope
=×2
The slope and the bias together repres
exponent
ent the scaling of the fixed-point
number.
2. Fixed-point data types can be defined by their word length, their
fraction length, and whether they are signed or unsigned.
See also bias, data type, exponent, fraction length, fractional slope,
integer, precision, range, scaling, slope, word length
floating-point representa tion
Method for representing numerical values and data types that can have
changing range and precision.
1. Floating-point numbers can be represented as
Glossary
real - world valuemantissa
=×2
exponent
2. Floating-point data types are defined by their word length.
See also datatype,exponent,mantissa,precision,range,wordlength
floor (round toward)
Rounding mode that rounds to the closest representable number in
the direction of negative infinity.
See also ceiling (round toward), convergent rounding, nearest (round
toward), rounding, truncation, zero (round toward)
fraction
Part o f a fixed-point number represented by the bits to the right of the
binary point. The fraction represents numbers that are less than one.
See also binary point, bit, fixed-point representation
fraction length
Number of bits to the right of the binary point in a fixed-point
representation of a number.
See also binary point, bit, fixed-point representation, fraction
Glossary-5
Glossary
fractional slope
Part of the numerical representation used to express a fixed-point
number. Fixed-point numbers can be represented as
real world valueslope stored integerbias-=×+()
wheretheslopecanbeexpressedas
slopefractional slope
=×2
The term slope adjustment is sometimes u
exponent
sed as a synonym for
fractional slope.
See also bias, exponent, fixed-point representation, integer, slope
guard bits
Extra bits in either a hardware register or software simulation that are
added to the high end of a binary word to ensure that no information
is lost in case of overflow.
See also binary word, b it, overflow
integer
1. Part of a fixed-point number represented by the bits to the left of the
binary point. The integer represents numbers that are greater than
or equal to one.
2. Also called the "stored integer." The raw binary number, in which the
binary point is assumed to be at the far right of the word. The integer
is part of the numerical re pre sentation used to express a fixed-point
number. Fixed-point numbers can be represented as
Glossary-6
fraction length
real - world valuestored integer
−
=×
2
or
real world valueslope stored integerbias-=×+()
wheretheslopecanbeexpressedas
Glossary
slopefractional slope
=×2
exponent
See also bias, fixed-point representation, fractional slope, integer,
real-world value, slope
integer length
Number of bits to the left of the bina ry point in a fixed-point
representation of a number.
See also binary point, bit, fixed-point representation, fraction length,
integer
least significant bit (LSB)
Bit in a binary word that can represent the smallest value. The LSB is
the rightmost bit in a big-endian-ordered binary word. The weight of
the LSB is related to the fraction length according to
weight of LSB
fraction length
=−2
See also big-endian, binary word, bit, most significant bit
logical shift
Shift of the bits of a binary word, for which a zero is incorporated into
the m ost significant bit for each bit shift to the right and into the least
significant bit for eac h bit shift to the left.
See also arithmetic shift, binary point, binary word, bit, most significant
bit
mantissa
Part of the numerical re presentation used to express a floating-point
number. Floating-point numbers are typically represented as
real - world valuemantissa
=×2
exponent
See also exponent, floating-point representation
Glossary-7
Glossary
most s ig n ificant bit (MSB)
Bit in a binary word that can represent the largest value. The MSB is
the leftmost bit in a big-endian-ordered binary word.
See also binary word, bit, least significant bit
nearest (round toward)
Rounding mode that rounds to the closest representable number, with
the exact midpoint rounded to the closest representable number in the
direction of posit iv e infinity. This is equiv al ent to the
nearest mode
in Fixed-Point Toolbox software.
See also ceiling (round toward), convergent rounding, floor (round
toward), rounding, truncation, zero (round toward)
noncontiguous binar y point
Binary point that is understood to fall outside the word length of a
data type. For example, the binary point for the following 4-bit word is
understood to occur two bits to the right of the word length,
Glossary-8
0000 .
thereby giv ing the bits of the word the following potential values:
5432
2222
.
See also binary point, data type, word length
one’s complement representation
Representation of signed fixed-point numbers. Negating a binary
number in one’s complement requires a bitwise complement. That is, all
0’sareflippedto1’sandall1’sareflippedto0’s. Inone’scomplement
notation there are two ways to represent zero. A binary word of all
0’srepresents"positive"zero,while a binary word of all 1’s represents
"negative" zero.
See also binary number, binary word, sign/magnitude representation,
signed fixed-point, two’s complement representation
overflow
Situation that occurs when the magnitude of a calculation result is too
large for the range of the data type being used. In many cases you can
choose to either saturate or wrap overflows.
See also saturation, wrapping
padding
Extending the least significant bit of a binary word with one or more
zeros.
See also least significant bit
precision
1. Measure of the smallest numerical interval that a fixed-point data
type and scaling can represent, determined by the value of the number’s
least significant bit. The precision is given by the slope, or the number
of fractional bits. The term resolution is sometimes used as a synonym
for this definition.
Glossary
2. Measure of the difference between a real-world numerical value and
the value of its quantized representation. This is sometimes called
quantization error or quantization noise.
See also data type, fraction, least significant bit, quantization,
quantization error, range, slope
Qformat
Representation used by Texas Instruments™ to encode signed two’s
complement fixed-point data types. This fixed-point notation takes the
form
Qm n.
where
• Q indicates that the number is in Q format.
• m is the number of bits used to designate the two’s complement
integer part of the number.
Glossary-9
Glossary
• n is the number of bits used to designate the two’s complement
fractional part of the number, or the number of bits to the right
of the binary point.
In Q format notation, the most significant bit is assumed to be the sign
bit.
See also binary point, bit, data type, fixed-point representation, fraction,
integer, two’s complement
quantization
Representation of a value by a data type that has too few bits to
representitexactly.
See also bit, data type, quantization error
quantization error
Error introduced when a value is represented by a data type that has
too few bits to represent it exactly, or when a value is converted from
one data type to a shorter data type. Quantization error is also called
quantization noise.
Glossary-10
See also bit, data type, quantization
radix point
Symbol in the shape of a period that separates the integer and fractional
parts of a number in any base system. Bits to the left of the radix point
are integer and/or sign bits, and bits to the right of the radix point are
fraction bits.
See also binary point, bit, fraction, integer, sign bit
range
Span of numbers that a certain data type can represent.
See also data type, precision
real-world value
Stored integer value with fixed-point scaling applied. Fixed-point
numbers can be represented as
fraction length
real - world valuestored integer
−
=×
2
or
real world valueslope stored integerbias-=×+()
wheretheslopecanbeexpressedas
Glossary
slopefractional slope
=×2
exponent
See also integer
resolution
See precision
rounding
Limiting the number of bits required to express a number. One or
more least significant bits are dropped, resulting in a loss of precision.
Rounding is necessary when a value cannot be expressed exactly by the
number of bits designated to represent it.
See also bit, ceiling (round toward), convergent rounding, floor (round
toward), least significant bit, nearest ( round toward), precision,
truncation, zero (round toward)
saturation
Method of handling numeric overflow that represents positive overflows
as the largest positive number in therangeofthedatatypebeingused,
and negative overflows as the largest negative number in the range.
See also overflow, wrapping
Glossary-11
Glossary
scaled double
A double data type that retains fixed-point scaling information. For
example, in Simulink and Fixed-Point Toolbox software you can use
data type override to convert your fixed-point data ty pe s to scaled
doubles. You can then simulate to determine the ideal floating-point
behavior of your system. After you gather that information you can
turn data type override off to return to fixed-point data types, and your
quantities still have their original scaling information because it was
held in the scaled double data types.
scaling
1. Format used for a fixed-point number of a given word length and
signedness. The slope and bias together form the scaling of a fixed-point
number.
2. Changing the slope and/or bias of a fixed-point number without
changing the stored integer.
See also bias, fixed-point representation, integer, slope
Glossary-12
shift
Movement of the bits of a binary word either towa rd the most significant
bit ("to the left") or toward the least significant bit ("to the right"). Shifts
to the right can be either logical, where the spaces emptied at the f ront
ofthewordwitheachshiftarefilledinwithzeros,orarithmetic,where
thewordissignextendedasitisshiftedtotheright.
See also arithmetic shift, logical shift, sign extension
sign bit
Bit (or bits) in a signed binary number that indicates whether the
number is pos itiv e or negative.
See also binary number, bit
sign extension
Addition of bits that have the value of the most significant bit to the
high end of a two’s complement number. Sign extension does not change
the value of the binary number.
See also binary number, guard bits, most significant bit, two’s
complement representation, word
sign/magnitude representation
Representation of signed fixed-point or floating-point numbers. In
sign/magnitude representation, one bit of a binary word is always
the dedicated sign bit, while the remaining bits of the word encode
the magnitude of the number. Negation using sign/magnitude
representation consists of flipping the sign bit from 0 (positive) to 1
(negative), or from 1 to 0.
See also binary word, bit, fixed-point representation, floating-point
representation, one’s complement representation, sign bit, signed
fixed-point, signedness, two’s complement representation
signed fixed-point
Fixed-point number or data type that can represent both positive and
negative numbers.
See also data type, fixed-point representation, signedness, unsigned
fixed-point
Glossary
signedness
The signedness of a number or data type can be signed or unsigned.
Signed numbers and data types can represent both positive and negative
values, whereas unsigned numbers and data types can only represent
values that are greater than or equal to zero.
See also data type, sign bit, sign/magnitude representation, signed
fixed-point, unsigned fixed-point
slope
Part of the numerical representation used to express a fixed-point
number. Along with the bias, the slope forms the scaling of a fixed-point
number. Fixed-point numbers can be represented as
real world valueslope stored integerbias-=×+()
wheretheslopecanbeexpressedas
slopefractional slope
=×2
exponent
Glossary-13
Glossary
See also bias, fixed-point representation, fractional slope, integer,
scaling, [Slope Bias]
slope adjustment
See fractional slope
[Slope Bias]
Representation used to define the scali ng of a fixed-point number.
See also bias, scaling, slope
stored integer
See integer
trivial scaling
Scaling that results in the real-world value of a number being simply
equal to its stored integer value:
real - world valuestored integer=
Glossary-14
In [Slope Bias] representation, fixed-point numbers can be represented
as
real world valueslope stored integerbias-=×+()
In the trivial case, slope = 1 and bias = 0.
In terms of binary point-only scaling, the binary point is to the right o
the least significant bit for trivial scaling, meaning that the fracti
f
on
length is zero:
fraction length
real - world valuestored integerstored i
=× =
−
2nnteger × 2
Scaling is always trivial for pure integers, such as int8, and also for the
true floating-point types
single and double.
See also bias, binary point, binary point-only scaling, fixed-point
representation, fraction length, integer, least significant bit, scaling,
slope, [Slope Bias]
See also ceiling (round toward), convergent rounding, floor (round
toward), nearest (round toward), rounding, zero (round toward)
two’s complement repres en tation
Common representation of signed fixed-point numbers. Negation using
signed two’s complement representation consists of a translation into
one’s complement followed by the binary addition of a one.
See also binary word, one’s complement representation, sign/magnitude
representation, signed fixed-point
unsigned fixed-point
Fixed-point number or data type that can only represent numbers
greaterthanorequaltozero.
Glossary
See also data type, fixed-point representation, signed fixed-point,
signedness
word
Fixed-length sequence of binary digits (1’s and 0’s). In digital hardware,
numbers are stored in words. The way hardware components or
software functions interpret this sequence of 1’s and 0’s is described
by a data type.
See also binary word, data type
word length
Number of bits in a binary word or data type.
See also binary word, bit, data type
wrapping
Method of handling overflow. Wrapping uses modulo arithmet
a number that falls outside of the representable range the d
being used back into the representable range.
See also data type, overflow, range, saturation
ic to cast
ata type
Glossary-15
Glossary
zero (round toward)
Rounding mode that rounds to the closest representable number in the
direction of zero. This is equivalent to the
fix mode in Fixed-Point
Toolbox software.
See also ceiling (round toward), convergent rounding, floor (round
toward), nearest (round toward), rounding, truncation