您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > matlab直扩仿真代码
1.在AWGN信道下对直扩通信系统进行性能仿真研究%ÐÅÏ¢ÂëƵÂÊÉèΪ100kHz£¬²ÉÑùƵÂÊÉèΪ40MHz£¬Î±Ëæ»úÂëƵÂÊÉèΪ5MHzcloseallclearall%ÐÅÔ´Ä£¿éSNR=[1:1:15]Rb=0.25;%ÂëÔªËÙÂÊ0.25Mb/sTb=1/Rb;%ÂëÔª¼ä¸ôM=100;%ÐÅÏ¢Âë¸öÊýL=400;%ÿ¸öÂëÔªÄڵIJÉÑùµãÊýN=M*L;%×ܲÉÑùµãÊýdt=Tb/L;%ʱÓò²ÉÑù¼ä¸ôdf=1/(N*dt);%ƵÓò²ÉÑù¼ä¸ôBs=N*df/2;%ϵͳ´ø¿íT=N*dt;%½Ø¶Ìʱ¼ät=linspace(-T/2,T/2,N);%ʱÓòºá×ø±êx=sign(rand(1,M)-0.5);%²úÉúË«¼«ÐÔ²»¹éÁãÂët0=linspace(0,T,M);fori=1:100;d((1+(i-1)*400):i*400)=x(i);%ÿ¸öÐÅÏ¢ÂëÔªÄÚº¬400¸ö²ÉÑùµãendfigure(1)plot(t,d)xlabel('t(ms)');ylabel('s(t)(V)');title('ÐÅÔ´');axis([0,200,-1.5,1.5]);gridon%Êý¾Ýµ÷ÖÆÄ£¿éfs=4000;%Ôز¨ÆµÂÊkHzz=reshape(d,2,N/2);%´®²¢±ä»»Q=z(1,:);%sµÄÆæÊýλ,¼´Q(t)I=z(2,:);%sµÄżÊýλ,¼´I(t)tq=linspace(-T/2,T/2,length(I));QPSK=(I.*cos(2*fs*pi*tq)-Q.*sin(2*fs*pi*tq))/sqrt(2);%QPSKµ÷ÖÆfigure(2)plot(tq,QPSK)xlabel('t(ms)');ylabel('QPSK(t)(V)');title('QPSKµ÷ÖÆÐźÅ');axis([0,200,-1.5,1.5]);gridon%À©ÆµÂë²úÉúÄ£¿é%À©ÆµÂë³õÖµÉ趨user=1;%Óû§Êýseq=1;%1£ºmÐòÁÐ2£ºGoldÐòÁÐ3£ºÕý½»GoldÐòÁÐstage=3;%ÐòÁн×Êýptap1=[13];%µÚÒ»¸öÏßÐÔÒÆλ¼Ä´æÆ÷µÄϵÊý£º[13]ptap2=[23];%µÚ¶þ¸öÏßÐÔÒÆλ¼Ä´æÆ÷µÄϵÊý£º[23]regi1=[111];%µÚÒ»¸öÏßÐÔÒÆλ¼Ä´æÆ÷µÄ³õʼ»¯£º[111]regi2=[111];%µÚ¶þ¸öÏßÐÔÒÆλ¼Ä´æÆ÷µÄ³õʼ»¯£º[111]switchseqcase1%mÐòÁÐcode=mseq(stage,ptap1,regi1,user);case2%GoldÐòÁÐm1=mseq(stage,ptap1,regi1);m2=mseq(stage,ptap2,regi2);code=goldseq(m1,m2,user);case3%Õý½»GoldÐòÁÐm1=mseq(stage,ptap1,regi1);m2=mseq(stage,ptap2,regi2);code=[goldseq(m1,m2,user),zeros(user,1)];endxxx=codeclen=length(code);xlength=100*50;%ÿ¸öÐÅÏ¢µ÷ÖÆÂëÄÚº¬50¸öαÂëx_code=zeros(1,xlength);fori=1:xlength%°Ñ0,1ÐòÁÐÂë±ä»»Îª-1,1µ÷ÖÆÂëifmod(i,7)~=0%mod(a,b)¾ÍÊÇÇóµÄÊÇa³ýÒÔbµÄÓàÊýx_code(i)=sign(code(mod(i,7))-0.5);elseifmod(i,7)==0x_code(i)=sign(code(7)-0.5);endendk_code=zeros(1,length(QPSK));fori=1:5000k_code((1+(i-1)*4):i*4)=x_code(i);%ÿ¸öαÂëÂëÔªÄÚº¬4¸ö²ÉÑùµãendfigure(3)plot(tq,k_code)xlabel('t(ms)');ylabel('k_code(t)(V)');title('À©ÆµÂë');axis([20,25,-1.5,1.5]);gridon%À©Æµµ÷ÖÆÄ£¿éb=QPSK.*k_code;%ÉäƵµ÷ÖÆÄ£¿éfc=4e4;%Ôز¨ÆµÂÊkHztd=linspace(0,T,length(b));%bÊÇÀ©Æµµ÷ÖÆÐźš£linspaceÊÇÓÃÀ´Éú³ÉÒ»¸öµÈ²îÊýÁеÄlinÊÇlinearµÄËõдx=linspace(a,b,n)¾ÍÊǽ«Éú³ÉÒ»¸öÒÔaºÍbΪ¶Ïµã¹²»®·ÖΪn¸öÇø¼äµÄÏòÁ¿s=b.*cos(2*fc*pi*td);figure(4)plot(td,s)xlabel('t(ms)');ylabel('s(t)(V)');title('ÉäƵµ÷ÖÆÐźÅ');axis([20,31,-1.5,1.5]);gridon%ÐŵÀÄ£¿ér=awgn(s,SNR(10),'measured');%¸ß˹°×ÔëÉùºóÃæÑ»·ÒÔʵÏÖÎóÂëÂʵÄÊä³ö%ÉäƵ½âµ÷Ä£¿érs=r.*cos(2*fc*pi*td);figure(5)plot(td,rs)xlabel('t(ms)');ylabel('rs(t)(V)');title('ÉäƵ½âµ÷ÐźÅ');axis([20,28,-1.5,1.5]);gridon%½âÀ©Ä£¿éjk_code=rs.*k_code;figure(6)plot(td,jk_code)xlabel('t(ms)');ylabel('rk(t)(V)');title('À©Æµ½âµ÷ÐźÅ');axis([20,33,-1.5,1.5]);gridon[f,rf]=T2F(td,jk_code);%ÉäƵ½âµ÷½ÓÊÕƵÓò[tl,l]=lpf(f,rf,fc/10000);%¾¹ýµÍͨÂ˲¨%½âµ÷Ä£¿éliremod=cos(2*fs*pi*tq)*sqrt(2).*l;%IͨµÀ½âµ÷[fi,lif]=T2F(tq,liremod);[tji,iremod]=lpf(fi,lif,fs/10000);%¾¹ýµÍͨÂ˲¨iremodo=sign(iremod);%²¨ÐÐÕûÐÎlqremod=(-1)*sin(2*fs*pi*tq)*sqrt(2).*l;%QͨµÀ½âµ÷[fq,lqf]=T2F(tq,lqremod);[tjq,qremod]=lpf(fq,lqf,fs/10000);%¾¹ýµÍͨÂ˲¨qremodo=sign(qremod);%²¨ÐÎÕûÐÎzl=[qremodo,iremodo];%²¢´®±ä»»figure(7)plot(t,zl)xlabel('t(ms)');ylabel('zl(t)(V)');title('½âµ÷ºóµÄÊä³öÐźÅ');axis([0,200,-1.5,1.5]);gridonz2=0;xo=zeros(size(x));fori=1:100z2=0forj=1+(i-1)*400:i*400z2=z2+zl(j);endifz2=0xo(i)=1;elsexo(i)=-1;endendfigure(8)plot(t0,xo)xlabel('t(ms)');ylabel('xo(t)(V)');title('Êä³öÐźÅ');axis([0,400,-1.5,1.5]);gridonfora=1:15r=awgn(s,SNR(a),'measured');;%¸Ä¶¯rs=r.*cos(2*fc*pi*td);jk_code=rs.*k_code;[f,rf]=T2F(td,jk_code);%ÉäƵ½âµ÷½ÓÊÕƵÓò[tl,l]=lpf(f,rf,fc/10000);%¾¹ýµÍͨÂ˲¨liremod=cos(2*fs*pi*tq)*sqrt(2).*l;%IͨµÀ½âµ÷[fi,lif]=T2F(tq,liremod);[tji,iremod]=lpf(fi,lif,fs/10000);%¾¹ýµÍͨÂ˲¨iremodo=sign(iremod);%²¨ÐÐÕûÐÎlqremod=(-1)*sin(2*fs*pi*tq)*sqrt(2).*l;%QͨµÀ½âµ÷[fq,lqf]=T2F(tq,lqremod);[tjq,qremod]=lpf(fq,lqf,fs/10000);%¾¹ýµÍͨÂ˲¨qremodo=sign(qremod);%²¨ÐÎÕûÐÎzl=[qremodo,iremodo];%²¢´®±ä»»z2=0;xo=zeros(size(x));fori=1:100z2=0forj=1+(i-1)*400:i*400z2=z2+zl(j);endifz2=0xo(i)=1;elsexo(i)=-1;endendz=0;fori=1:100if(x(i)~=xo(i))z=z+1;endendz1(a)=z/100endfigure(8)plot(SNR,z1)xlabel('SNR');ylabel('z1');title('ÎóÂëÂÊ');axis([0,15,10^(-4),1]);gridon1.ifuser==12.ich4=ich3;3.qch4=qch3;4.else5.ich4=sum(ich3);6.qch4=sum(qch3);7.end8.%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++9.10.%+++++++++++++++++++++++衰减信道++++++++++++++++++++++++++11.ifrfade==012.ich5=ich4;13.qch5=qch4;14.else15.[ich5,qch5]=sefade(ich4,qch4,itau,dlvl1,th1,n0,itnd1,…16.now1,length(ich4),tstp,fd,flat);17.itnd1itnd1=itnd1+itndel;18.end19.%+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++20.21.%+++++++++++++++++++++++++接收机++++++++++++++++++++++++++++22.spow=sum(rot90(ich3.^2+qch3.^2))/nd;%衰减计算23.attn=sqrt(0.5*spow*sr/br*10^(-ebn0/10));24.25.[ich6,qch6]=comb2(ich5,qch5,attn);%添加高斯白噪声(AWGN)26.[ich7,qch7]=compconv2(ich6,qch6,xh2);%滤波27.28.sampl=irfn*IPOINT+1;29.ich8=ich7(:,sampl:IPOINT:IPOINT*nd*clen+sampl-1);30.qch8=qch7(:,sampl:IPOINT:IPOINT*nd*clen+sampl-1);31.32.[ich9qch9]=despread(ich8,qch8,code);%解扩33.34.demodata=qpskdemod(ich9,qch9,user,nd,ml
本文标题:matlab直扩仿真代码
链接地址:https://www.777doc.com/doc-3232830 .html