您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 基于MATLAB的CDMA系统仿真
基于MATLAB的CDMA系统仿真姓名:班级:学号:指导老师:日期:作业要求1.分析附录的源程序,逐行给出中文注释,并分析仿真结果。2.按照下列框图设计一个CDMA系统,并进行仿真。1.分析附录的源程序,逐行给出中文注释,并分析仿真结果。信源卷积编码交织编码加扰码扩频调制AWGN信道调制解扩信宿解卷积解交织去扰码%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];%Viterbi生成多项式矩阵K=size(G_Vit,2);%列数L=size(G_Vit,1);%行数%++++++++++++++++++++++++++++++++++++++++++++++++++++++%++++++++++++++++++++++Walsh矩阵++++++++++++++++++++++++WLen=64;%walsh码的长度Walsh=reshape([1;0]*ones(1,WLen/2),WLen,1);%32个10行%Walsh=zeros(WLen,1);%++++++++++++++++++++++++++++++++++++++++++++++++++++++%++++++++++++++++++扩频调制PN码的生成多项式++++++++++++++%Gi=[1010001110100001]';%Gq=[1001110001111001]';Gi_ind=[15,13,9,8,7,5,0]';%i路PN码生成多项式参数Gq_ind=[15,12,11,10,6,5,4,3,0]';%q路PN码生成多项式参数Gi=zeros(16,1);%16×1的0矩阵Gi(16-Gi_ind)=ones(size(Gi_ind));%根据Gi_ind配置i路PN码生成多项式Zi=[zeros(length(Gi)-1,1);1];%I路信道PN码生成器的初始状态Gq=zeros(16,1);%16×1的0矩阵Gq(16-Gq_ind)=ones(size(Gq_ind));%根据Gq_ind配置q路PN码生成多项式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);%43×1的0矩阵Gs(43-Gs_ind)=ones(size(Gs_ind));%根据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:-1.5];%++++++++++++++++++++++++++++++++++++++++++++++++++++++%------------------------------------------------------%-------------------------主程序-------------------------ErrorsB=[];ErrorsC=[];NN=[];if(SD==1)%判断软/硬判决接收fprintf('\nSOFTDecisionViterbiDecoder\n\n');elsefprintf('\nHARDDecisionViterbiDecoder\n\n');endfori=1:length(EbNo)%根据EbNo多次运行fprintf('\nProcessing%1.1f(dB)',EbNo(i));%输出当前EbNo值iter=0;ErrB=0;ErrC=0;while(ErrB300)&(iter150)drawnow;%++++++++++++++++++++++发射机+++++++++++++++++++++++TxData=(randn(N,1)0);%生成源数据%速率为19.2Kcps[TxChips,Scrambler]=PacketBuilder(TxData,G_Vit,Gs);%产生IS-95前向链路系统的发送数据包%速率为1.2288Mcps[xPNMF]=Modulator(TxChips,MFType,Walsh);%实现IS-95前向链路系统的数据调制%++++++++++++++++++++++++++++++++++++++++++++++++++++++%++++++++++++++++++++++++信道+++++++++++++++++++++++++++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');%RAKE接收机输入符号与发送码相比出错的码subplot(313);plot(xor(TxData,RxData),'-o');%硬判决接收机与发送数据相比的出错码title(['DataBitErrors.Metric=',num2str(Metric)]);pause;endif(mod(iter,50)==0)%每50次保存一次fprintf('.');saveTempResultsErrBErrCNiter%保存结果endErrB=ErrB+sum(xor(RxData,TxData));%求出错比特数ErrC=ErrC+sum(xor(RxHD,TxChips));%求出错码数iter=iter+1;%迭代次数endErrorsB=[ErrorsB;ErrB];%存储各EbNo值下的出错比特数ErrorsC=[ErrorsC;ErrC];%存储各EbNo值下的出错码数NN=[NN;N*iter];%存储各EbNo值下的总数据码数目saveSimData*%保存当前迭代的数据end%+++++++++++++++++++++++++误码率计算++++++++++++++++++++++++PerrB=ErrorsB./NN;%出错比特比例%PerrB1=ErrorsB1./NN1;PerrC=ErrorsC./NN;%出错码比例Pbpsk=1/2*erfc(sqrt(10.^(EbNo/10)));%EbNo的余误差PcVit=1/2*erfc(sqrt(10.^((EbNo-EbEcVit)/10)));%EbNo-EbEcVit的余误差Pc=1/2*erfc(sqrt(10.^((EbNo-EbEc)/10)));%EbNo-EbEc的余误差%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%%+++++++++++++++++++++++++性能仿真显示++++++++++++++++++++++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++++++++++++++++++++++++
本文标题:基于MATLAB的CDMA系统仿真
链接地址:https://www.777doc.com/doc-4242578 .html