登录后复制
clear; close all; clc; EbN0=0:10; %信噪比 nsymbol=1000000; %随机信号长度M=2;L=7; %约束长度 k=log2(M); %每个字符的bit数tblen=6*L; %维特比算法回溯长度rate=1/2; %1/2码率trellis=poly2trellis(L,[133,171]); %生成卷积码网格表commcnv_plotnextstates(trellis.nextStates);%卷积码网格表可视化data=randi([0,1],1,nsymbol); %消息源data1=convenc(data,trellis); %卷积编码tx=pskmod(data1,M); %2PSK调制parfor i=1:length(EbN0) snrdB = EbN0(i) + 10*log10(k*rate); %SNR与Eb/N0的转换 rx=awgn(tx,snrdB,'measured'); data_out=pskdemod(rx,M); %2PSK解调 hard=vitdec(data_out,trellis,tblen,'cont','hard'); %硬判决,硬判决使用的汉明距离丢失了更多信息 soft=vitdec(real(rx),trellis,tblen,'cont','unquant'); %软判决,使用几何距离 end%维特比算法类似于寻求最短路径errbN=berawgn(EbN0,'psk',2,'nodiff'); %不使用卷积码的2PSK误码率figure()semilogy(EbN0,errbH,'-*');hold on;semilogy(EbN0,errbS,'-x');hold on;semilogy(EbN0,errbN,'-');legend('硬判决译码误码率','软判决译码误码率','不使用卷积码误码率');title('BPSK调制在AWGN信道下卷积码的性能');grid onxlabel('Eb/N0');ylabel('BER');function commcnv_plotnextstates(nextStates)% Utility function to display nextStates matrix for Convolutional Encoder% with Uncoded Bits and Feedback example. To open the model, type% commcnvencoder.% Copyright 2003-2011 The MathWorks, Inc.% $Revision: 1.1.6.2 $ $Date: 2011/12/11 07:38:29 $%-- Create a new figure to plot NextStatesfigure;%-- Declare and initialize intermediate variables[numStates,numIn] = size(nextStates); yplot = NaN*ones(3*numIn,numStates);yplot([1:3:end],:) = ones(numIn,1)*[0:numStates-1];yplot([2:3:end],:) = nextStates';xplot = repmat([1 numStates NaN]',numIn,numStates);%-- Plot NextStates matrixplot(xplot,yplot,'o-','MarkerSize',6,'MarkerEdgeColor','k','MarkerFaceColor','k');grid on; title('Plot of {\itNextStates} Matrix');xlabel('State Transition'); set(gca,'yTick',[0:numStates-1],'YDir','Reverse',... 'YTickLabel',...[dec2base([0:numStates-1],2) repmat('/',numStates,1) dec2base([0:numStates-1],8)], ... 'YLim', [-1 numStates], 'Xlim',[0 numStates+1],'xTick',[1 numStates], ... 'xTickLabel','N|N+1','Position',[.11 .1 .78 .8]);ylabel('Initial State (Binary/Octal representation)',... 'HorizontalAlignment','center','VerticalAlignment','Bottom');1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.
2014a
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删