Why does 'round' mode of the QUANTIZER function of the Fixed Point toolbox give different results from ROUND in MATLAB?

6 views (last 30 days)
I am using the Quantizer object as follows:
Q=quantizer([12 0],'fixed','round','saturate');
round([-1.5 1.5])
Here, I get the output as:
ans =
-2 2
Now, if I use the QUANTIZE function as:
quantize(Q,[-1.5 1.5])
Here, I get the output as:
ans =
-1 2
I would like to know why it is not quantizing with a 'Roundmode' of 'round' consistent with MATLAB's round function.
This occurred when I was trying to make my MATLAB fixed point code "bit-true" with a Xilinx Blockset model in Simulink.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Jan 2010
This is expected behavior, and one that is more natural for two's-complement integers.
Rounding on the half-way point is always up (towards positive infinity) in fixed-point mode with roundmode='round'. Otherwise it would give an uneven step across zero.
The algorithm is "add half a bit and truncate."
floor([-1.5 1.5]+.5)
You would get the output:
ans =
-1 2
As a further example, see the following example:
x=(-3:.25:3)'; q=quantizer([12 0],'round');
[x quantize(q,x) floor(x+.5) round(x)]
IEEE 754 floating-point is sign-magnitude, and the round on the half-way point goes towards the larger absolute value (towards positive infinity if the number is positive, towards negative infinity if the number is negative).

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!