ardec.m

来自「huffman 和 arithtic code run in the matla」· M 代码 · 共 40 行

M
40
字号
function symseq=ardec(symbol,pr,codeword,symlen)% Usage: symseq=ardec(symbol,pr,codeword,symlen)% arithmetic decoding in decimal given a %   symbol probability table.% output: %   symseq:  the input sequence of symbols to be encoded.% input:%   symbol: the list of symbols, a row vector of single letters%   pr:     the corresponding probabilty of each symbol%   codeword: a decimal number, the lower bound of the final interval.%   symlen: length of the decoded symbol sequence.% (C) 2002 by Yu Hen Hu% created: 11/14/2002%format longhigh_range=[];for k=1:length(pr),   high_range=[high_range sum(pr(1:k))];endlow_range=[0 high_range(1:length(pr)-1)];prmin=min(pr); symseq=[];for i=1:symlen,    idx=max(find(low_range<=codeword));   codeword=codeword-low_range(idx);   % due to numerical error, sometimes the encoded number    % will be slightly smaller than the current lower bound.   % If this happens, a correction is required.   if abs(codeword-pr(idx))< 0.01*prmin,       idx=idx+1;       codeword=0;   end   symseq=[symseq symbol(idx)],   codeword=codeword/pr(idx),   if abs(codeword)<0.01*prmin,      i=symlen+1;  % break the for loop immediately   endend

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?