[键入文字][键入文字]QPSK调制与解调在MATLAB平台上的实现QPSK即四进制移向键控(QuaternaryPhaseShiftKeying),它利用载波的四种不同相位来表示数字信息,由于每一种载波相位代表两个比特信息,因此每个四进制码元可以用两个二进制码元的组合来表示。两个二进制码元中的前一个码元用a表示,后一个码元用b表示。QPSK信号可以看作两个载波正交2PSK信号的合成,下图表示QPSK正交调制器。由QPSK信号的调制可知,对它的解调可以采用与2PSK信号类似的解调方法进行解调。解调原理图如下所示,同相支路和正交支路分别采用相干解调方式解调,得到()It和()Qt,经过抽样判决和并/串交换器,将上下支路得到的并行数据恢复成串行数据。%调相法clearall[键入文字][键入文字]closeallt=[-1:0.01:7-0.01];tt=length(t);x1=ones(1,800);fori=1:ttif(t(i)=-1&t(i)=1)|(t(i)=5&t(i)=7);x1(i)=1;elsex1(i)=-1;endendt1=[0:0.01:8-0.01];t2=0:0.01:7-0.01;t3=-1:0.01:7.1-0.01;t4=0:0.01:8.1-0.01;tt1=length(t1);x2=ones(1,800);fori=1:tt1if(t1(i)=0&t1(i)=2)|(t1(i)=4&t1(i)=8);x2(i)=1;elsex2(i)=-1;endendf=0:0.1:1;xrc=0.5+0.5*cos(pi*f);y1=conv(x1,xrc)/5.5;y2=conv(x2,xrc)/5.5;n0=randn(size(t2));f1=1;i=x1.*cos(2*pi*f1*t);q=x2.*sin(2*pi*f1*t1);I=i(101:800);Q=q(1:700);QPSK=sqrt(1/2).*I+sqrt(1/2).*Q;QPSK_n=(sqrt(1/2).*I+sqrt(1/2).*Q)+n0;[键入文字][键入文字]n1=randn(size(t2));i_rc=y1.*cos(2*pi*f1*t3);q_rc=y2.*sin(2*pi*f1*t4);I_rc=i_rc(101:800);Q_rc=q_rc(1:700);QPSK_rc=(sqrt(1/2).*I_rc+sqrt(1/2).*Q_rc);QPSK_rc_n1=QPSK_rc+n1;figure(1)subplot(4,1,1);plot(t3,i_rc);axis([-18-11]);ylabel('a序列');subplot(4,1,2);plot(t4,q_rc);axis([-18-11]);ylabel('b序列');subplot(4,1,3);plot(t2,QPSK_rc);axis([-18-11]);ylabel('合成序列');subplot(4,1,4);plot(t2,QPSK_rc_n1);axis([-18-11]);ylabel('加入噪声');效果图:%设定T=1,加入高斯噪声clearall[键入文字][键入文字]closeall%调制bit_in=randint(1e3,1,[01]);bit_I=bit_in(1:2:1e3);bit_Q=bit_in(2:2:1e3);data_I=-2*bit_I+1;data_Q=-2*bit_Q+1;data_I1=repmat(data_I',20,1);data_Q1=repmat(data_Q',20,1);fori=1:1e4data_I2(i)=data_I1(i);data_Q2(i)=data_Q1(i);end;f=0:0.1:1;xrc=0.5+0.5*cos(pi*f);data_I2_rc=conv(data_I2,xrc)/5.5;data_Q2_rc=conv(data_Q2,xrc)/5.5;f1=1;t1=0:0.1:1e3+0.9;n0=rand(size(t1));I_rc=data_I2_rc.*cos(2*pi*f1*t1);Q_rc=data_Q2_rc.*sin(2*pi*f1*t1);QPSK_rc=(sqrt(1/2).*I_rc+sqrt(1/2).*Q_rc);QPSK_rc_n0=QPSK_rc+n0;%解调I_demo=QPSK_rc_n0.*cos(2*pi*f1*t1);Q_demo=QPSK_rc_n0.*sin(2*pi*f1*t1);%低通滤波I_recover=conv(I_demo,xrc);Q_recover=conv(Q_demo,xrc);I=I_recover(11:10010);Q=Q_recover(11:10010);[键入文字][键入文字]t2=0:0.05:1e3-0.05;t3=0:0.1:1e3-0.1;%抽样判决data_recover=[];fori=1:20:10000data_recover=[data_recoverI(i:1:i+19)Q(i:1:i+19)];end;bit_recover=[];fori=1:20:20000ifsum(data_recover(i:i+19))0data_recover_a(i:i+19)=1;bit_recover=[bit_recover1];elsedata_recover_a(i:i+19)=-1;bit_recover=[bit_recover-1];endenderror=0;dd=-2*bit_in+1;ddd=[dd'];ddd1=repmat(ddd,20,1);fori=1:2e4ddd2(i)=ddd1(i);endfori=1:1e3ifbit_recover(i)~=ddd(i)error=error+1;endendp=error/1000;figure(1)subplot(2,1,1);plot(t2,ddd2);axis([0100-22]);title('原序列');subplot(2,1,2);plot(t2,data_recover_a);axis([0100-22]);title('解调后序列');效果图:[键入文字][键入文字]%设定T=1,不加噪声clearall[键入文字][键入文字]closeall%调制bit_in=randint(1e3,1,[01]);bit_I=bit_in(1:2:1e3);bit_Q=bit_in(2:2:1e3);data_I=-2*bit_I+1;data_Q=-2*bit_Q+1;data_I1=repmat(data_I',20,1);data_Q1=repmat(data_Q',20,1);fori=1:1e4data_I2(i)=data_I1(i);data_Q2(i)=data_Q1(i);end;t=0:0.1:1e3-0.1;f=0:0.1:1;xrc=0.5+0.5*cos(pi*f);data_I2_rc=conv(data_I2,xrc)/5.5;data_Q2_rc=conv(data_Q2,xrc)/5.5;f1=1;t1=0:0.1:1e3+0.9;I_rc=data_I2_rc.*cos(2*pi*f1*t1);Q_rc=data_Q2_rc.*sin(2*pi*f1*t1);QPSK_rc=(sqrt(1/2).*I_rc+sqrt(1/2).*Q_rc);%解调I_demo=QPSK_rc.*cos(2*pi*f1*t1);Q_demo=QPSK_rc.*sin(2*pi*f1*t1);I_recover=conv(I_demo,xrc);Q_recover=conv(Q_demo,xrc);I=I_recover(11:10010);Q=Q_recover(11:10010);t2=0:0.05:1e3-0.05;t3=0:0.1:1e3-0.1;[键入文字][键入文字]data_recover=[];fori=1:20:10000data_recover=[data_recoverI(i:1:i+19)Q(i:1:i+19)];end;ddd=-2*bit_in+1;ddd1=repmat(ddd',10,1);fori=1:1e4ddd2(i)=ddd1(i);endfigure(1)subplot(4,1,1);plot(t3,I);axis([020-66]);subplot(4,1,2);plot(t3,Q);axis([020-66]);subplot(4,1,3);plot(t2,data_recover);axis([020-66]);subplot(4,1,4);plot(t,ddd2);axis([020-66]);效果图:%QPSK误码率分析SNRindB1=0:2:10;[键入文字][键入文字]SNRindB2=0:0.1:10;fori=1:length(SNRindB1)[pb,ps]=cm_sm32(SNRindB1(i));smld_bit_err_prb(i)=pb;smld_symbol_err_prb(i)=ps;end;fori=1:length(SNRindB2)SNR=exp(SNRindB2(i)*log(10)/10);theo_err_prb(i)=Qfunct(sqrt(2*SNR));end;title('QPSK误码率分析');semilogy(SNRindB1,smld_bit_err_prb,'*');axis([01010e-81]);holdon;%semilogy(SNRindB1,smld_symbol_err_prb,'o');semilogy(SNRindB2,theo_err_prb);legend('仿真比特误码率','理论比特误码率');holdoff;function[y]=Qfunct(x)y=(1/2)*erfc(x/sqrt(2));function[pb,ps]=cm_sm32(SNRindB)N=10000;E=1;SNR=10^(SNRindB/10);sgma=sqrt(E/SNR)/2;s00=[10];s01=[01];s11=[-10];s10=[0-1];fori=1:Ntemp=rand;if(temp0.25)dsource1(i)=0;dsource2(i)=0;elseif(temp0.5)dsource1(i)=0;[键入文字][键入文字]dsource2(i)=1;elseif(temp0.75)dsource1(i)=1;dsource2(i)=0;elsedsource1(i)=1;dsource2(i)=1;end;end;numofsymbolerror=0;numofbiterror=0;fori=1:Nn=sgma*randn(size(s00));if((dsource1(i)==0)&(dsource2(i)==0))r=s00+n;elseif((dsource1(i)==0)&(dsource2(i)==1))r=s01+n;elseif((dsource1(i)==1)&(dsource2(i)==0))r=s10+n;elser=s11+n;end;c00=dot(r,s00);c01=dot(r,s01);c10=dot(r,s10);c11=dot(r,s11);c_max=max([c00c01c10c11]);if(c00==c_max)decis1=0;decis2=0;elseif(c01==c_max)decis1=0;decis2=1;elseif(c10==c_max)decis1=1;decis2=0;elsedecis1=1;decis2=1;end;symbolerror=0