Tharmetharan Balendran 5 лет назад
Родитель
Сommit
fcd0f1d50b
1 измененных файлов с 16 добавлено и 2 удалено
  1. 16 2
      models/optical_channel.py

+ 16 - 2
models/optical_channel.py

@@ -108,6 +108,19 @@ class OpticalChannel(defs.Channel):
 
 
         pass
         pass
 
 
+    # def eye_diagram(self, t, val_t, num_of_symbols=100):
+    #     symbol_width = int(len(val_t)/num_of_symbols)
+    #     time_scale = t[0:symbol_width]
+    #     counter = 0
+    #     l = 0
+    #     u = symbol_width
+    #     while counter < 100:
+    #         symbol = val_t[l:u]
+    #         plt.plot(time_scale, symbol)
+    #         counter += 1
+    #         l += symbol_width
+    #         u += symbol_width
+
     def forward(self, values):
     def forward(self, values):
         # Converting APF representation to time-series
         # Converting APF representation to time-series
         t, val_t = self.__get_time_domain(values)
         t, val_t = self.__get_time_domain(values)
@@ -142,6 +155,8 @@ class OpticalChannel(defs.Channel):
         t_descision = self.sample_period * idx
         t_descision = self.sample_period * idx
 
 
         if self.show_graphs:
         if self.show_graphs:
+            self.__plot_eye(val_t)
+
             plt.plot(t, val_t)
             plt.plot(t, val_t)
             plt.title('time domain (post-detection)')
             plt.title('time domain (post-detection)')
             plt.show()
             plt.show()
@@ -175,9 +190,8 @@ if __name__ == '__main__':
     symbol_vals[:, 2] = 0
     symbol_vals[:, 2] = 0
 
 
     channel = OpticalChannel(noise_level=-20, dispersion=-21.7, symbol_rate=7e9,
     channel = OpticalChannel(noise_level=-20, dispersion=-21.7, symbol_rate=7e9,
-                             sample_rate=336e9, length=0, pulse_shape='rrcos', show_graphs=False)
+                             sample_rate=336e9, length=0, pulse_shape='rcos', show_graphs=True)
     v = channel.forward(symbol_vals)
     v = channel.forward(symbol_vals)
-
     rx = (v > 0.5).astype(int)
     rx = (v > 0.5).astype(int)
     tru = np.sum(rx == symbol_vals[:, 0].astype(int))
     tru = np.sum(rx == symbol_vals[:, 0].astype(int))
     print("Accuracy: {}".format(tru/num_of_symbols))
     print("Accuracy: {}".format(tru/num_of_symbols))