arithintcod.m
来自「一个详尽的算术编码的matlab仿真程序。」· M 代码 · 共 74 行
M
74 行
function tag=arithintcod(alpha,cnt,seq)
ls=length(seq);
CC(1)=0;
for i=1:length(cnt)
CC(i+1)=CC(i)+cnt(i);
end
totcount=CC(i+1);
m=ceil(log2(totcount*4));
l=0;
u=2^m-1;
tag='';
scale=0;
for i=1:ls
p=find(seq(i)==alpha);
l1=l+floor(((u-l+1)*CC(p))/totcount);
u=l+floor(((u-l+1)*CC(p+1))/totcount)-1;
l=l1;
lb=dec2bin(l,m);
ub=dec2bin(u,m);
E2=1;E3=1;
while (E2 | E3)
fbl=lb(1);
fbu=ub(1);
if fbl==fbu
E2=1;
tag=strcat(tag,fbl);
lb(1)='';
lb(end+1)='0';
ub(1)='';
ub(end+1)='1';
if fbl=='0'
sc='1';
else
sc='0';
end
while scale>0
tag=strcat(tag,sc);
scale=scale-1;
end
else
E2=0;
end
sbl=lb(2);
sbu=ub(2);
if sbl=='1' & sbu=='0'
lb(1)='';
lb(end+1)='0';
ub(1)='';
ub(end+1)='1';
lb(1)='0';
ub(1)='1';
scale=scale+1;
E3=1;
else
E3=0;
end
end
l=bin2dec(lb);
u=bin2dec(ub);
end
f=lb(1);
lb(1)='';
if f=='0'
sc='1';
else
sc='0';
end
tag=strcat(tag,f);
while scale>0
tag=strcat(tag,sc);
scale=scale-1;
end
tag=strcat(tag,lb);
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?