Advertisement
artynet

costellazioni4_test

Mar 26th, 2012
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.34 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf8 -*-
  3.  
  4. from gnuradio import gr
  5. from gnuradio import audio
  6. from gnuradio import blks2
  7. import random
  8. #import wxversion
  9. #wxversion.select('2.8.11')
  10. import wx
  11. import os                   # Operating System dependent call
  12. import sys                  
  13. #from source.modulazioni import bpsk, qpsk, psk8
  14. #from source.modulazioni import bask, qask, ask8
  15. #from source.modulazioni import qam16, qam64, qam256
  16. import cPickle as p
  17. import csv
  18. from source.modulazioni import sunde
  19. import Image
  20. #from source import stdgui2
  21. #from source import visualizza_costfile, visualizza_framemod2 #, slider_ber2
  22. import thread
  23. #import bertool_rician_gnuradio_test
  24.  
  25. # Define dialog component
  26. ID_EXIT = 98
  27. ID_CALCULATE = 99
  28. ID_PLOT = 100
  29. ID_CLOSE = 101
  30. ID_CLEAR_TERM = 102
  31. ID_RESET = 103
  32. ID_ORIG_2_RAW = 104
  33. ID_RAW_2_ORIG = 105
  34. ID_MODULATE = 106
  35.  
  36.  
  37. def ReadFile (arrImg, fpR):
  38.  
  39.     while True:
  40.         data = fpR.read(1)  # Read data, 1 byte each time
  41.         if len(data) == 0:  # If reach EOF, finish the loop
  42.             break
  43.  
  44.         lData  = ord(data)  # Convert char to int
  45.    
  46.         arrImg.append(lData) # Store data(int) into array
  47.    
  48.     return arrImg
  49.  
  50.  
  51. def Ber(sent, received, length):
  52.     try:
  53.     n = 0
  54.     for i in range(length-1):
  55.         if sent[i] != received[i]:
  56.         n+=1                     # no n++ and ++n in Python
  57.     return (float(n)/float(length))
  58.     except IndexError:
  59.     sys.exit()
  60.     except ZeroDivisionError:
  61.     sys.exit()
  62.    
  63. def formatta(valore):
  64.         tmp = str("%.1f" % valore)
  65.         if tmp == "-0.0":
  66.                 return tmp.replace("-","")
  67.         else:
  68.                 return tmp
  69.  
  70.  
  71. class MainWindow(wx.Frame):
  72.     def __init__(self, parent, id, title):
  73.         wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(350, 400),pos = (200,100))
  74.    
  75.    
  76.     #Creates a menu
  77.     filemenu1=wx.Menu()
  78.     filemenu1.AppendSeparator()
  79.     filemenu1.Append(ID_EXIT, "&Exit", "Terminate the program")
  80.    
  81.     # Creating the menubar
  82.     menuBar=wx.MenuBar()
  83.     menuBar.Append(filemenu1, "&File") #Adding the filemenu to the MenuBar
  84.     self.SetMenuBar(menuBar) #Adding the MenuBar to the Frame content
  85.     self.CreateStatusBar() # A statusbar in the bottom of the window
  86.  
  87.         mod = ['BASK','4-ASK','8-ASK','BPSK','Q-PSK','8-PSK','Sunde FSK','QAM-16','QAM-64','QAM-256']
  88.     #mod = ['B-ASK','BPSK','Q-PSK','8-PSK','Sunde FSK']
  89.         #ext = ['.wav', '.mp3', '.ogg','.flac']
  90.    
  91.         wx.StaticText(self, -1, "Scegliere la modulazione :",(50,30))
  92.         self.combo1 = wx.ComboBox(self, -1, pos=(50, 70), size=(150, -1), choices=mod, value='BASK',
  93.                     style=wx.CB_READONLY)
  94.    
  95.     wx.StaticText(self, -1, "Scegliere il valore di Eb :",(50,120))
  96.     wx.StaticText(self, -1, "Eb :",(50,155))
  97.    
  98.     wx.StaticText(self, -1, "Inserire il valore di K (dB) e σ0 :",(50,185))
  99.     wx.StaticText(self, -1, "K :",(50,215))
  100.     wx.StaticText(self, -1, 'σ0 : ',(180,215))
  101.  
  102.     self.txt1 = wx.TextCtrl(self, -1, '1.0',(90,150))  #eb
  103.     self.txt2 = wx.TextCtrl(self, -1, '5.0',(80,210))  # kdb
  104.     self.txt3 = wx.TextCtrl(self, -1, '1.0',(210,210))  # sigma
  105.        
  106.     wx.StaticText(self, -1, "Visualizza Costellazione :",(50,250))
  107.  
  108.     wx.Button(self, ID_MODULATE, 'Start !', (50, 280))
  109.  
  110.     #wx.Button(self, ID_CLOSE, 'Close', (50, 300))
  111.    
  112.     wx.EVT_MENU(self, ID_EXIT, self.OnClose)
  113.     wx.EVT_BUTTON(self, ID_MODULATE, self.calculate)
  114.  
  115.  
  116.     def OnClose(self, e):
  117.         self.Close(True)
  118.    
  119.     def calculate(self,e):
  120.    
  121.     name = self.combo1.GetValue()
  122.     kappa = float(self.txt2.GetValue())
  123.     sigma = float(self.txt3.GetValue())
  124.     number = float(self.txt1.GetValue())
  125.        
  126.         try:
  127.         #name = self.data['name']
  128.         ###ebno = float(self.txt1.GetValue())
  129.         #number = self.data['number']
  130.         #kappa = self.data['kappa']
  131.         #sigma = self.data['sigma']
  132.         ##self.data = dict()
  133.  
  134.         ##name = self.data['title'] = self.combo1.GetValue()
  135.         #thread.start_new_thread(self.calculate, (name,kappa,sigma,number,))
  136.        
  137.         if name == 'BASK':
  138.             #number = float(self.txt1.GetValue())
  139.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_bask,"BASK Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  140.             fg.Show(True)
  141.         elif name == '4-ASK':
  142.             #number = float(self.txt1.GetValue())
  143.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_qask,"4-ASK Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  144.             fg.Show(True)
  145.         elif name == '8-ASK':
  146.             #number = float(self.txt1.GetValue())
  147.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_ask8,"8-ASK Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  148.             fg.Show(True)
  149.         elif name == 'BPSK':
  150.             #number = float(self.txt1.GetValue())
  151.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_bpsk,"BPSK Rician  K = "+str(kappa)+"dB  σ0= "+str(sigma))
  152.             fg.Show(True)
  153.         elif name == 'Q-PSK':
  154.             #number = float(self.txt1.GetValue())
  155.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_qpsk,"Q-PSK Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  156.             fg.Show(True)
  157.         elif name == '8-PSK':
  158.             #number = float(self.txt1.GetValue())
  159.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_psk8,"8-PSK Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  160.             fg.Show(True)
  161.         elif name == 'Sunde FSK':
  162.             #number = float(self.txt1.GetValue())
  163.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_sunde,"Sunde Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  164.             fg.Show(True)
  165.         elif name == 'QAM-16':
  166.             #number = float(self.txt1.GetValue())
  167.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_qam16,"QAM-16 Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  168.             fg.Show(True)
  169.         elif name == 'QAM-64':
  170.             #number = float(self.txt1.GetValue())
  171.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_qam64,"QAM-64 Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  172.             fg.Show(True)
  173.         elif name == 'QAM-256':
  174.             #number = float(self.txt1.GetValue())
  175.             fg = stdgui2.stdframe4(number,kappa,sigma,bertool_rician_gnuradio_test.ber_rician_qam256,"QAM-256 Rician  K = "+str(kappa)+"dB  σ0 = "+str(sigma))
  176.             fg.Show(True)
  177.     except ValueError:
  178.         self.Close(True)
  179.        
  180.        
  181.     def reset(self,e):
  182.     #ext = self.extension
  183.     os.system('rm ./raw.rgb ./rx_unpack.rgb ./rx_unpack.* ./orig.*' )
  184.    
  185.     def clear_term(self,e):
  186.     os.system('clear')
  187.    
  188.     #def frame_ber(self,m,d):
  189.     #fg3 = slider_ber2.Slider(self,m,d)
  190.     #fg3.Show(True)
  191.        
  192.     #def miothread1(self,e):
  193.     #self.data = dict()
  194.     #self.data['name'] = self.combo1.GetValue()
  195.     #self.data['kappa'] = float(self.txt2.GetValue())
  196.     #self.data['sigma'] = float(self.txt3.GetValue())
  197.     #self.data['number'] = float(self.txt1.GetValue())
  198.     ##name = self.data['title'] = self.combo1.GetValue()
  199.     ##thread.start_new_thread(self.calculate, (name,kappa,sigma,number,))
  200.     #thread.start_new_thread(self.parameters, (0,))
  201.    
  202.     #def miothread2(self,e,f):
  203.     #thread.start_new_thread(self.frame_ber, (e,f,))
  204.    
  205.  
  206. class MyApp(wx.App):
  207.     def OnInit(self):
  208.     frame=MainWindow(None, -1, "")
  209.     frame.Show(True)
  210.     self.SetTopWindow(frame)
  211.     return True
  212.    
  213. app = MyApp()
  214. #ComboBox(None, -1, 'BER Tool')
  215. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement