ardecode.m
资源名称:work.rar [点击查看]
上传用户:hwtw888
上传日期:2016-03-15
资源大小:177k
文件大小:1k
源码类别:
压缩解压
开发平台:
Matlab
- function symseq = ardecode(symbol, pr, codeword, symlen)
- %给定字符概率的算术编码
- %输出:symse:字符串
- %输入:symbol:由字符组成的行向量
- % pr:字符出现的概率
- % codeword:码字
- % symlen:待解码字符串长度
- format long
- high_range = [];
- for k = 1 : length(pr),
- high_range = [high_range sum(pr(1 : k))];
- end
- low_range = [0 high_range(1 : length(pr) - 1)];
- prmin = min(pr);
- symseq = [];
- symseq = [];
- for i = 1 : symlen,
- index = max(find(low_range <= codeword));
- codeword = codeword - low_range(index);
- %duo 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(index)) < 0.01 * prmin,
- index = index + 1;
- codeword = 0;
- end
- symseq = [symseq symbol(index)];
- codeword = codeword/pr(index);
- if abs(codeword) < 0.01 * prmin,
- i = symlen + 1; %break the for loop immediately
- end
- end