Data type conversion changes the value of the signal
Show older comments
Any clue why this happens? 

For reference this is how the signal is defined:

I guess the offset has something to deal with it.
Accepted Answer
More Answers (1)
Andy Bartlett
on 3 Feb 2023
Edited: Andy Bartlett
on 3 Feb 2023
Brief answer
The original value 0.1 is between two representable values (0.099609375 and 0.1005859375) of the type being quantized to fixdt(0,32,0.0009765625,-2056192). The original value is rounded to the nearest of the two representable values of the output type.
Tool to explain "any" case
The attached function provides a more detailed explaination of what happens when quantizing "any" scalar value to "any" numeric type. It should work fine for just about "any" case of interest including fixed-point, integer, and floating-point.
I put "any" in quotes because the analysis and plotting use calculations in double precision floating-point. If the input value or data type used was extreme relative to doubles then the analysis will fall apart. For example, the maximum finite value of double is approximately 1e308. The data type fixdt(0,8,-3000) has a maximum representable value equal to 255*2^3000 or approximately 1e905 which is extreme compared to the finite range of double.
Using tool on your example
dt1 = fixdt(0,32,0.0009765625,-2056192);
uIdeal1 = 0.1;
explainQuantizationOfConstant(uIdeal1,dt1)
2 Comments
Les Beckham
on 3 Feb 2023
I believe that @Luca Ferro is actually asking why the value changes to 0.125 when converted to single (scroll the image to the right to see the second Display block), not why it shows 0.09961 in the first Display block.
At least, that is what I am wondering.
Andy Bartlett
on 3 Feb 2023
Hi Les,
Ah. Thanks for pointing out the second possible and more likely intended question.
Andy
Categories
Find more on Digital Number Representation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!