使用matlab计算信源熵
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
使用matlab计算信源熵
电信1班杨晓东20131305025
程序
yingyu=textread('yingyu.txt','%s');
s=length(yingyu);
H=zeros(1,s)
for i=1:s
K=yingyu(i);
K=cell2mat(K);
N=zeros(1,26);
for n=1:length(K)
if double(K(n))>96&&double(K(n))<=122
N(1,double(K(n))-96)= N(1,double(K(n)-96))+1;
elseif double(K(n))>64&&double(K(n))<=90
N(1,double(K(n))-64)= N(1,double(K(n)-64))+1;
end
end
P=[0.063,0.0105,0.023,0.035,0.105,0.0221,0.011,0.047,0.055,0.001,0.00 3,0.029,0.021,0.059,0.0644,0.0175,0.001,0.053,0.052,0.071,0.0215,0.00 8,0.012,0.002,0.012,0.001];
I=zeros(1,26);
I=log2(1./P);
H(i)=sum(I.*N)
end
x=1:1:s
plot(x,H)
xlabel('x'), ylabel('y=H(x)')
实验结果
0102030
40506005
10
15
20
2530
35
40
45
x y =H (x )