CDMA系统仿真%main_IS95_forward.m%此函数用于IS-95前向链路系统的仿真,包括扩%频调制,匹配滤波,RAKE接收等相关通信模块。%仿真环境:加性高斯白噪声信道.%数据速率=9600KBps%clearallcloseallclcdisp('--------------start-------------------');globalZiZqZsshowRGiGqclearj;show=0;SD=0;%选择软/硬判决接收%-------------------主要的仿真参数设置------------------BitRate=9600;ChipRate=1228800;N=184;MFType=1;%匹配滤波器类型--升余弦R=5;%+++++++++++++++++++Viterbi生成多项式++++++++++++++++++G_Vit=[111101011;101110001];K=size(G_Vit,2);L=size(G_Vit,1);%++++++++++++++++++++++++++++++++++++++++++++++++++++++%++++++++++++++++++++++Walsh矩阵++++++++++++++++++++++++WLen=64;Walsh=reshape([1;0]*ones(1,WLen/2),WLen,1);信源卷积编码交织编码加扰码扩频调制AWGN信道调制解扩信宿解卷积解交织去扰码%Walsh=zeros(WLen,1);%++++++++++++++++++++++++++++++++++++++++++++++++++++++%++++++++++++++++++扩频调制PN码的生成多项式++++++++++++++%Gi=[1010001110100001]';%Gq=[1001110001111001]';Gi_ind=[15,13,9,8,7,5,0]';Gq_ind=[15,12,11,10,6,5,4,3,0]';Gi=zeros(16,1);Gi(16-Gi_ind)=ones(size(Gi_ind));Zi=[zeros(length(Gi)-1,1);1];%I路信道PN码生成器的初始状态Gq=zeros(16,1);Gq(16-Gq_ind)=ones(size(Gq_ind));Zq=[zeros(length(Gq)-1,1);1];%Q路信道PN码生成器的初始状态%++++++++++++++++++++++++++++++++++++++++++++++++++++++%+++++++++++++++++++扰码生成多项式++++++++++++++++++++++Gs_ind=[42,35,33,31,27,26,25,22,21,19,18,17,16,10,7,6,5,3,2,1,0]';Gs=zeros(43,1);Gs(43-Gs_ind)=ones(size(Gs_ind));Zs=[zeros(length(Gs)-1,1);1];%长序列生成器的初始状态%++++++++++++++++++++++++++++++++++++++++++++++++++++++%++++++++++++++++++++++AWGN信道++++++++++++++++++++++++EbEc=10*log10(ChipRate/BitRate);EbEcVit=10*log10(L);EbNo=[-2:0.5:6.5];%仿真信噪比范围(dB)%EbNo=[2:0.5:2.5];%++++++++++++++++++++++++++++++++++++++++++++++++++++++%------------------------------------------------------%-------------------------主程序-------------------------ErrorsB=[];ErrorsC=[];NN=[];if(SD==1)fprintf('\nSOFTDecisionViterbiDecoder\n\n');elsefprintf('\nHARDDecisionViterbiDecoder\n\n');endfori=1:length(EbNo)fprintf('\nProcessing%1.1f(dB)',EbNo(i));iter=0;ErrB=0;ErrC=0;while(ErrB300)&(iter150)drawnow;%++++++++++++++++++++++发射机+++++++++++++++++++++++TxData=(randn(N,1)0);%速率为19.2Kcps[TxChips,Scrambler]=PacketBuilder(TxData,G_Vit,Gs);%速率为1.2288Mcps[xPNMF]=Modulator(TxChips,MFType,Walsh);%++++++++++++++++++++++++++++++++++++++++++++++++++++++%++++++++++++++++++++++++信道+++++++++++++++++++++++++++noise=1/sqrt(2)*sqrt(R/2)*(randn(size(x))+j*randn(size(x)))*10^(-(EbNo(i)-EbEc)/20);r=x+noise;%++++++++++++++++++++++++++++++++++++++++++++++++++++++%+++++++++++++++++++++++++接收机++++++++++++++++++++++++RxSD=Demodulator(r,PN,MF,Walsh);%软判决,速率为19.2KcpsRxHD=(RxSD0);%定义接收码片的硬判决if(SD)[RxDataMetric]=ReceiverSD(RxSD,G_Vit,Scrambler);%软判决else[RxDataMetric]=ReceiverHD(RxHD,G_Vit,Scrambler);%硬判决end%++++++++++++++++++++++++++++++++++++++++++++++++++++++if(show)subplot(311);plot(RxSD,'-o');title('SoftDecisions');subplot(312);plot(xor(TxChips,RxHD),'-o');title('ChipErrors');subplot(313);plot(xor(TxData,RxData),'-o');title(['DataBitErrors.Metric=',num2str(Metric)]);pause;endif(mod(iter,50)==0)fprintf('.');saveTempResultsErrBErrCNiterendErrB=ErrB+sum(xor(RxData,TxData));ErrC=ErrC+sum(xor(RxHD,TxChips));iter=iter+1;endErrorsB=[ErrorsB;ErrB];ErrorsC=[ErrorsC;ErrC];NN=[NN;N*iter];saveSimData*end%+++++++++++++++++++++++++误码率计算++++++++++++++++++++++++PerrB=ErrorsB./NN;%PerrB1=ErrorsB1./NN1;PerrC=ErrorsC./NN;Pbpsk=1/2*erfc(sqrt(10.^(EbNo/10)));PcVit=1/2*erfc(sqrt(10.^((EbNo-EbEcVit)/10)));Pc=1/2*erfc(sqrt(10.^((EbNo-EbEc)/10)));%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%%+++++++++++++++++++++++++性能仿真显示++++++++++++++++++++++figure;semilogy(EbNo(1:length(PerrB)),PerrB,'b-*');holdon;%%semilogy(EbNo(1:length(PerrB1)),PerrB1,'k-o');holdon;%semilogy(EbNo(1:length(PerrC)),PerrC,'b-o');gridon;%semilogy(EbNo,Pbpsk,'b-.^');%%semilogy(EbNo,PcVit,'k-.x');ylabel('BER');%semilogy(EbNo,Pc,'b-.x');xlabel('信噪比/dB');ylabel('误码率');gridon;%legend('PbofSystem(HD)','PbofSystem(SD)','PcbeforeViterbiofSystem',%...'PbofBPSKwithnoViterbi(theory)','PconReceiver(theory)');%%%%legend('PbofSystem','PcbeforeViterbiofSystem',...%'PbofBPSKwithnoViterbi(theory)',%'PcbeforeViterbi(theory)','PconReceiver(theory)');%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++disp('--------------end-------------------');%------------------------------------------------------%************************beginningoffile*****************************%PacketBuilder.mfunction[ChipsOut,Scrambler]=PacketBuilder(DataBits,G,Gs);%%此函数用于产生IS-95前向链路系统的发送数据包%+++++++++++++++++++++++variables++++++++++++++++++++++++++++%DataBits发送数据(二进制形式)%GViterbi编码生成多项式%Gs长序列生成多项式(扰码生成多项式)%ChipsOut输入到调制器的码序列(二进制形式)%Scrambler扰码%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++globalZsK=size(G,2);L=size(G,1);N=64*L*(length(DataBits)+K-1);%码片数(9.6Kbps-1.288Mbps)chips=VitEnc(G,[DataBits;zeros(K-1,1)]);%Viterbi编码%交织编码INTERL=reshape(chips,24,16);%IN:列,OUT:行chips=reshape(INTERL',length(chips),1);%速率=19.2KBps%产生扰码[LongSeqZs]=PNGen(Gs,Zs,N);Scrambler=LongSeq(1:64:end);ChipsOut=xor(chips,Scrambler);%************************endoffile***********************************%************************beg