Advertisement
stiansjogren

Lab 3 Radio

May 30th, 2016
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 3.37 KB | None | 0 0
  1. close all
  2.  
  3.  
  4. %% Problem 1
  5.  
  6.  
  7. T_S = 1/(7.68e6);
  8. omega_max = 300;
  9. nb_samples = 10e-3 * 7.68e6;
  10.  
  11.  
  12. % Generation of narrowband Rayleigh fading Channel
  13. % using internal filter based MATLAB function
  14.  
  15. rayChanObj = rayleighchan(T_S, omega_max, 0, 0) ;
  16. rayChanObj.StoreHistory = 1;
  17. x = ones(nb_samples,1);
  18. y = filter(rayChanObj,x);
  19. g = rayChanObj.PathGains;
  20.  
  21. %-------------------------------------------------
  22.  
  23. % Rayleigh fading channel using Sum of sinusoids method
  24. [acf_sos,lag_sos] = xcorr(sumofsinusoids((1/(7.68e6)), 20, 300,nb_samples));
  25.  
  26. % Rayleigh fading channel using filter based method
  27. [acf_flt,lag_flt] = xcorr(y);
  28.  
  29.  
  30.  
  31. % Plotting
  32. subplot(1,3,1)
  33. plot(lag_sos,acf_sos/max(acf_sos));
  34. title 'Sum of sinusoids'
  35. subplot(1,3,2)
  36. plot(lag_flt,acf_flt/max(acf_flt));
  37. title 'Filter based method'
  38. chlen = -0.01:T_S:0.01;
  39. subplot(1,3,3)
  40. plot(linspace(-76799,76799,length(besselj(0, 2*pi*300*chlen))),besselj(0, 2*pi*300*chlen));
  41. title 'Theorethical'
  42. figure;
  43. plot(lag_sos,acf_sos/max(acf_sos), 'r');
  44. hold on
  45. grid on
  46. plot(lag_flt,acf_flt/max(acf_flt),'g');
  47. hold on
  48. plot(linspace(-76799,76799,length(besselj(0, 2*pi*300*chlen))),besselj(0, 2*pi*300*chlen));
  49. title 'Problem one'
  50. legend('Sum-of-Sinusoids', 'Filter based', 'Bessel function'  );
  51. hold off
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. %% Problem 2
  61.  
  62. % Generate four independent fading channels
  63.  
  64. a = [0 0.3 0.9]; b = [0 0.9 0.9];
  65. G = zeros(2,2,nb_samples);
  66. tmp = sumofsinusoids((1/(7.68e6)), 20, 300,nb_samples);
  67.  
  68. for k=1:2
  69.     for j=1:2
  70.         for i= 1:length(sumofsinusoids((1/(7.68e6)), 20, 300,nb_samples))
  71.             G(k,j,i) = tmp(i);
  72.         end
  73.         tmp = sumofsinusoids((1/(7.68e6)), 20, 300,nb_samples);
  74.     end
  75. end
  76.  
  77. Rtx1 = [1 a(1); conj(a(1)) 1] ; Rrx1 = [1 b(1); conj(b(1)) 1];
  78. Rtx2 = [1 a(2); conj(a(2)) 1] ; Rrx2 = [1 b(2); conj(b(2)) 1];
  79. Rtx3 = [1 a(3); conj(a(3)) 1] ; Rrx3 = [1 b(3); conj(b(3)) 1];
  80.  
  81. H = zeros(2,2,nb_samples);
  82. %H2 = zeros(2,2,nb_samples);
  83. %H3 = zeros(2,2,nb_samples);
  84.  
  85. % for n =1:length(G)
  86. %     H1(:,:,n) = sqrtm(Rrx1) .* G(:,:,n) .*transpose(sqrtm(Rtx1));
  87. %     H2(:,:,n) = sqrtm(Rrx2) .* G(:,:,n) .*transpose(sqrtm(Rtx2));
  88. %     H3(:,:,n) = sqrtm(Rrx3) .* G(:,:,n) .*transpose(sqrtm(Rtx3));
  89. % end
  90.  
  91.  
  92. SNR = power(10,-20/10):10:power(10,30/10);
  93. SNR_db = -20:10:30;
  94. figure;
  95. colors = ['b', 'r', 'c'];
  96. tic
  97. for k = 1:3
  98.     R_tx = sqrtm([1 a(k); conj(a(k)) 1]);
  99.     R_rx = sqrtm([1 b(k); conj(b(k)) 1]);
  100.     %for m = 1:nb_samples
  101.     %    H(:,:,m) = R_rx .* G(:,:,m).* transpose(R_tx);
  102.     %end
  103.     CAP      = capacity_SU_CL_ML(H,SNR);
  104.     CAP_mean = mean(CAP,2) ;
  105.     plot(SNR_db, CAP_mean(:), colors(k));
  106.     hold on
  107. end
  108.  
  109. xlabel('SNR [dB]');
  110. ylabel('Channel Capacity');
  111. title('SNR vs Channel capacity with low, medium, and high correlation');
  112. legend('Low correlation (alpha=0, beta=0)', ...
  113.     'Medium correlation (alpha=0.3, beta=0.9)',...
  114.     'High correlation (alpha=0.9, beta=0.9)');
  115.    
  116. toc
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127. % figure;
  128. %
  129. %
  130. % [CAP] = capacity_SU_CL_ML( H1, SNR ,0);
  131. % plot(SNR,CAP);
  132. %
  133. % figure;
  134. % title 'Capacity of SU MIMO channel for medium correlation case';
  135. % for i=1:10:length(SNR)
  136. %     [CAP] = capacity_SU_CL_ML( H2, SNR(i),0);
  137. %     hold on
  138. %     plot(CAP);
  139. % end
  140. % figure;
  141. % title 'Capacity of SU MIMO channel for high correlation case';
  142. % for i=1:10:length(SNR)
  143. %     [CAP] = capacity_SU_CL_ML( H3, SNR(i),0);
  144. %     hold on
  145. %     plot(CAP);
  146. % end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement