您好,欢迎访问三七文档
%绘制调制波形00101010clearall;Ts=1/16000;%基带信号周期为1/16000s,即为16KHzTb=1/32000;%输入信号周期为Ts/2=1/32000s,即32KHzBbTb=0.5;%取BbTb为0.3Bb=BbTb/Tb;%3dB带宽Fc=32000;%载波频率为32KHzF_sample=64;%每载波采样64个点B_num=8;%基带信号为8个码元B_sample=F_sample*Fc*Tb;%每基带码元采样点数B_sample=Tb/DtDt=1/Fc/F_sample;%采样间隔t=0:Dt:B_num*Tb-Dt;%仿真时间T=Dt*length(t);%仿真时间值Ak=[00101010];%产生8个基带信号Ak=2*Ak-1;gt=ones(1,B_sample);%每码元对应的载波信号Akk=sigexpand(Ak,B_sample);%码元扩展temp=conv(Akk,gt);%码元扩展Akk=temp(1:length(Akk));%码元扩展tt=-2.5*Tb:Dt:2.5*Tb-Dt;%g(t)=Q[2*pi*Bb*(t-Tb/2)/sqrt(log(2))]-Q[2*pi*Bb*(t+Tb/2)/sqrt(log(2))];%Q(t)=erfc(t/sqrt(2))/2;gausst=erfc(2*pi*Bb*(tt-Tb/2)/sqrt(log(2))/sqrt(2))/2-erfc(2*pi*Bb*(tt+Tb/2)/sqrt(log(2))/sqrt(2))/2;J_g=zeros(1,length(gausst));%使J_g的长度和Gausst的一样fori=1:length(gausst)ifi==1J_g(i)=gausst(i)*Dt;elseJ_g(i)=J_g(i-1)+gausst(i)*Dt;end;end;J_g=J_g/2/Tb;%计算相位AlphaAlpha=zeros(1,length(Akk));k=1;L=0;forj=1:B_sampleJ_Alpha=Ak(k+2)*J_g(j);Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;end;k=2;L=0;forj=1:B_sampleJ_Alpha=Ak(k+2)*J_g(j)+Ak(k+1)*J_g(j+B_sample);Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;end;k=3;L=0;forj=1:B_sampleJ_Alpha=Ak(k+2)*J_g(j)+Ak(k+1)*J_g(j+B_sample)+Ak(k)*J_g(j+2*B_sample);Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;end;k=4;L=0;forj=1:B_sampleJ_Alpha=Ak(k+2)*J_g(j)+Ak(k+1)*J_g(j+B_sample)+Ak(k)*J_g(j+2*B_sample)+Ak(k-1)*J_g(j+3*B_sample);Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;end;L=0;fork=5:B_num-2ifk==5L=0;elseL=L+Ak(k-3);end;forj=1:B_sampleJ_Alpha=Ak(k+2)*J_g(j)+Ak(k+1)*J_g(j+B_sample)+Ak(k)*J_g(j+2*B_sample)+Ak(k-1)*J_g(j+3*B_sample)+Ak(k-2)*J_g(j+4*B_sample);Alpha((k-1)*B_sample+j)=pi*J_Alpha+mod(L,4)*pi/2;end;end;%B_num-1;k=B_num-1;L=L+Ak(k-3);forj=1:B_sampleJ_Alpha=Ak(k+1)*J_g(j+B_sample)+Ak(k)*J_g(j+2*B_sample)+Ak(k-1)*J_g(j+3*B_sample)+Ak(k-2)*J_g(j+4*B_sample);Alpha((k-1)*B_sample+j)=pi*J_Alpha+mod(L,4)*pi/2;end;%B_num;k=B_num;L=L+Ak(k-3);forj=1:B_sampleJ_Alpha=Ak(k)*J_g(j+2*B_sample)+Ak(k-1)*J_g(j+3*B_sample)+Ak(k-2)*J_g(j+4*B_sample);Alpha((k-1)*B_sample+j)=pi*J_Alpha+mod(L,4)*pi/2;end;S_Gmsk=cos(2*pi*Fc*t+Alpha);subplot(311)plot(t/Tb,Akk);axis([08-1.51.5]);title('基带波形');subplot(312)plot(t/Tb,Alpha*2/pi);axis([08min(Alpha*2/pi)-1max(Alpha*2/pi)+1]);title('相位波形');subplot(313)plot(t/Tb,S_Gmsk);axis([08-1.51.5]);title('GMSK波形');%解调forn=1:512;ifn=B_sampleAlpha1(n)=0;elseAlpha1(n)=Alpha(n-B_sample);endenda=[01111111]ak=sigexpand(a,B_sample);%码元扩展temp=conv(ak,gt);%码元扩展ak=temp(1:length(ak));S_Gmsk1=cos(2*pi*Fc*(t-Tb)+Alpha1+pi/2).*ak;%延迟1bt,移相pi/2figuresubplot(311)plot(t/Tb,S_Gmsk1);axis([08-1.51.5]);title('延迟1bt,移相pi/2GMSK波形');xt=S_Gmsk1.*S_Gmsk;x=0;subplot(312)plot(t/Tb,xt,t/Tb,x,'r:');axis([08-1.51.5]);title('相乘后波形');%低通滤波Fs=10000;rp=3;rs=50;wp=2*pi*50;ws=2*pi*800;[n,wn]=buttord(wp,ws,rp,rs,'s')[z,p,k]=buttap(n);[bp,ap]=zp2tf(z,p,k);[bs,as]=lp2lp(bp,ap,wn);[b,a]=bilinear(bs,as,Fs)y=filter(b,a,xt);subplot(313)plot(t/Tb,y,t/Tb,x,'r:');axis([08-1.51.5]);title('经过低通滤波器后波形');fori=1:8ify(i*B_sample)0bt(i)=1elsebt(i)=0endendbt=2*bt-1;btt=sigexpand(bt,B_sample);%码元扩展temp1=conv(btt,gt);%码元扩展btt=temp1(1:length(btt));%码元扩展figuresubplot(311)plot(bt)title('抽样值');axis([08-1.51.5]);subplot(312)plot(t/Tb,Akk);axis([08-1.51.5]);title('原基带波形');subplot(313)plot(t/Tb,btt);axis([08-1.51.5]);title('解调后波形');function[out]=sigexpand(d,M)%将输入序列扩展为间隔为N-1个0的序列N=length(d);out=zeros(M,N);out(1,:)=d;out=reshape(out,1,M*N)%gmsk误码率x=0:10;y=x;TracebackLength=7;%回溯长度fori=1:length(x)xSNR=x(i);title('gmsk_error');y(i)=xErrorRate(1);%获取误码率endsemilogy(x,y,'r');gridon;%加网格holdon;%保留当前图形%msk误码率x=0:10;y=x;TracebackLength=4;fori=1:length(x)xSNR=x(i);title('msk_error');y(i)=xErrorRate(1);endsemilogy(x,y,'bd');%bd表示蓝色的菱形gridon;holdon;
本文标题:GMSK-代码
链接地址:https://www.777doc.com/doc-5565220 .html