Kaynağa Gözat

Added 32QAM

Min 5 yıl önce
ebeveyn
işleme
34c1776176
3 değiştirilmiş dosya ile 86 ekleme ve 33 silme
  1. 38 0
      alphabets/32qam.a
  2. 44 32
      main.py
  3. 4 1
      models/basic.py

+ 38 - 0
alphabets/32qam.a

@@ -0,0 +1,38 @@
+RI
+0,-0.6,1
+1,-0.2,1
+29,+0.2,1
+28,+0.6,1
+
+4,-1,0.6
+8,-0.6,0.6
+12,-0.2,0.6
+16,+0.2,0.6
+20,+0.6,0.6
+24,+1,0.6
+
+5,-1,0.2
+9,-0.6,0.2
+13,-0.2,0.2
+17,+0.2,0.2
+21,+0.6,0.2
+25,+1,0.2
+
+6,-1,-0.2
+10,-0.6,-0.2
+14,-0.2,-0.2
+18,+0.2,-0.2
+22,+0.6,-0.2
+26,+1,-0.2
+
+7,-1,-0.6
+11,-0.6,-0.6
+15,-0.2,-0.6
+19,+0.2,-0.6
+23,+0.6,-0.6
+27,+1,-0.6
+
+3,-0.6,-1
+2,-0.2,-1
+30,+0.2,-1
+31,+0.6,-1

+ 44 - 32
main.py

@@ -5,7 +5,7 @@ from sklearn.metrics import accuracy_score
 from models import basic
 from models.basic import AWGNChannel, BPSKDemod, BPSKMod, BypassChannel, AlphabetMod, AlphabetDemod
 import misc
-from models.autoencoder import Autoencoder
+from models.autoencoder import Autoencoder, view_encoder
 
 
 def show_constellation(mod, chan, demod, samples=1000):
@@ -62,35 +62,43 @@ if __name__ == '__main__':
     # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
     #          label='AE 4bit -25dB')
 
-    aenc = Autoencoder(5, -25)
-    aenc.train(samples=1e6)
-    plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
-             label='AE 5bit -25dB')
-
-    aenc = Autoencoder(5, -15)
-    aenc.train(samples=1e6)
-    plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
-             label='AE 5bit -15dB')
-
-    aenc = Autoencoder(4, -25)
-    aenc.train(samples=6e5)
-    plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
-             label='AE 4bit -20dB')
+    # aenc = Autoencoder(5, -25)
+    # aenc.train(samples=2e5)
+    # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
+    #          label='AE 5bit -25dB')
 
-    aenc = Autoencoder(4, -15)
-    aenc.train(samples=6e5)
-    plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
-             label='AE 4bit -15dB')
+    # view_encoder(aenc.encoder, 5)
+    # plt.plot(*get_AWGN_ber(AlphabetMod('32qam', 10e6), AlphabetDemod('32qam', 10e6), samples=12000, start=-15), '-',
+    #          label='32-QAM')
+    # show_constellation(AlphabetMod('32qam', 10e6), AWGNChannel(-1), AlphabetDemod('32qam', 10e6))
+    # mod = AlphabetMod('32qam', 10e6)
+    # misc.display_alphabet(mod.alphabet, a_vals=True)
+    # pass
 
-    aenc = Autoencoder(2, -20)
-    aenc.train(samples=6e5)
-    plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
-             label='AE 2bit -20dB')
+    # aenc = Autoencoder(5, -15)
+    # aenc.train(samples=2e6)
+    # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
+    #          label='AE 5bit -15dB')
+    #
+    # aenc = Autoencoder(4, -25)
+    # aenc.train(samples=6e5)
+    # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
+    #          label='AE 4bit -20dB')
+    #
+    # aenc = Autoencoder(4, -15)
+    # aenc.train(samples=6e5)
+    # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
+    #          label='AE 4bit -15dB')
 
-    aenc = Autoencoder(2, -15)
-    aenc.train(samples=6e5)
-    plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
-             label='AE 2bit -15dB')
+    # aenc = Autoencoder(2, -20)
+    # aenc.train(samples=6e5)
+    # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
+    #          label='AE 2bit -20dB')
+    #
+    # aenc = Autoencoder(2, -15)
+    # aenc.train(samples=6e5)
+    # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
+    #          label='AE 2bit -15dB')
 
     # aenc = Autoencoder(4, -10)
     # aenc.train(samples=5e5)
@@ -102,11 +110,15 @@ if __name__ == '__main__':
     # plt.plot(*get_AWGN_ber(aenc.get_modulator(), aenc.get_demodulator(), samples=12000, start=-15), '-',
     #          label='AE 4bit -8dB')
 
-    plt.plot(*get_AWGN_ber(AlphabetMod('64qam', 10e6), AlphabetDemod('64qam', 10e6), samples=12000, start=-15), '-', label='64-QAM')
-    plt.plot(*get_AWGN_ber(AlphabetMod('16qam', 10e6), AlphabetDemod('16qam', 10e6), samples=12000, start=-15), '-', label='16-QAM')
-    plt.plot(*get_AWGN_ber(AlphabetMod('qpsk', 10e6), AlphabetDemod('qpsk', 10e6), samples=12000, start=-15), '-', label='QPSK')
-    plt.plot(*get_AWGN_ber(AlphabetMod('8psk', 10e6), AlphabetDemod('8psk', 10e6), samples=12000, start=-15), '-', label='8PSK')
-    plt.plot(*get_AWGN_ber(BPSKMod(10e6), BPSKDemod(10e6, 10e3), samples=12000), '-', label='BPSK')
+    for scheme in ['64qam', '32qam', '16qam', 'qpsk', '8psk']:
+        plt.plot(*get_AWGN_ber(
+            AlphabetMod(scheme, 10e6),
+            AlphabetDemod(scheme, 10e6),
+            samples=20e3,
+            steps=40,
+            start=-15
+        ), '-', label=scheme.upper())
+
     plt.yscale('log')
     plt.gca().invert_xaxis()
     plt.grid()

+ 4 - 1
models/basic.py

@@ -89,7 +89,10 @@ def load_alphabet(name, polar=True):
             cols = row.split(',')
             try:
                 if len(cols) == 3:
-                    indexes.append(int(cols[0], 2))
+                    base = 2
+                    if 'i' in header:
+                        base = 10
+                    indexes.append(int(cols[0], base))
                     x = float(cols[1])
                     y = float(cols[2])
                 elif len(cols) == 2: