信息论上机1

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

信息论实验报告班级:通信11-4姓名:李阳学号:11101060427指导教师:范锦宏完成日期:2014.6.82.1程序代码:clearall;closeall;clc;p=0:0.01:1;I=-log2(p+eps);plot(p,I);xlabel('\it{p(x_i)}');ylabel('\it{I(x_i)}','rotation',0,'position',[-0.05,3.5,0]);ylim([0,7]);运行结果:2.2程序代码:clearall;closeall;clc;p=0:0.01:1;q=1-p;H=-p.*log2(p+eps)-q.*log2(q+eps);plot(p,H);xlabel('\it{p}');ylabel('\it{H[p]}','rotation',0,'position',{-0.1,0.5,0]);00.10.20.30.40.50.60.70.80.9101234567p(xi)I(xi)xlim([0,1]);ylim([0,1]);运行结果:3.1(1)程序代码:%画出作为r函数的差错概率图clearall;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('ErrorprobilityversusSNR/bit')ylabel('ErrorProb.')运行结果:00.10.20.30.40.50.60.70.80.91-0.200.20.40.60.81p3.1(2)程序代码:clearall;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('channelcapacityversusSNR/bit')ylabel('channelcapacity')运行结果:10-210-1100101102012345678SNR/bitErrorprobilityversusSNR/bitErrorProb.3-2(1)%W=3000Hz的加性高斯白噪声的信道容量作为P/N0的函数图clearallechoonpn0_db=[-20:0.1:30];pn0=10.^(pn0_db./10);capacity=3000.*log2(1+pn0/3000);pauseclfsemilogx(pn0,capacity)title('Capacityvs.P/N0inanAWGNchannel')xlabel('P/N0')ylabel('Capacity(bits/second)')clearw={1:10,12:2:100,105:5:500;510:10:5000;5025:25:20000,20050:50:100000};pn0_db=25;pn0=10^(pn0_db/10);capacity=w.*log2(1+pn0./w);pauseclf%在AWGN信道中作为带宽的函数的容量semilogx(w,capacity)title('Capacityvs.bandwidthinanAWGNchannel')10-210-1100101102889889.5890890.5891891.5SNR/bitchannelcapacityversusSNR/bitchannelcapacityxlabel('Bandwidth(Hz)')ylabel('Capacity(bits/second)')运行结果:3-2(2)echoon;pn0_db=25pn0=10.^(pn0_db./10);w=0:100000;capacity=w.*log2(1+pn0./w);pause;clfsemilogx(w,capacity);title('capacityvs.P/N0inanAWGNChannel');xlabel('P/N0');ylabel('Capacity(bits/second)');运行结果:10-210-11001011021030200400600800100012001400Capacityvs.P/N0inanAWGNchannelP/N0Capacity(bits/second)3.3%3.3离散无记忆信道的迭代计算%function[cc,paa]=channelcap(p,k)%p:输入的正向转移矩阵,k:迭代计算的精度%cc:最佳信道容量,paa:最佳输入概率矩阵%pa:初始输入概率矩阵,pba:正向转移概率矩阵%pb:输出矩阵概率,pab:反向转移概率矩阵%c:初始信道容量,r:输入符号数,s:输出符号数%提示错误信息if(length(fing(p0))~=0error('notaprob.vector,negetivecomponent')endif(abs(sum(p')-1)10e-10)error('notaprov.vector,componentdonotaddupto1')end[r,s]=size(p);pa=(1/(r+eps))*ones(1,r);sumrow=zeros(1,r);pba=p;n=0;c=0;cc=1;whileabs(cc-c)=kn=n+1;pb=zeros(1,s);forj=1:s100101102103104105050100150200250300350400450500capacityvs.P/N0inanAWGNChannelP/N0Capacity(bits/second)fori=1:rpb(j)=pb(j)+pa(i)*pba(i,j);endendsuma=zeros(1,s);forj=1:sfori=1:rpab(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));endendc=sum(suma);l=zeros(1,r);sumaa=0;fori=1:rforj=1:sl(i)=l(i)+pba(i,j)*log(pab(j,i)+eps);enda(i)=exp(l(i));endsumaa=sum(a);fori=1:rpaa(i)=a(i)/(sumaa+eps);endcc=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.06080.40310.06920.46684-1%function[]=RD(Pa,d,S)formatlongS=[];%r=input('输入信源数r=');%s=input('输出信源数s=');%d=input('失真矩阵d=');%Pa=input('输入概率分布Pa=');r=2s=2d=[01;10]Pa=[0.50.5]S(1)=-99.5times=100;pba=[];RS=[];DS=[];m=1;forz=1:times%初始化Pba(1:r,1:s,1)=1/(r*s)*ones(r,s);forj=1:sPb(j,1)=0;fori=1:rPb(j,1)=Pb(j,1)+Pa(i)*Pba(i,j,1);endendfori=1:rtemp(i)=0;forj=1:stemp(i)=temp(i)+Pb(j,1)*exp(S(m)*d(i,j));endendfori=1:rforj=1:sPba(i,j,2)=(Pb(j,1)*exp(S(m)*d(i,j)))/temp(i);end%计算D(1)(S)和R(1)(S)D(1)=0;fori=1:rforj=1:sD(1)=D(1)+Pa(i)*Pba(i,j,1)*d(i,j);endendR(1)=0;fori=1:rforj=1:sif(Pba(i,j,1)~=0)R(1)=R(1)+Pa(i)*Pba(i,j,1)*log2(Pba(i,j,1)/Pb(j,1));endendendn=2;while(1)%计算pn(bj)forj=1:sPb(j,n)=0;fori=1:rPb(j,n)=Pb(j,n)+Pa(i)*Pba(i,j,n);endend%计算pn+1(bj/ai)fori=1:rtemp(i)=0;forj=1:stemp(i)=temp(i)+Pb(j,n)*exp(S(m)*d(i,j));endendfori=1:rforj=1:sif(temp(i)~=0)Pba(i,j,n+1)=(Pb(j,n)*exp(S(m)*d(i,j)))/temp(i);endendend%计算D(n)(S)和R(n)(S)D(n)=0;fori=1:rforj=1:sD(n)=D(n)+Pa(i)*Pba(i,j,n)*d(i,j);endendR(n)=0;fori=1:rforj=1:sif(Pba(i,j,n)~=0)R(n)=R(n)+Pa(i)*Pba(i,j,n)*log2(Pba(i,j,n)/Pb(j,n));endendendif(abs(R(n)-R(n-1))1e-7)if(abs(D(n)-D(n-1))1e-7)break;endendn=n+1;endS(m+1)=S(m)+0.5;pba=[Pba(:,:,:)];RS=[RSR(n)];DS=[DSD(n)];m=m+1;endend[k,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=0110Pa=0.50000.5000S=-99.5000迭代结果如下:最小信息率Rmin:0最佳转移概率分布Pba:0.73130.26870.26920.73088.1程序代码:clearall;closeall;clc;k=4;fori=1:2^kforj=k:-1:1ifrem(i-1,2^(-j+k+1))=2^(-j+k)u(i,j)=1;elseu(i,j)=0;endendend%定义生成矩阵gg=[1001110111;1110001110;0110110101;1101111001];%生成码字c=rem(u*g,2)%求最小重量w_min=min(sum((c(2:2^k,:))'))运行结果:00.050.10.150.20.250.30.350.40.450.500.10.20.30.40.50.60.70.80.91DR(D)信息率失真函数图象8.2程序代码:function[H,G]=Hamm_gen(m)%H=mxN:奇偶校验矩阵,其中,N=2^m-1%G=KxN:Hamming码的生成矩阵,其中,K=N-mifnargin2,opt=1;endH=[ones(2,1)eye(2)];G=[1H(:,1).'];ifm3,return;endfori=3:mN=2^i;N2=N/2;K=N-1-i;for

1 / 14
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功