开发者

How to calculate quantization error from 16bit to 8bit?

Does anyone know how to calculate the error of quantizing from 16bit to 8bit?

I have looked at the Wikipedia article about Quantization, but it doesn't explain this.

Can anyone explain how it is done?

Lots of love, Louise

Update:开发者_JS百科 My function looks like this.

unsigned char quantize(double d, double max) {
  return (unsigned char)((d / max) * 255.0);
}


I think you need to convert both the 16-bit value and the 8-bit value to their respective analog values that they represent and then take the difference between those. To stick with the wikipedia entries, here is one that talks about it.


It is there in the Wikipedia article, expressed as signal to noise ratio. But I guess the real question is, in what units do you want the result? As a signal to noise power ratio, it's 20 log(2^8) = 55 dB

You probably need to read this: http://en.wikipedia.org/wiki/Decibel


It is interesting that if you treat last 8 bits as signed char, it gives you correct quantization error.

char absolute_quatization_error(short measurement) //lets consider that short is 16bits
{
   return (measurement & 0xFF);
}

Ok upper function is tricky you should use something like.

short absolute_quatization_error(short measurement) //lets consider that short is 16bits
{
    short r;
    r=measurement & 0xFF;
    if (r>0x7F)
        return (0xFF-r);
    else
        return r;
}

If you need relative error you should use.

float relative_quatization_error(short measurement)
{
     return 1.0*absolute_quatization_error(measurement)/((float)measurement); //i did not check if this correctly converts to float.
}


Generally, the error is the difference between the reconstituted quantized signal and the original signal.

Say your original series is Xi, and you quantize by doing an integer division by q - you get a series of integer values int(Xi/q). Your error term is e = Xi - q*int(Xi/q).

For example: a sample value of 60000 divided by 256 gives 234. 234*256 = 59904 after dequantization. The quantization error is 60000-59904=96.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜