声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 2926|回复: 7

[共享资源] matlab仿真OFDM

[复制链接]
发表于 2006-12-19 21:07 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
  1. %%%%%%%%%%%  Developed for 16 QAM %%%%%%%%%%%%%%
  2. clear all
  3. close all
  4. t0=clock;
  5. %%%%%%%  INPUT PARAMETERS %%%%%%%%%%%
  6. %%%%%  N=, Number of FFT Points
  7. N=1024;
  8. %%%%% M=, Number of OFDM Sub Carriers
  9. M=512;
  10. %%%%% L=, Number of Symbols
  11. L=10;
  12. MMMa=16;%%%% Modulation Method %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% QPSK 16QAM
  13. MMM1a=log2(MMMa);
  14. %%%%% Tg=, Gurd Interval Ratio %%%%%%%%
  15. Tg=0.1;
  16. W=10;%%% Bandwidth(MHz)
  17. DFF=W/M;
  18. %%%%%% ts=, Effective Sumbol Duration (Micro Sec) %%%%%%%
  19. ts=M/W;
  20. %%%%%% D=, Gurd Interval Duration (Micro Sec) %%%%%%%
  21. D=ts*Tg;
  22. %%%%%% Ts=, Symbol Duration (Micro Sec) %%%%%%%%%%
  23. Ts=ts+D;
  24. st1=ts/N;
  25. %%%%%%% Ng=, Number of Samples for Gurd Interval %%%%%%%
  26. Ng=round(D/(ts/N));
  27. %%%%%%% Nt=, Number of Samples for a Symbol %%%%%%%
  28. Nt=(N+Ng);
  29. %%%%%%% NNt=, Number of Samples for a Flame %%%%%%
  30. NNt=Nt*L;
  31. %%%%%%%%% Sampling frequency (usec) %%%%%%%%%%
  32. tbw=1/st1;
  33. %%%%%%% tsw=, Total Allocated Signal Bandwidth (MHz) %%%%%%%
  34. tsw=(1/ts*M);%%%% W bandwidth
  35. ddf=tbw/NNt; %%%% Frequency resolution
  36. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  37. dt=0.1;%%%%%%  delay spread
  38. ds=st1;%%%%%%  delay spacing
  39. NP=10;  %%%%%% number of delay path

  40. %%% Power Delay profile with  Exponential decay constant
  41. amp(1)=0.7854;
  42. amp(2)=0.4861;
  43. amp(3)=0.3009;
  44. amp(4)=0.1863;
  45. amp(5)=0.1153;
  46. amp(6)=0.0714;
  47. amp(7)=0.0442;
  48. amp(8)=0.0273;
  49. amp(9)=0.0169;
  50. amp(10)=0.0105;
  51. dts1(1:NP)=0:9;
  52. %[amp,dst,dts1]=f_MUL(NP,dt,ds,st1);
  53. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  54. cn=30;%%% dB
  55. cn1=10^(-cn/10);

  56. LLL=1;%%% Number of trial
  57. for KLL=1:LLL;
  58. if mod(KLL,1)==0,KLL
  59.   end
  60. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  61.   zxn1=zeros(1,NP);
  62.   zyn1=zeros(1,NP);
  63.   zn1=zeros(1,NP);
  64.   zn2=zeros(1,NP);
  65.   phn=zeros(1,NP);
  66.   amp1=zeros(1,NP);
  67.   qd3=zeros(1,NNt);
  68.   %%% Generation of Rayleigh fading
  69.   %%% Amplitude
  70.   zxn1(1:NP)=randn(1,NP);
  71.   zyn1(1:NP)=randn(1,NP);
  72.   zn1(1:NP)=zxn1(1:NP)+j*zyn1(1:NP);
  73.   zn2(1:NP)=abs(zn1(1:NP))/sqrt(2);
  74.   %%% Phase
  75.   phn(1:NP)=atan2(zyn1(1:NP),zxn1(1:NP));
  76.   amp1(1:NP)=zn2(1:NP).*amp(1:NP).*exp(j*phn(1:NP));
  77. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  78. ya=zeros(L,M);
  79. x3=zeros(L,N);
  80. L1=N/2+1-M/2;
  81. L2=N/2+M/2;
  82. %%%%%%%%%%%%%Data generation %%%%%%%%%%%%%%
  83. ya(1:L,1:M)=randint(L,M,MMMa);
  84. %%%%%%%%%%%%% Modulation %%%%%%%%%
  85. x3(1:L,L1:L2)=f_EnMQAM(ya(1:L,1:M),MMMa);
  86. %%%%%%%%%%%Converting from Frequency to Time domain signal %%%%%%%%%
  87. for k=1:L;
  88. zz1(k,1:N)=ifft(fftshift(x3(k,1:N)))*sqrt(N);
  89. %%%% Adding Guard Interval
  90. z3(k,1:Nt)=[zz1(k,N-Ng+1:N) zz1(k,1:N)];
  91. end
  92.   q13=z3';
  93.   q73=q13(:)';
  94.   %%%%%%%%%% Evaluation of Power Spectrum under AWGN condition
  95.   q73a=fftshift(fft(q73));
  96.   pow1=q73a.*conj(q73a);
  97.   pow2=10*log10(pow1/max(pow1));
  98.   %%%%%%%%%%%
  99.   po3=mean(q73.*conj(q73));
  100.   c3=po3/2*cn1;
  101.   %%%%%% Noise Generation %%%%%
  102.      zxc(1:L,1:Nt)=sqrt(c3).*randn(L,Nt);
  103.      zyc(1:L,1:Nt)=sqrt(c3).*randn(L,Nt);
  104.      znc(1:L,1:Nt)=zxc(1:L,1:Nt)+j*zyc(1:L,1:Nt);
  105.      znn1c=znc';
  106.      znnc=znn1c(:)';
  107.      
  108.      qd3(1:NNt)=amp1(1).*q73(1:NNt);
  109.      %%%% Generation of Multi-path fading signal
  110.   for k=2:NP;
  111.      qu23(k,1:NNt)=[q73(NNt+1-dts1(k):NNt) q73(1:NNt-dts1(k))];
  112.      qu23(k,1:NNt)=amp1(k).*qu23(k,1:NNt);
  113.      qd3(1:NNt)=qd3(1:NNt)+qu23(k,1:NNt);
  114.   end
  115.   %%%%%%%%%% Evaluation of Power Spectrum under multi-path fading condition
  116.   qd3a=fftshift(fft(qd3));
  117.   pow3=qd3a.*conj(qd3a);
  118.   pow4=10*log10(pow3/max(pow3));
  119.   %%%% Adding AWGN
  120.   q73x=qd3+znnc;
  121.   q73y=q73+znnc;
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. imax=1;
  124. %%% Removing Guard interval
  125. for k=1:L;
  126.      p93(k,1:Nt)=q73x(imax-1+(k-1)*Nt+(1:Nt));
  127.      p993(k,1:N)=[p93(k,Ng+1:N+Ng)];
  128.      %%%%%%%%%%  FFT %%%%%
  129.      p813(k,1:N)=fftshift(fft(p993(k,1:N))/sqrt(N));
  130.      HH3(1:M)=p813(1,L1:L2)./x3(1,L1:L2);
  131.      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  132.      p8x3(k,1:M)=p813(k,L1:L2)./HH3(1:M);
  133.      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  134.      p93y(k,1:Nt)=q73y(imax-1+(k-1)*Nt+(1:Nt));
  135.      p993y(k,1:N)=[p93y(k,Ng+1:N+Ng)];
  136.      %%%%%%%%%%%%%%%%%%%%%%%%%%%%
  137.      p813y(k,1:N)=fftshift(fft(p993y(k,1:N))/sqrt(N));
  138.      p8y3(k,1:M)=p813y(k,L1:L2);
  139.      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  140.     end
  141.    
  142.     %%% Demodulation of signal under AWGN
  143.   pb1(1:L,1:M)=f_DeMQAM(p8x3(1:L,1:M),MMMa);%%%
  144.   %%% evaluation of bit error rate performance
  145.   per1(KLL)=biterr(pb1(2:L,1:M),ya(2:L,1:M))/(M*(L-1)*MMM1a);
  146.   %%% Demodulation of signal under multi-path fading
  147.   pb2(1:L,1:M)=f_DeMQAM(p8y3(1:L,1:M),MMMa);%%%
  148.   per2(KLL)=biterr(pb2(2:L,1:M),ya(2:L,1:M))/(M*(L-1)*MMM1a);
  149. end
  150. %%%% Final BER
  151. ERR1=mean(per1(1:LLL));
  152. ERR2=mean(per2(1:LLL));

  153. %%%%%%%%%%%%%%%%%%%%%%%%
  154. figure(1)%%%%%% Information Real Data in Freq
  155. stem(real(x3(2,1:N)))
  156. grid on
  157. figure(2)%%%%%% Information Imag Data in Freq
  158. stem(imag(x3(2,1:N)))
  159. grid on
  160. figure(3)%%%%%% Time domain signal
  161. plot(abs(z3(1,1:Nt)))
  162. grid on
  163. figure(4)
  164. plot(abs(z3(1,1:Ng)))
  165. grid on
  166. figure(5)
  167. plot(abs(z3(1,Nt-Ng:Nt)))
  168. grid on
  169. figure(6)
  170. plot(pow2)
  171. grid on
  172. figure(7)
  173. plot(pow4)
  174. grid on
  175. figure(8)
  176. plot(abs(HH3))
  177. grid on
  178. figure(9)
  179. stem(real(p8x3(2,1:M)))
  180. grid on
  181. figure(10)
  182. stem(imag(p8x3(2,1:M)))
  183. grid on
  184. figure(11)
  185. plot(p8x3(2:L,1:M),'x')
  186. grid on
  187. figure(12)
  188. plot(p8y3(2:L,1:M),'x')
  189. grid on



  190. etime(clock,t0)/60
复制代码
回复
分享到:

使用道具 举报

发表于 2006-12-20 09:19 | 显示全部楼层

:)

正在学习这个,真是太感谢了:)
发表于 2007-10-30 21:24 | 显示全部楼层
randint 是什么意思?
发表于 2007-10-31 15:10 | 显示全部楼层

回复 #3 zhouwh 的帖子

help randint
发表于 2007-11-1 16:01 | 显示全部楼层

~~

有错误啊。

f_EnMQAM  这是啥东西呢?
发表于 2007-11-4 16:29 | 显示全部楼层
thank you very much
发表于 2009-4-4 13:51 | 显示全部楼层
是啊,有错误啊,
??? Undefined function or variable 'f_EnMQAM'.

Error in ==> E:\MATLAB6p5\work\Untitled333.m
On line 87  ==> x3(1:L,L1:L2)=f_EnMQAM(ya(1:L,1:M),MMMa);
谁能给解释下啊
怎么改?
刚开始学,不大懂
发表于 2009-4-4 22:19 | 显示全部楼层

回复 7楼 haobaobao521 的帖子

太长了, 懒, 没细看
可能是自订函数吧, 楼主可能为给齐
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-11 22:40 , Processed in 0.058002 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表