姓名:孟云飞学号Y080430 任意信道的信道容量C及最佳输入分布P_X源程序
function [P_X,C,N]=contmax(P_YX,e)
% 计算任意信道的信道容量C及最佳输入分布P_X
% P_X -------输入概率分布
% C----------信道容量N----------迭代次数
% P_YX-----DMC信道的转移矩阵e-----------精度
if length(find(P_YX<0)~=0)
error('Not a probable vector.Negtive component');
end
if abs(sum(P_YX')-1)>10e-10
error('Not a probable vector,Component do not add up to "1" ');
end
% 变量初始化
C1=1;C=0;N=0;
r=size(P_YX);P_X=ones(1,r(1))/r(1);
% 调整P_YX的零元素值
Pyx=(P_YX==0).*eps;P_YX=P_YX+Pyx;
% 迭代求解
while (abs(C1-C))>e
P_Y=P_X*P_YX;
I1=sum((P_YX.*log2(P_YX))');
I2=log2(P_Y)*(P_YX'); BETA=exp(I1-I2);
B=P_X*(BETA');
C1=log(B);C=log(max(BETA));
P_X=P_X.*BETA/B;
N=N+1;
end
P_YX =
0.5000 0.3000 0.2000
0.4000 0.3000 0.3000
0.1000 0.6000 0.4000
>> [P_X,C,N]=contmax(P_YX,0.001)
P_X =
0.3599 0.0023 0.6378
C =
0.1596
N =
40
>> [P_X,C,N]=contmax(P_YX,0.0001)
P_X =
0.3620 0.0002 0.6378
C = 0.1591
N = 58