信息论上机(共14页).docx
精选优质文档-倾情为你奉上信息论实验报告班级:通信11-4姓名:李阳 学号: 指导教师:范锦宏 完成日期:2014.6.82.1程序代码:clear all;close all;clc;p = 0:0.01:1;I = -log2(p + eps);plot(p,I);xlabel('itp(x_i)');ylabel('itI(x_i)','rotation',0,'position',-0.05,3.5,0);ylim(0,7);运行结果:2.2程序代码:clear all;close all;clc;p = 0:0.01:1;q = 1-p;H = -p.*log2(p + eps) - q.*log2(q + eps);plot(p,H);xlabel('itp');ylabel('itHp','rotation',0,'position',-0.1,0.5,0);xlim(0,1);ylim(0,1);运行结果:3.1(1)程序代码:%画出作为r函数的差错概率图clear all;gamma_db = -20:0.1:20;gamma = 10.(gamma_db ./10);p_error = 0.5.*(sqrt(2 .*gamma);semilogx(gamma,p_error)xlabel('SNR/bit')title('Error probility versus SNR/bit')ylabel('Error Prob.')运行结果:3.1(2)程序代码:clear all;gamma_db=-20:0.1:20;gamma=10.(gamma_db./10);p_error=0.5.*(sqrt(2.*gamma);capacity=1.-sum(-p_error.*log2(p_error);semilogx(gamma,capacity)xlabel('SNR/bit')title('channel capacity versus SNR/bit')ylabel('channel capacity')运行结果:3-2(1)%W=3000Hz 的加性高斯白噪声的信道容量作为P/ N0的函数图clear allecho onpn0_db = -20:0.1:30;pn0 = 10 .(pn0_db./10);capacity = 3000 .* log2(1+pn0/3000);pauseclfsemilogx( pn0,capacity)title('Capacity vs.P/N0 in an AWGN channel')xlabel('P/N0')ylabel('Capacity (bits/second)')clearw = 1:10,12:2:100,105:5:500;510:10:5000;5025:25:20000,20050:50:;pn0_db = 25;pn0 = 10(pn0_db/10);capacity = w.*log2(1 + pn0./w);pauseclf%在AWGN信道中作为带宽的函数的容量semilogx(w,capacity)title('Capacity vs. bandwidth in an AWGN channel')xlabel('Bandwidth (Hz)')ylabel('Capacity (bits/second)')运行结果:3-2(2)echo on;pn0_db = 25pn0 = 10 .(pn0_db ./10);w = 0:;capacity = w .*log2(1 + pn0 ./w);pause;clfsemilogx(w,capacity);title('capacity vs. P/N0 in an AWGN Channel');xlabel('P/N0');ylabel('Capacity (bits/second)');运行结果:3.3%3.3离散无记忆信道的迭代计算%functioncc,paa=channelcap(p,k)%p:输入的正向转移矩阵,k:迭代计算的精度%cc:最佳信道容量,paa:最佳输入概率矩阵%pa:初始输入概率矩阵,pba:正向转移概率矩阵%pb:输出矩阵概率,pab:反向转移概率矩阵%c:初始信道容量,r:输入符号数,s:输出符号数%提示错误信息if(length(fing(p<0)=0 error('not a prob.vector,negetive component')endif(abs(sum(p')-1)>10e-10) error('not a prov.vector, component do not add up to 1')endr,s=size(p);pa=(1/(r+eps)*ones(1,r);sumrow=zeros(1,r);pba=p;n=0;c=0;cc=1;while abs(cc-c)>=k n=n+1; pb=zeros(1,s); for j=1:s for i=1:r pb(j)=pb(j)+pa(i)*pba(i,j); end end suma=zeros(1,s); for j=1:s for i=1:r pab(j,i)*pba(i,j)/(pb(j)+eps); suma(j)=suma(j)+pa(i)*pba(i,j)*log2(pab(j,i)+eps)/(pa(i)+eps); end end c=sum(suma); l=zeros(1,r); sumaa=0; for i=1:r for j=1:s l(i)=l(i)+pba(i,j)*log(pab(j,i)+eps); end a(i)=exp(l(i); end sumaa=sum(a); for i=1:r paa(i)=a(i)/(sumaa+eps); end cc=log2(sumaa); pa=paa;end运行结果:输入:p=0.2,0.3,0.5;0.6,0.2,0.2;0.5,0.2,0.3;0.1,0.3,0.6; k=10e-4;a,b=channelcap(p,k)输出:a = 0.2057b = 0.0608 0.4031 0.0692 0.46684-1%function=RD(Pa,d,S) format long S=;%r=input('输入信源数 r=');%s=input('输出信源数 s='); %d=input('失真矩阵 d='); %Pa=input('输入概率分布 Pa=');r=2 s=2 d=0 1;1 0 Pa=0.5 0.5S(1)=-99.5 times=100; pba=; RS=; DS=; m=1;for z=1:times %初始化 Pba(1:r,1:s,1)=1/(r*s)*ones(r,s); for j=1:s Pb(j,1)=0; for i=1:r Pb(j,1)=Pb(j,1)+Pa(i)*Pba(i,j,1); end end for i=1:r temp(i)=0; for j=1:s temp(i)=temp(i)+Pb(j,1)*exp(S(m)*d(i,j); end end for i=1:r for j=1:s Pba(i,j,2)=(Pb(j,1)*exp(S(m)*d(i,j)/temp(i); end %计算D(1)(S)和R(1)(S) D(1)=0; for i=1:r for j=1:s D(1)=D(1)+Pa(i)*Pba(i,j,1)*d(i,j); end end R(1)=0; for i=1:r for j=1:s if(Pba(i,j,1)=0) R(1)=R(1)+Pa(i)*Pba(i,j,1)*log2(Pba(i,j,1)/Pb(j,1); end end end n=2; while(1) %计算pn(bj) for j=1:s Pb(j,n)=0; for i=1:r Pb(j,n)=Pb(j,n)+Pa(i)*Pba(i,j,n); end end %计算pn+1(bj/ai) for i=1:r temp(i)=0; for j=1:s temp(i)=temp(i)+Pb(j,n)*exp(S(m)*d(i,j); end end for i=1:r for j=1:s if(temp(i)=0) Pba(i,j,n+1)=(Pb(j,n)*exp(S(m)*d(i,j)/temp(i); end end end %计算D(n)(S)和R(n)(S) D(n)=0; for i=1:r for j=1:s D(n)=D(n)+Pa(i)*Pba(i,j,n)*d(i,j); end end R(n)=0; for i=1:r for j=1:s if(Pba(i,j,n)=0) R(n)=R(n)+Pa(i)*Pba(i,j,n)*log2(Pba(i,j,n)/Pb(j,n); end end end if(abs(R(n)-R(n-1)<1e-7) if(abs(D(n)-D(n-1)<1e-7) break; end end n=n+1; end S(m+1)=S(m)+0.5; pba=Pba(:,:,:); RS=RS R(n); DS=DS D(n); m=m+1; endendk,l,q=size(pba);Pba=pba(:,:,q); Rmin=min(RS);Dmax=max(DS); Smax=S(m-1); fprintf(2,'迭代结果如下:n'); fprintf(2,'最小信息率 Rmin :n');disp(Rmin); fprintf(2,'最佳转移概率分布 Pba :n'); disp(Pba); plot(DS,RS); xlabel('D'); ylabel('R(D)'); title('信息率失真函数图象')运行结果:r = 2s = 2d = 0 1 1 0Pa = 0.5000 0.5000S = -99.5000迭代结果如下:最小信息率 Rmin : 0最佳转移概率分布 Pba : 0.7313 0.26870.2692 0.73088.1程序代码:clear all;close all;clc;k=4;for i=1:2k for j=k:-1:1 if rem(i-1,2(-j+k+1)>=2(-j+k) u(i,j)=1; else u(i,j)=0; end endend%定义生成矩阵gg=1 0 0 1 1 1 0 1 1 1; 1 1 1 0 0 0 1 1 1 0; 0 1 1 0 1 1 0 1 0 1; 1 1 0 1 1 1 1 0 0 1;%生成码字c=rem(u*g,2)%求最小重量w_min=min(sum(c(2:2k,:)')运行结果: 8.2程序代码:function H,G=Hamm_gen(m)%H=mxN:奇偶校验矩阵,其中,N=2m-1%G=KxN:Hamming码的生成矩阵,其中,K=N-mif nargin<2, opt=1;endH=ones(2,1) eye(2);G=1 H(:,1).'if m<3, return;endfor i=3:m N=2i; N2=N/2; K=N-1-i; for j=1:N2-1, H(i,j)=1; end for j=N2:K, H(i,j)=0; end H(1:i-1,N2:K)= H(1:i-1,1:N2-i); H(1:i,N-i:N-1)=eye(i);endH(:,1:K)=fliplr(H(:,1:K);G=eye(K) H(1:m,1:K).'运行结果:输入:m=4;H,G=Hamm_gen(m)输出:8.3程序代码:clear all;k=11;for i=1:2k for j=k:-1:1 if rem(i-1,2(-j+k+1)>=2(-j+k) u(i,j)=1; else u(i,j)=0; end endendH, G=hamm_gen(4);c=rem(u*G,2)w_min=min(sum(c(2:2k,:)')运行结果:(15,11)的Hamming码的全部码字较多,共2048行15列专心-专注-专业