赞
踩
clear all
format long
symbol='abcd';
pr=[0.1 0.4 0.2 0.3];
seqin='aabccddcd';
codeword=arenc(symbol,pr,seqin);
function arcode=arenc(symbol,pr,seqin)
%算术编码
%输出:码串
%输入:symbol:字符行向量
%pr:字符出现的概率
%seqin:代编码字符串
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)]
sbidx=zeros(size(seqin))
for i=1:length(seqin)
sbidx(i)=find(symbol==seqin(i))
end
low=0
high=1
for i=1:length(seqin),
range=high-low
high=low+range*high_range(sbidx(i));
low=low+range*low_range(sbidx(i));
end
arcode=low;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。