数据压缩 第四次作业
生活随笔
收集整理的這篇文章主要介紹了
数据压缩 第四次作业
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
5.給定如表4-9所示的概率模型,求出序列a1a1a3a2a3a1的實(shí)值標(biāo)簽。
算術(shù)編碼代碼
clc,clear all; symbol=['abc']; %輸入一串序列 pr=[0.2 0.3 0.5]; %各字符出現(xiàn)的概率 temp=[0.0 0.2 0.5 1.0]; %各字符的累積概率 orignal=temp; in=input('input a string of abc:'); n=length(in); %編碼 for i=1:n width=temp(4)-temp(1); w=temp(1); switch in(i) case 'a' m=1; case 'b' m=2; case 'c' m=3; otherwise error('do not input other character'); end temp(1)=w+orignal(m)*width; temp(4)=w+orignal(m+1)*width; left=temp(1); right=temp(4); fprintf('left=%.6f',left); fprintf(' '); fprintf('right=%.6f\n',right); end encode=(temp(1)+temp(4))/2結(jié)果:
input a string of abc:'aacbca' left=0.000000 right=0.200000 left=0.000000 right=0.040000 left=0.020000 right=0.040000 left=0.024000 right=0.030000 left=0.027000 right=0.030000 left=0.027000 right=0.027600encode =0.0273結(jié)論:? a1a1a3a2a3a1的實(shí)值標(biāo)簽為 0.0273
?
6.對(duì)于表4-9給出的概率模型,對(duì)于一個(gè)標(biāo)簽為0.63215699的長(zhǎng)度為10的序列進(jìn)行解碼。
算術(shù)解碼代碼:
encode=0.63215699; %序列標(biāo)簽 n=10; %序列長(zhǎng)度 pr=[0.2 0.3 0.5]; %各字符出現(xiàn)的概率 temp=[0.0 0.2 0.5 1.0]; %各字符的累積概率 orignal=temp; decode=['0']; for i=1:n fprintf('tmp=%.6f\n',encode); if(encode>=orignal(1)& encode<orignal(2)) decode(i)='a'; t=1; elseif(encode>=orignal(2)& encode<orignal(3)) decode(i)='b'; t=2; else decode(i)='c'; t=3; end encode=(encode-orignal(t)); encode=encode/pr(t); end decode結(jié)果:
tmp=0.632157 tmp=0.264314 tmp=0.214380 tmp=0.047933 tmp=0.239666 tmp=0.132219 tmp=0.661093 tmp=0.322185 tmp=0.407284 tmp=0.690947decode =cbbabacbbc結(jié)論:? 標(biāo)簽為0.63215699的長(zhǎng)度為10的序列為? a3a2a2a1a2a1a3a2a2a3
轉(zhuǎn)載于:https://www.cnblogs.com/rwg-xs/p/6033579.html
總結(jié)
以上是生活随笔為你收集整理的数据压缩 第四次作业的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: JAVA学习笔记-“Hello Worl
- 下一篇: 模拟赛1031d1