《信息论上机(共14页).docx》由会员分享,可在线阅读,更多相关《信息论上机(共14页).docx(14页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、精选优质文档-倾情为你奉上信息论实验报告班级:通信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(
2、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(Er
3、ror 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
4、 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
5、/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,capac
6、ity);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(p10e-10) erro
7、r(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)=su
8、ma(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
9、.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
10、: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(
11、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)
12、=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)*log
13、2(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)=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 nargin2, opt=1;endH=ones(2,1) eye(2);G=1 H(:,1).;if m=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列专心-专注-专业