Open baggepinnen opened 1 week ago
The underlying models seems to have several issues:
2^bits
levels there are 2^bits-1
differences.A better variant seems to be: y = resolution*floor((u-yMin)/resolution+0.5)+yMin;
and parameter Real resolution = if quantized then ((yMax - yMin)/(2^bits-1)) else 0;
, but I don't know how such devices are normally built.
Note that the problem gets worse as the number of bits decreases; and it seems no-one counted the 257 levels for the default setting.
As expected the DSP world is a bit more complicated.
What I proposed is closer to a mid-riser one https://en.wikipedia.org/wiki/Quantization_(signal_processing) - whereas the current formula seems to be broken variant of a dead-zone quantizer (a form of mid-tread quantizer).
However, having non-symmetric limits isn't considered on that page; and I assume most people who use a non-symmetric limit in practice use it for a non-negative limit (such as yMin=0, yMax=255).
The following model demonstrates that the quantization function may output more levels than the number of bits allows, which is $2^\text{bits}$. The quantization is here set to 2 bits, allowing for 4 distinct output levels However, the number of unique output levels is 5:
Full model, implemented with OpenModelica