tags:

views:

439

answers:

4

Hi everyone,

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: My function looks like this.

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

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.

Ori Pessach
So it is not possible to calculate the error in general?
Louise
That might come in handy. Thanks a lot =)
Louise
+2  A: 

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.

Mark Wilkins
+1  A: 

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.
}
ralu
+1  A: 

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

Andrew McGregor
So I guess it is the SQNR values I have to calculate and subtract?SQNR_16 - SQNR_8 = 20*log_10(2^16) - 20*log_10(2^8) = 48.165 dB Or should it be SQNR = 20*log10(2^(16-8)) = 55dB, if I want to know the error going from 16bit to 8bit?
Louise
The latter, 55 dB going from 16 bit to 8 bit.
Andrew McGregor