Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. % Task 1.1
  2. clc;
  3. clear all;
  4. close all;
  5. EbN0 = linspace(-5,10,16);
  6. %EbN0 = linspace(10^(-0.5),10,16);% from -5 to 10 dB.
  7. Pe = qfunc(sqrt(2 * 10.^(EbN0/10)));
  8. semilogy(EbN0,Pe)
  9. xlabel('$\displaystyle\frac{E_b}{N_0}$ [dB]','interpreter','latex');
  10. ylabel("Pe");
  11. hold on
  12. %% Task 1.2
  13.  
  14. mu = 0;
  15. Error = zeros(1,16); % Vector where we count number of bit errors
  16. %Pe = zeros(1,16);
  17. for i = 1:16 % We want to loop for each SNR N times
  18. SNR = 10.^(EbN0(i)/10);
  19. N0 = 1/SNR;
  20. sigma = sqrt(N0/2);
  21. for N = 1:100000
  22. s = randi([-1 1]); % We transmit 1 or -1.
  23. while s == 0
  24. s = randi([-1 1],1);
  25. end
  26.  
  27. noise = normrnd(mu,sigma);
  28. x = s + noise; % We add noise and receive x.
  29.  
  30. if(sign(x) ~= sign(s)) %If true we recieved wrong.
  31. Error(i) = Error(i) + 1;
  32. end
  33.  
  34. end
  35. Pe1(i) = Error(i)/100000;
  36. end
  37. semilogy(EbN0,Pe1)
  38. ylim([10^(-4) 1]);
  39. legend("Exact","Experimentally")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement