MATLAB程序-信源编码.docx

MATLAB程序-信源编码.docx

ID:57436129

大小:11.36 KB

页数:4页

时间:2020-08-15

MATLAB程序-信源编码.docx_第1页
MATLAB程序-信源编码.docx_第2页
MATLAB程序-信源编码.docx_第3页
MATLAB程序-信源编码.docx_第4页
资源描述:

《MATLAB程序-信源编码.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、计算信源熵的MATLAB源程序functionH=entropy(P,r)if(length(find(P<=0))~=0)error('Notaprob.vector,negativecomponent');endif(abs(sum(P)-1)>10e-10)error('Notaprob.vector,componentdonotaddupto1');endH=(sum(-P.*log2(P)))/(log2(r)+eps);香农编码的MATLAB源程序function[s,L,q]=shannon(p)%if(length(find(p<=0))~=0)%er

2、ror('Notaprob.vector,negativecomponent');%end%if(abs(sum(p)-1)>10e-10)%error('Notaprob.vector,componentdonotaddupto1')%endn=length(p);x=1:n;[p,x]=array(p,x);l=ceil(-log2(p));P(1)=0;n=length(p);fori=2:nP(i)=P(i-1)+p(i-1);endfori=1:nforj=1:l(i)temp(i,j)=floor(P(i)*2);P(i)=P(i)*2-temp(i,j)

3、;endends=[];fori=1:nforj=1:l(i)t=temp(i,j);%if(temp(i,j)==0)%W(i,j)=48;s=[snum2str(t)];%else%W(i,j)=49;%endends=[s''];endL=sum(p.*l);H=entropy(p,2);q=H/L;fori=1:nB{i}=i;ends0='很好!输入正确,编码结果如下:';s1='Shannon编码所得码字W:';s2='Shannon编码平均码字长度L:';s3='Shannon编码的编码效率q:';disp(s0);disp(s1),disp(B),di

4、sp(s);disp(s2),disp(L);disp(s3),disp(q);费诺编码的MATLAB源程序function[W,L,q]=fano(P)if(length(find(P<=0))~=0)error('Notaprob.vector,negativecomponent');endif(abs(sum(P)-1)>10e-10)error('Notaprob.vector,componentdonotaddupto1');endn=length(P);x=1:n;[P,x]=array(P,x);fori=1:ncurrent_index=i;j=1;c

5、urrent_P=P;while1[next_P,code_num,next_index]=compare(current_P,current_index);current_index=next_index;current_P=next_P;W(i,j)=code_num;j=j+1;if(length(current_P)==1)break;endendl(i)=length(find(abs(W(i,:))~=0));endL=sum(P.*l);H=entropy(P,2);q=H/L;fori=1:nB{i}=i;end[n,m]=size(W);TEMP=3

6、2*ones(n,5);W=[W,TEMP];W=W';[n,m]=size(W);W=reshape(W,1,n*m);W=sprintf('%s',W);s0='很好!输入正确,编码结果如下:';s1='Fano编码所得码字W:';s2='Fano编码平均码字长度L:';s3='Fano编码的编码效率q:';disp(s0);disp(s1),disp(B),disp(W);disp(s2),disp(L);disp(s3),disp(q);霍夫曼编码的MATLAB源程序function[W,L,q]=huffman(P)if(length(find(P<=0))

7、~=0)error('Notaprob.vector,negativecomponent');endif(abs(sum(P)-1)>10e-10)error('Notaprob.vector,componentdonotaddupto1');endn=length(P);p=P;mark=zeros(n-1,n);fori=1:n-1[p,num]=sort(p);mark(i,:)=[num(1:n-i+1),zeros(1,i-1)];p=[p(1)+p(2),p(3:n),1];endfori=1:n-1table(i,:)=blanks(n

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。