main.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. import matplotlib.pyplot as plt
  2. import graphs
  3. from models.basic import AWGNChannel, BPSKDemod, BPSKMod, BypassChannel, AlphabetMod, AlphabetDemod
  4. if __name__ == '__main__':
  5. # show_constellation(BPSKMod(10e6), AWGNChannel(-1), BPSKDemod(10e6, 10e3))
  6. # get_ber(BPSKMod(10e6), AWGNChannel(-20), BPSKDemod(10e6, 10e3))
  7. # mod = MaryMod('8psk', 10e6)
  8. # misc.display_alphabet(mod.alphabet, a_vals=True)
  9. # mod = MaryMod('qpsk', 10e6)
  10. # misc.display_alphabet(mod.alphabet, a_vals=True)
  11. # mod = MaryMod('16qam', 10e6)
  12. # misc.display_alphabet(mod.alphabet, a_vals=True)
  13. # mod = MaryMod('64qam', 10e6)
  14. # misc.display_alphabet(mod.alphabet, a_vals=True)
  15. # aenc = Autoencoder(4, -25)
  16. # aenc.train(samples=5e5)
  17. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  18. # label='AE 4bit -25dB')
  19. # aenc = Autoencoder(5, -25)
  20. # aenc.train(samples=2e5)
  21. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  22. # label='AE 5bit -25dB')
  23. # view_encoder(aenc.encoder, 5)
  24. # plt.plot(*get_AWGN_ber(AlphabetMod('32qam', 10e6), AlphabetDemod('32qam', 10e6), samples=12000, start=-15), '-',
  25. # label='32-QAM')
  26. # show_constellation(AlphabetMod('32qam', 10e6), AWGNChannel(-1), AlphabetDemod('32qam', 10e6))
  27. # mod = AlphabetMod('32qam', 10e6)
  28. # misc.display_alphabet(mod.alphabet, a_vals=True)
  29. # pass
  30. # aenc = Autoencoder(5, -15)
  31. # aenc.train(samples=2e6)
  32. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  33. # label='AE 5bit -15dB')
  34. #
  35. # aenc = Autoencoder(4, -25)
  36. # aenc.train(samples=6e5)
  37. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  38. # label='AE 4bit -20dB')
  39. #
  40. # aenc = Autoencoder(4, -15)
  41. # aenc.train(samples=6e5)
  42. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  43. # label='AE 4bit -15dB')
  44. # aenc = Autoencoder(2, -20)
  45. # aenc.train(samples=6e5)
  46. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  47. # label='AE 2bit -20dB')
  48. #
  49. # aenc = Autoencoder(2, -15)
  50. # aenc.train(samples=6e5)
  51. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  52. # label='AE 2bit -15dB')
  53. # aenc = Autoencoder(4, -10)
  54. # aenc.train(samples=5e5)
  55. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  56. # label='AE 4bit -10dB')
  57. #
  58. # aenc = Autoencoder(4, -8)
  59. # aenc.train(samples=5e5)
  60. # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
  61. # label='AE 4bit -8dB')
  62. # for scheme in ['64qam', '32qam', '16qam', 'qpsk', '8psk']:
  63. # plt.plot(*get_SNR(
  64. # AlphabetMod(scheme, 10e6),
  65. # AlphabetDemod(scheme, 10e6),
  66. # samples=100e3,
  67. # steps=40,
  68. # start=-15
  69. # ), '-', label=scheme.upper())
  70. # plt.yscale('log')
  71. # plt.grid()
  72. # plt.xlabel('SNR dB')
  73. # plt.ylabel('BER')
  74. # plt.legend()
  75. # plt.show()
  76. # for l in np.logspace(start=0, stop=3, num=6):
  77. # plt.plot(*misc.get_SNR(
  78. # AlphabetMod('4pam', 10e6),
  79. # AlphabetDemod('4pam', 10e6),
  80. # samples=2000,
  81. # steps=200,
  82. # start=-5,
  83. # stop=20,
  84. # length=l,
  85. # pulse_shape='rcos'
  86. # ), '-', label=(str(int(l))+'km'))
  87. #
  88. # plt.yscale('log')
  89. # # plt.gca().invert_xaxis()
  90. # plt.grid()
  91. # plt.xlabel('SNR dB')
  92. # # plt.ylabel('BER')
  93. # plt.title("BER against Fiber length")
  94. # plt.legend()
  95. # plt.show()
  96. for ps in ['rect', 'rcos', 'rrcos']:
  97. plt.plot(*graphs.get_SNR(
  98. AlphabetMod('4pam', 10e6),
  99. AlphabetDemod('4pam', 10e6),
  100. samples=30000,
  101. steps=100,
  102. start=-5,
  103. stop=20,
  104. length=1,
  105. pulse_shape=ps
  106. ), '-', label=ps)
  107. plt.yscale('log')
  108. plt.grid()
  109. plt.xlabel('SNR dB')
  110. plt.ylabel('BER')
  111. plt.title("BER for different pulse shapes")
  112. plt.legend()
  113. plt.show()
  114. pass