The arithmetic coding was finished recently and this
blog is to show the testing of the code.
Since the algorithm of the code was assumed to be
infinite precision which means the computer may be out of order if the input is
too large, some short inputs were applied as examples to show the correctness
of the codes.
1. For
the first example, the inputs are as follow:
A= [0 1 2]; ‘A’ gives the
voltages of the voice signal given by the dictionary.
P= [0.2
0.4 0.4]; ‘P’ gives the probabilities corresponds to the values in A.
in= [2
1 0]; ‘in’ is input needs to be encoded.
code=[1
0 1 1 0 0]; ‘code’ is the input to be decoded.
Encoder
The function of encoder is defined as:
And the result was showed as an array with the inputs:
The output [1 0 1 1 0 0] is the binary code for ‘210’
and to be transmitted.
Decoder
The function of decoder is defined as:
And the result was showed as an array with the inputs:
The input of the encoder is identical to the output of
the decoder which means the encoder and decoder worked well and matches with
each other.
2. For
the second example, the inputs are:
A= [0 1 2 3]; ‘A’ gives the
voltages of the voice signal given by the dictionary.
P= [0.05
0.05 0.5 0.4]; ‘P’ gives the probabilities corresponds to the values in A.
in= [2 3
2 0]; ‘in’ is input needs to be encoded.
code=[0 1
1 0 1 1 0 0 0]; ‘code’ is the input to be decoded.
Encoder
And the result was showed as an array with the inputs:
The output [0 1 1 0 1 1 0 0 0] is the binary code for
‘2320’ and to be transmitted.
Decoder
And the result was showed as an array with the inputs:
The input of the encoder is identical to the output of
the decoder which means the encoder and decoder worked well and matches with
each other.
After the testing of the two examples, the functions of
the codes are proved to be correct. However, infinite precision arithmetic
coding can only be applied with short input. consequently, it is not able to
solve practical problems.
没有评论:
发表评论