gmsk.asv
上传用户:chenyang06
上传日期:2015-04-05
资源大小:3k
文件大小:4k
源码类别:

生物技术

开发平台:

Matlab

  1. %绘制调制波形10110001
  2. clear all;
  3. Ts=1/16000;                         %基带信号周期为1/16000s,即为16KHz
  4. Tb=1/32000;                         %输入信号周期为Ts/2=1/32000s,即32KHz
  5. BbTb=0.5;                           %取BbTb为0.3
  6. Bb=BbTb/Tb;                         %3dB带宽
  7. Fc=32000;                           %载波频率为32KHz
  8. F_sample=64;                        %每载波采样64个点
  9. B_num=8;                            %基带信号为8个码元
  10. B_sample=F_sample*Fc*Tb;            %每基带码元采样点数B_sample=Tb/Dt
  11. Dt=1/Fc/F_sample;                   %采样间隔
  12. t=0:Dt:B_num*Tb-Dt;                 %仿真时间
  13. T=Dt*length(t);                     %仿真时间值
  14. Ak=[1 0 1 0 1 0 1 0];               %产生8个基带信号
  15. Ak=2*Ak-1;
  16. gt=ones(1,B_sample);         %每码元对应的载波信号
  17. Akk=sigexpand(Ak,B_sample);   %码元扩展
  18. temp=conv(Akk,gt);                 %码元扩展
  19. Akk=temp(1:length(Akk));            %码元扩展
  20. tt=-2.5*Tb:Dt:2.5*Tb-Dt;   
  21. %g(t)=Q[2*pi*Bb*(t-Tb/2)/sqrt(log(2))]-Q[2*pi*Bb*(t+Tb/2)/sqrt(log(2))];
  22. %Q(t)=erfc(t/sqrt(2))/2;
  23. 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;    
  24. J_g=zeros(1,length(gausst)); %使J_g 的长度和Gausst的一样
  25. for i=1:length(gausst)
  26.     if i==1 
  27.         J_g(i)=gausst(i)*Dt;
  28.     else
  29.         J_g(i)=J_g(i-1)+gausst(i)*Dt;
  30.     end;
  31. end;
  32. J_g=J_g/2/Tb;
  33. %计算相位Alpha
  34. Alpha=zeros(1,length(Akk));
  35. k=1;
  36. L=0;
  37. for j=1:B_sample
  38.     J_Alpha=Ak(k+2)*J_g(j);
  39.     Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;
  40. end; 
  41. k=2;
  42. L=0;
  43. for j=1:B_sample
  44.     J_Alpha=Ak(k+2)*J_g(j)+Ak(k+1)*J_g(j+B_sample);
  45.     Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;
  46. end;  
  47. k=3;
  48. L=0;
  49. for j=1:B_sample
  50.     J_Alpha=Ak(k+2)*J_g(j)+Ak(k+1)*J_g(j+B_sample)+Ak(k)*J_g(j+2*B_sample);
  51.     Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;
  52. end;  
  53. k=4;
  54. L=0;
  55. for j=1:B_sample
  56.     J_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);
  57.     Alpha((k-1)*B_sample+j)=pi*J_Alpha+L*pi/2;
  58. end;
  59. L=0;
  60. for k=5:B_num-2
  61.     if k==5
  62.         L=0;
  63.     else
  64.         L=L+Ak(k-3);
  65.     end;
  66.     for j=1:B_sample
  67.         J_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);
  68.         Alpha((k-1)*B_sample+j)=pi*J_Alpha+mod(L,4)*pi/2;
  69.     end;    
  70. end;
  71. %B_num-1;
  72. k=B_num-1;
  73. L=L+Ak(k-3);
  74. for j=1:B_sample
  75.     J_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);
  76.     Alpha((k-1)*B_sample+j)=pi*J_Alpha+mod(L,4)*pi/2;
  77. end;  
  78. %B_num;
  79. k=B_num;
  80. L=L+Ak(k-3);
  81. for j=1:B_sample
  82.     J_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);
  83.     Alpha((k-1)*B_sample+j)=pi*J_Alpha+mod(L,4)*pi/2;
  84. end;  
  85. S_Gmsk=cos(2*pi*Fc*t+Alpha);
  86. subplot(311)
  87. plot(t/Tb,Akk);
  88. axis([0 8 -1.5 1.5]);
  89. title('基带波形');
  90. subplot(312)
  91. plot(t/Tb,Alpha*2/pi);
  92. axis([0 8 min(Alpha*2/pi)-1 max(Alpha*2/pi)+1]);
  93. title('相位波形');
  94. subplot(313)
  95. plot(t/Tb,S_Gmsk);
  96. axis([0 8 -1.5 1.5]);
  97. title('GMSK波形');
  98. %解调
  99. for n=1:512;
  100.     if n<=B_sample
  101.         Alpha1(n)=0;
  102.     else Alpha1(n)=Alpha(n-B_sample);
  103.     end
  104. end
  105. a=[0 1 1 1 1 1 1 1 ]
  106. ak=sigexpand(a,B_sample);   %码元扩展
  107. temp=conv(ak,gt);                 %码元扩展
  108. ak=temp(1:length(ak));
  109. S_Gmsk1=cos(2*pi*Fc*(t-Tb)+Alpha1+pi/2).*ak; %延迟1bt,移相pi/2
  110. figure
  111. subplot(311)
  112. plot(t/Tb,S_Gmsk1);
  113. axis([0 8 -1.5 1.5]);
  114. title('延迟1bt,移相pi/2GMSK波形');
  115. xt=S_Gmsk1.*S_Gmsk;
  116. x=0;
  117. subplot(312)
  118. plot(t/Tb,xt,t/Tb,x,'r:');
  119. axis([0 8 -1.5 1.5]);
  120. title('相乘后波形');
  121. %低通滤波
  122. Fs=10000;
  123. rp=3;rs=50;
  124. wp=2*pi*50;ws=2*pi*800;
  125. [n,wn]=buttord(wp,ws,rp,rs,'s')
  126. [z,p,k]=buttap(n);  %把滤波器零极点模型转化为传递函数模型
  127. [bs,as]=lp2lp(bp,ap,wn);  %把模拟滤波器的模型转化为截止频率为WN的低通滤波器
  128. [b,a]=bilinear(bs,as,Fs)    %用双线性变换法实现从模到数的转化
  129. y=filter(b,a,xt);
  130. subplot(313)
  131. plot(t/Tb,y,t/Tb,x,'r:');
  132. axis([0 8 -1.5 1.5]);
  133. title('经过低通滤波器后波形');
  134. for i=1:8
  135.     if y(i*B_sample)>0
  136.         bt(i)=1
  137.     else
  138.         bt(i)=0
  139.     end
  140. end
  141. bt=2*bt-1;
  142. btt=sigexpand(bt,B_sample);   %码元扩展
  143. temp1=conv(btt,gt);                 %码元扩展
  144. btt=temp1(1:length(btt));            %码元扩展
  145. figure
  146. subplot(311)
  147. plot(bt)
  148. title('抽样值');
  149. axis([0 8 -1.5 1.5]);
  150. subplot(312)
  151. plot(t/Tb,Akk);
  152. axis([0 8 -1.5 1.5]);
  153. title('原基带波形');
  154. subplot(313)
  155. plot(t/Tb,btt);
  156. axis([0 8 -1.5 1.5]);
  157. title('解调后波形');