FixedPoint Designer 

This example shows how to define unsigned and signed two's complement integer and fixedpoint numbers.
FixedPoint Number Definitions
This example illustrates the definitions of unsigned and signedtwo'scomplement integer and fixedpoint numbers.
Unsigned integers are represented in the binary number system in the following way. Let
b = [b(n) b(n1) ... b(2) b(1)]
be the binary digits of an nbit unsigned integer, where each b(i) is either one or zero. Then the value of b is
u = b(n)*2^(n1) + b(n1)*2^(n2) + ... + b(2)*2^(1) + b(1)*2^(0)
For example, let's define a 3bit unsigned integer quantizer, and enumerate its range.
originalFormat = get(0, 'format'); format q = quantizer('ufixed',[3 0]); [a,b] = range(q); u = (a:eps(q):b)' % Now, let's display those values in binary. b = num2bin(q,u)
u = 0 1 2 3 4 5 6 7 b = 000 001 010 011 100 101 110 111
Unsigned Integer Number Circle.
Let's array them around a clock face with their corresponding binary and decimal values.
fidemo.numbercircle(q);
Unsigned fixedpoint values are unsigned integers that are scaled by a power of two. We call the negative exponent of the power of two the "fractionlength".
If the unsigned integer u is defined as before, and the fractionlength is f, then the value of the unsigned fixedpoint number is
uf = u*2^f
For example, let's define a 3bit unsigned fixedpoint quantizer with a fractionlength of 1, and enumerate its range.
q = quantizer('ufixed',[3 1]); [a,b] = range(q); uf = (a:eps(q):b)' % Now, let's display those values in binary. b = num2bin(q,uf)
uf = 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000 3.5000 b = 000 001 010 011 100 101 110 111
Unsigned FixedPoint Number Circle.
Let's array them around a clock face with their corresponding binary and decimal values.
fidemo.numbercircle(q);
Unsigned Fractional FixedPoint.
Unsigned fractional fixedpoint numbers are fixedpoint numbers whos fractionlength f is equal to the wordlength n, which produces a scaling such that the range of numbers is between 0 and 12^f, inclusive. This is the most common form of fixedpoint numbers because it has the nice property that all of the numbers are less than one, and the product of two numbers less than one is a number less than one, and so multiplication does not overflow.
Thus, the definition of unsigned fractional fixedpoint is the same as unsigned fixedpoint, with the restriction that f=n, where n is the wordlength in bits.
uf = u*2^f
For example, let's define a 3bit unsigned fractional fixedpoint quantizer, which implies a fractionlength of 3.
q = quantizer('ufixed',[3 3]); [a,b] = range(q); uf = (a:eps(q):b)' % Now, let's display those values in binary. b = num2bin(q,uf)
uf = 0 0.1250 0.2500 0.3750 0.5000 0.6250 0.7500 0.8750 b = 000 001 010 011 100 101 110 111
Unsigned Fractional FixedPoint Number Circle.
Let's array them around a clock face with their corresponding binary and decimal values.
fidemo.numbercircle(q);
Signed Two'sComplement Integers.
Signed integers are represented in two'scomplement in the binary number system in the following way. Let
b = [b(n) b(n1) ... b(2) b(1)]
be the binary digits of an nbit signed integer, where each b(i) is either one or zero. Then the value of b is
s = b(n)*2^(n1) + b(n1)*2^(n2) + ... + b(2)*2^(1) + b(1)*2^(0)
Note that the difference between this and the unsigned number is the negative weight on the mostsignificantbit (MSB).
For example, let's define a 3bit signed integer quantizer, and enumerate its range.
q = quantizer('fixed',[3 0]); [a,b] = range(q); s = (a:eps(q):b)' % Now, let's display those values in binary. b = num2bin(q,s) % Note that the mostsignificantbit of negative numbers is 1, and positive % numbers is 0.
s = 4 3 2 1 0 1 2 3 b = 100 101 110 111 000 001 010 011
Signed Two'sComplement Integer Number Circle.
Let's array them around a clock face with their corresponding binary and decimal values.
The reason for this ungainly looking definition of negative numbers is that addition of all numbers, both positive and negative, is carried out as if they were all positive, and then the n+1 carry bit is discarded. The result will be correct if there is no overflow.
fidemo.numbercircle(q);
Signed fixedpoint values are signed integers that are scaled by a power of two. We call the negative exponent of the power of two the "fractionlength".
If the signed integer s is defined as before, and the fractionlength is f, then the value of the signed fixedpoint number is
sf = s*2^f
For example, let's define a 3bit signed fixedpoint quantizer with a fractionlength of 1, and enumerate its range.
q = quantizer('fixed',[3 1]); [a,b] = range(q); sf = (a:eps(q):b)' % Now, let's display those values in binary. b = num2bin(q,sf)
sf = 2.0000 1.5000 1.0000 0.5000 0 0.5000 1.0000 1.5000 b = 100 101 110 111 000 001 010 011
Signed FixedPoint Number Circle.
Let's array them around a clock face with their corresponding binary and decimal values.
fidemo.numbercircle(q);
Signed Fractional FixedPoint.
Signed fractional fixedpoint numbers are fixedpoint numbers whos fractionlength f is one less than the wordlength n, which produces a scaling such that the range of numbers is between 1 and 12^f, inclusive. This is the most common form of fixedpoint numbers because it has the nice property that the product of two numbers less than one is a number less than one, and so multiplication does not overflow. The only exception is the case when we are multiplying 1 by 1, because +1 is not an element of this number system. Some processors have a special multiplication instruction for this situation, and some add an extra bit in the product to guard against this overflow.
Thus, the definition of signed fractional fixedpoint is the same as signed fixedpoint, with the restriction that f=n1, where n is the wordlength in bits.
sf = s*2^f
For example, let's define a 3bit signed fractional fixedpoint quantizer, which implies a fractionlength of 2.
q = quantizer('fixed',[3 2]); [a,b] = range(q); sf = (a:eps(q):b)' % Now, let's display those values in binary. b = num2bin(q,sf)
sf = 1.0000 0.7500 0.5000 0.2500 0 0.2500 0.5000 0.7500 b = 100 101 110 111 000 001 010 011
Signed Fractional FixedPoint Number Circle.
Let's array them around a clock face with their corresponding binary and decimal values.
fidemo.numbercircle(q);
set(0, 'format', originalFormat);