Advertisement
Guest User

Untitled

a guest
Jan 18th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import random
  4. import matplotlib as mpl
  5. import math
  6. from scipy.io import wavfile
  7.  
  8. sum_am = 9
  9. bits = 36
  10. samples = 500
  11. Tb = 0.2
  12. # 1o Eρώτημα (a)
  13. Amplitude = sum_am
  14. sequence = np.empty(bits,dtype = int) #δημιουργία πίνακα 36 θέσεων
  15. #σε κάθε θέση του πίνακα sequence θα μπεί 0 ή 1
  16. for i in range (bits):
  17. sequence[i] = random.randint(0,1)
  18. print(sequence)
  19.  
  20. #Δημιουργία πίνακα για το BPAM , όπου θα είναι bits*samples θέσεων έτσι ώστε
  21. #για κάθε bit na υπάρχουν τόσα samples
  22. BPAM = np.empty(bits*samples,dtype = int)
  23. #αρχικοποίηση μεταβλητών που θα χρησιμοποιηθούν στα loops
  24. lowbound = 0
  25. upperbound = samples
  26. #Για κάθε 0 το πλάτος είναι -Αmplitude για κάθε 1 το πλάτος είναι +Amplitude
  27. for a in sequence :
  28. if(a == 0):
  29. for j in range (lowbound,upperbound):
  30. BPAM[j]= -Amplitude
  31. else:
  32. for j in range (lowbound,upperbound):
  33. BPAM[j] = Amplitude
  34. lowbound+=samples
  35. upperbound+=samples
  36.  
  37. t = np.linspace(0,bits*Tb,bits*samples)
  38. plt.figure(figsize=(12,9))
  39. plt.figure(1)
  40. plt.plot(t, BPAM, label = 'Kωδικοποιημένο κατα BPAM ')
  41. plt.xlabel("Time (sec)")
  42. plt.ylabel("B-PAM modulation")
  43. plt.title("B-PAM modulation")
  44. plt.grid()
  45. plt.show()
  46.  
  47. # 1o Eρώτημα (b)
  48. E=Amplitude**2*Tb
  49. f= BPAM/math.sqrt(E)
  50. Em = np.empty(bits*samples)
  51. for i in range (bits*samples):
  52. Em[i]=math.sqrt(E)
  53. plt.scatter(f,Em)
  54. plt.xlabel("φ1(t)")
  55. plt.ylabel("B-PAM modulation")
  56. plt.title("Διάγραμμα αστερισμού BPAM")
  57. plt.grid()
  58. plt.show()
  59.  
  60. #1ο Ερώτημα (c)
  61. t2 = np.zeros(bits*samples)
  62. signal_power = Amplitude**2
  63. SNR1 = 6
  64. SNR2 = 12
  65. noise_power = signal_power/(2*math.sqrt(10**(SNR1/10)))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement