Rayleigh_fading.m
上传用户:asli888
上传日期:2013-05-03
资源大小:7045k
文件大小:3k
源码类别:

matlab例程

开发平台:

Matlab

  1. %***************************** HIMANSHU RAY ************************************************************************%
  2. % Calculating average fade duration and plotting envelope of Rayleigh distribution for specified value of fm and ro %
  3. %************************** ****************************************************************************************%
  4. close all
  5. clear all
  6. clc
  7. N=256;    %Number of frequency samples
  8. M=8192;   %Number of time samples 
  9. % Required parameters for INPUT: fm and row (r0)
  10. fm=input('ENTER THE VALUE OF fm [20 Hz, 200Hz]:')
  11. r0=input('ENTER THE VALUE OF r0 [1,0.1,0.01]:')
  12. y=1;
  13. Afd_p=0;                   % Average fade duration; practical value
  14. Nr_p=0;                    % Number of Zero-crossing level per second
  15. Rrms_p=0;                  % Practically calculated R-rms value
  16. while(y<=1)
  17.     
  18.     delta_f=2*fm/N;        % Frequency resolution
  19.     delta_t=N/(M-1)/2/fm;  % Time resolution
  20. %*************************   NOTE   **********************************%
  21. % "If N=M-1, then the time resolution delta_t=1/2*fm, which may not be
  22. % small so take M >> N. When M > N, we need to pad with zero values
  23. % before taking IFFT."
  24. X1(1)=randn(1);            % Generating Gaussain Random with N(0,1)
  25. X1=X1(1);
  26. Y1(1)=randn(1);
  27. Y1=Y1(1);  
  28. for m=2:(N/2)+1
  29.     X1(m)=randn(1);
  30.     X2(m)=randn(1);
  31.     Y1(m)=randn(1);
  32.     Y2(m)=randn(1);
  33.     X(m)=X1(m)+i*X2(m);
  34.     Y(m)=Y1(m)+i*Y2(m);
  35. end
  36. for m=1:(N/2)+1
  37.     X(M-m+1)=conj(X(m+1));
  38.     Y(M-m+1)=conj(Y(m+1));
  39. end
  40. % Sample Se(f) Spectrum
  41. for jj=1:N/2               
  42. SeF(jj)=1.5/(pi*fm*(sqrt(1-((jj-1)*delta_f/fm)^2))); 
  43. end
  44. % Calculating Edge Value by extending the slope prior to passband edge to edge
  45. SeF((N/2)+1)=SeF(N/2)+SeF(N/2)-SeF((N/2)-1); 
  46. for m=1:N/2
  47. SeF(M-m+1)=SeF(m+1);
  48. end
  49. for m=1:M
  50.     X_shaped(m)=X(m)*sqrt(SeF(m));
  51.     Y_shaped(m)=Y(m)*sqrt(SeF(m));
  52. end
  53. X_component=real(ifft(X_shaped));   % Only considering the real part
  54. Y_component=real(ifft(Y_shaped));
  55. %************* Find R-rms value and envelope of Rayleigh Distribution ***********%
  56. R=sqrt(X_component.^2+Y_component.^2);
  57. r=20*log10(R);
  58. rms=sqrt(mean(R.^2));
  59. Rrms=20*log10(rms);
  60. level=20*log10(r0*rms);
  61. R=r-Rrms;
  62. figure
  63. plot(1:8192,R,'r')
  64. xlabel ('Time Samples, M=8192');
  65. ylabel ('Instantaneous Power dB');
  66. title ('Figure(1):Rayleigh fading signal for Specified fm & r0 ');
  67. %  Calculating (Practically) Number of Zero Level Crossing and Average Fade Duration  %
  68. h=1;
  69. c=0;
  70. C1=0;
  71. NUM=0;
  72.   while h<=M
  73.   if r(h)<=level
  74.       i=h;
  75.       while i<=M
  76.           if r(i)>=level
  77.               NUM=NUM+1;
  78.               break;
  79.           end
  80.           i=i+1;
  81.       end
  82.       c=i-h;
  83.       C1=C1+c;
  84.       h=i-1;
  85.   end
  86.   h=h+1;
  87. end    
  88. Afd_p=Afd_p+(C1/NUM)*delta_t;
  89. Nr_p=Nr_p+NUM*delta_f;
  90. Rrms_p=Rrms_p+Rrms;
  91. y=y+1;
  92. end
  93. %************ Theoretical calculation of  Number of Zero Level Crossing (Nr) and Average Fade Duration ************* %
  94. Nr_theoretical=sqrt(2*pi)*fm*r0*exp(-r0^2); 
  95. z1=exp(r0^2)-1;
  96. z2=r0*fm*sqrt(2*pi);  
  97. Average_fade_duration_theoretical =z1/z2;
  98. rowdb=10*log10(r0) ;
  99. Rrms_theoretical=Rrms+rowdb;
  100. %*********************** Displayiing Calculated values  ************************ %
  101. Nr_practical=(Nr_p);
  102. Nr_practical
  103. Nr_theoretical
  104. Average_fade_duration_Practical=(Afd_p);
  105. Average_fade_duration_Practical
  106. Average_fade_duration_theoretical =z1/z2
  107. Rrms_Practical=Rrms_p
  108. Rrms_theoretical