# How to compute number of dedicated bits in arithmetic coding in matlab

13 views (last 30 days)
alex net on 2 Dec 2018
Answered: Walter Roberson on 2 Dec 2018
Hello. I have a vector of size 4096. After applying arithmetic coding, how I can count number of bits to compute compression ratio. compression ratio = number_of_umcompressed_bits/number_of_compressed_bits. regards.

Walter Roberson on 2 Dec 2018
You have vector of values. Calculate
bit_usage = ceil(log2(NumberOfPossibleStates)) * NumberOfElements;
If your output is a vector of values each of which is 0 or 1, or '0' or '1', then the number of states is 2, log2(2) is 1, and the calculation becomes identical to NumberOfElements.
If you output is a vector of uint8 and all values from 0 to 255 can occur, then that is 256 states, log2() is 8, and the number of bits is then 8 * NumberOfElements.
This calculation is also valid on the input, but on the input side you need think more about whether you want to calculate based upon possible states or upon representation. For example if the input is in hexadecimal, then you have an 8 bit character that is restricted to 0 to 9 or A, B, C, D, E, F, which is 16 possible states, log2(16) = 4. So you need to think about whether you want to count the 8 bits per character of input that was the external representation, or the 4 bits per character that is the information content.