ashutoshbb

Untitled

Sep 14th, 2021
1,911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.37 KB | None | 0 0
  1. clear all;
  2. clc;
  3.  
  4.  
  5. SNR_dB = -5:4:30;
  6. SNR = 10.^(SNR_dB/10);
  7. NR = 2;
  8. BER_MRC = 1:length(SNR_dB);
  9. BER_EGC = BER_MRC;
  10. BER_SC = BER_MRC;
  11.  
  12. bits = 10^5;
  13. signal_power = 4;
  14. random_bits = randi([0 1],1,bits);
  15.  
  16. x = random_bits
  17. x(x == 0) = -sqrt(signal_power);
  18. x(x == 1) = sqrt(signal_power);
  19. % Calculate the BPSK representation of the message bits
  20. Nr = [1 , 2]
  21.  
  22. % Compute BER for each value of SNR
  23.    
  24. %% Maximal Ratio Combiner
  25.  
  26. for i=1:2
  27.     H = [randn(Nr(i),bits)+sqrt(-1)*randn(Nr(i),bits)];
  28.     n = [randn(Nr(i),bits)+sqrt(-1)*randn(Nr(i),bits)];
  29.     xkron=kron(ones(Nr(i),1),x);
  30.    
  31.     for j=1:length(SNR)
  32.         noise_var = signal_power/SNR(j);
  33.         sigma=sqrt(noise_var/2);
  34.         y= H.*xkron+ sigma*n;
  35.         y_n= sum(conj(H).*y,1)./sum(H.*conj(H),1);
  36.         y_f= real(y_n) > 0;
  37.         N_diff(i,j) = sum(random_bits ~= y_f);
  38.     end
  39. end
  40.  
  41. BER_MRC= N_diff(2,:)/bits;
  42. %% Equal Gain Combining
  43.  
  44. for i=1:2
  45.     H = [randn(Nr(i),bits)+sqrt(-1)*randn(Nr(i),bits)];
  46.     n = [randn(Nr(i),bits)+sqrt(-1)*randn(Nr(i),bits)];
  47.     xkron=kron(ones(Nr(i),1),x);
  48.    
  49.     for j=1:length(SNR)
  50.         noise_var = signal_power/SNR(j);
  51.         sigma=sqrt(noise_var/2);
  52.         y= H.*xkron+ sigma*n;
  53.         y_n= sum(exp(-1i*angle(H)).*y,1);
  54.         y_f= real(y_n) > 0;
  55.         N_diff(i,j) = sum(random_bits ~= y_f);
  56.     end
  57. end
  58.  
  59. BER_EGC= N_diff(2,:)/bits;
  60. %% Selection Combiner
  61.  
  62.  
  63. for i=1:2
  64.     H = [randn(Nr(i),bits)+sqrt(-1)*randn(Nr(i),bits)];
  65.     n = [randn(Nr(i),bits)+sqrt(-1)*randn(Nr(i),bits)];
  66.     xkron=kron(ones(Nr(i),1),x);
  67.    
  68.     for j=1:length(SNR)
  69.         noise_var = signal_power/SNR(j);
  70.         sigma=sqrt(noise_var/2);
  71.         y= H.*xkron+ sigma*n;
  72.         inst_SNR = abs(H).^2;
  73.         [max_SNR, indexes] = max(inst_SNR, [], 1);
  74.         weights = zeros(size(H));
  75.         for k = 1:length(indexes)
  76.             weights(indexes(k), k) = 1;
  77.         end
  78.  
  79.         y_n= sum(weights.*(y./H),1);
  80.        
  81.         y_f= real(y_n) > 0;
  82.         N_diff(i,j) = sum(random_bits ~= y_f);
  83.     end
  84. end
  85. BER_SC= N_diff(2,:)/bits;
  86.  
  87. % Plot BER Vs SNR_dB.
  88. semilogy(SNR_dB,BER_MRC,'--');
  89. hold on;
  90. semilogy(SNR_dB,BER_EGC,'*-');
  91. hold on;
  92. semilogy(SNR_dB,BER_SC,'.-');
  93. hold on;
  94. grid on;
  95. xlabel('SNR (dB)');
  96. ylabel('Bit Error Rate');
  97. legend('MRC','EGC','SC');
  98.  
  99. title('BER Vs SNR plot for SIMO with BPSK with MRC, EGC and SC under Rayleigh channel');
  100.  
Advertisement
Add Comment
Please, Sign In to add comment