The quantization formula you are using will map input values to a quantized version. However it will not limit the result to only 512 levels since your input signal can exceed the [-1,+1]
range and you are not doing anything to limit the quantizer output (or input for that matter).
To limit the values you can use min
and max
built-in functions. However since they work with the modulus for complex number, you'll have to split the numbers into their real and imaginary parts first. So, quantizing complex numbers with real and imaginary parts each constrained within the range [minValue,maxValue]
can be done with:
q = (maxValue-minValue)/(2^9-1);
realPart = min(max(real(s),minValue),maxValue);
realPart = minValue + round((realPart-minValue)/q)*q;
imagPart = min(max(imag(s),minValue),maxValue);
imagPart = minValue + round((imagPart-minValue)/q)*q;
quantSignal = realPart + j*imagPart;
I mentioned earlier that your normal signal with unit variance will in general not be restricted to the [-1,1]
range (or to any range for that matter). It is thus common to try to minimize a measure of quantization error such as a mean squared error (the expected value of the squared difference between the unquantized input and the corresponding quantized output).
For a uniform quantizer and given specific signal characteristics (in this case a complex Gaussian signal) this mean squared error is a function of the number of quantization levels and the quantizer's input range. For 512 levels, the real and imaginary parts should ideally be within approximately +/- 4.2 standard deviations. Since your standard deviation is sqrt(0.5)
for the real and imaginary parts, this can be achieved with
maxValue = 4.2*sqrt(0.5);
minValue = -maxValue;
Should you need the real and imaginary part of your quantized output to be constrained to a specific range, then you may apply a scaling factor at the output of the quantizer (e.g. divide by 4.2*sqrt(0.5)
to get the real and imaginary part constrained to [-1,+1]
).