Advertisement
FridayLord

mc_1&4_codes

Apr 24th, 2024 (edited)
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | Software | 0 0
  1. //⚠️ THANK YOU GUYS. AS THIS LINK SHALL CEASE TO EXIST ON 29TH. THE VERY LAST DAY OF THESE BEAUTIFUL DAYS, adios ladies and gentlemen.
  2. // This is the final goodbye, takecare.👋
  3. // More practicals are given below. ⏬
  4. //~FridayLord
  5.  
  6. //EXP 1 -> ONLINEGDB
  7. import numpy as np
  8. c1=[1,1,1,1]
  9. c2=[1,-1,1,-1]
  10. c3=[1,1,-1,-1]
  11. c4=[1,-1,-1,1]
  12. rc=[]
  13. print("Enter the data bits :")
  14. d1=int(input("Enter D1 :"))
  15. d2=int(input("Enter D2 :"))
  16. d3=int(input("Enter D3 :"))
  17. d4=int(input("Enter D4 :"))
  18. r1=np.multiply(c1,d1)
  19. r2=np.multiply(c2,d2)
  20. r3=np.multiply(c3,d3)
  21. r4=np.multiply(c4,d4)
  22. resultant_channel=r1+r2+r3+r4;
  23. print("Resultant Channel",resultant_channel)
  24. Channel=int(input("Enter the station to listen for C1=1 ,C2=2, C3=3 C4=4 : "))
  25. if Channel==1:
  26.     rc=c1
  27. elif Channel==2:
  28.     rc=c2
  29. elif Channel==3:
  30.     rc=c3
  31. elif Channel==4:
  32.     rc=c4
  33. inner_product=np.multiply(resultant_channel,rc)
  34. print("Inner Product",inner_product)
  35. res1=sum(inner_product)
  36. data=res1/len(inner_product)
  37. print("Data bit that was sent",data)
  38.  
  39.  
  40. //EXP 4 -> MATLAB
  41.  
  42. clear
  43. N = 10^6 %number of bits
  44. rand('state',100);
  45. randn('state',200); % initializing the randn() function
  46. % Transmitter \
  47. ip = rand(1,N)>0.5; % generating 0,1 with equal probability
  48. s = 2*ip-1; % BPSK modulation 0 -> -1; 1 -> 1
  49. n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)]; % white gaussian noise, 0dB
  50.  
  51. Eb_N0_dB = [-3:10]; % multiple Eb/N0 values
  52. for ii = 1:length(Eb_N0_dB)
  53. % Noise addition
  54. y = s + 10^(-Eb_N0_dB(ii)/20)*n; % additive white gaussian noise
  55. % receiver - hard decision decoding
  56. ipHat = real(y)>0;
  57. % counting the errors
  58. nErr(ii) = size(find([ip- ipHat]),2);
  59. end
  60. simBer = nErr/N; % simulated ber
  61. theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))); % theoretical ber
  62.  
  63. % plot
  64. close all
  65. figure;
  66. semilogy(Eb_N0_dB,theoryBer,'b.-');
  67. hold on ;
  68. semilogy(Eb_N0_dB,simBer,'mx-');
  69. axis([-3 10 10^-5 0.5])
  70. grid on;
  71. legend('theory', 'simulation');
  72. xlabel('Eb/No, dB');
  73. ylabel('Bit Error Rate');
  74. title('Bit error probability curve for BPSK modulation');
  75.  
  76. //other than this -> GOOGLE DRIVE LINK --> http://tiny.cc/fridaylordMC
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement