Advertisement
Guest User

Untitled

a guest
Aug 6th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. __author__ = 'Iram'
  2. import matplotlib
  3. matplotlib.use('TkAgg')
  4. from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  5. from matplotlib import pyplot as plt
  6. from numpy import arange, sin, pi
  7. from matplotlib.figure import Figure
  8. from random import randint
  9. import Tkinter as Tk
  10.  
  11.  
  12. x=[2,3,4,5,6,7,8,9,10]
  13. y=[6,6,6,6,6,6,6,6,6]
  14. y1=[6,6,6,6,6,6,6,6,6]
  15.  
  16. root = Tk.Tk()
  17. root.wm_title("Primary User Generator")\
  18.  
  19.  
  20. channelsDescription = Tk.Label(root,text="Channels")
  21. channelsDescription.grid(row=0, column=1)
  22. primary_userDescription = Tk.Label(root,text="Primary User")
  23. primary_userDescription.grid(row=0,column=2)
  24. secondary_userDescription = Tk.Label(root,text="Secondary User Spectrum Sensing")
  25. secondary_userDescription.grid(row=0, column=3)
  26. pBWDescription = Tk.Label(root,text="pBW")
  27. pBWDescription.grid(row=2,column=1)
  28. pWBDescription = Tk.Label(root,text="pWB")
  29. pWBDescription.grid(row=2, column=2)
  30. sideDescription = Tk.Label(root,text="Set Values:")
  31. sideDescription.grid(row=1,column=0)
  32. sideDescription = Tk.Label(root,text="Probabilities:")
  33. sideDescription.grid(row=3,column=0)
  34. channelsInput = Tk.Entry(root)
  35. channelsInput.grid(row=1,column=1)
  36. primary_userInput = Tk.Entry(root)
  37. primary_userInput.grid(row=1,column=2)
  38. secondary_userInput = Tk.Entry(root)
  39. secondary_userInput.grid(row=1,column=3)
  40. pBWInput = Tk.Entry(root)
  41. pBWInput.grid(row=3,column=1)
  42. pWBInput = Tk.Entry(root)
  43. pWBInput.grid(row=3,column=2)
  44.  
  45.  
  46. def onSubmitChange():
  47. ch = int(channelsInput.get())
  48. pu = int(primary_userInput.get())
  49. su = int(secondary_userInput.get())
  50. if ch >= su and ch >= pu:
  51. plt.close()
  52. x = [p for p in range(ch)]
  53. y = [0 for i in range(ch)]
  54. y1 = [0 for i in range(ch)]
  55. t = [ch + 1 for i in range(pu)]
  56. t1 = [ch + 1 for i in range(su)]
  57. m = 0
  58. m1 = 0
  59. while m < pu:
  60. p = 0
  61. e = randint(0, ch-1)
  62. q = 0
  63. for l in t:
  64. if e == t[q]:
  65. p = 2
  66. q += 1
  67. t[m] = e
  68. if p != 2:
  69. m += 1
  70. for u in t:
  71. y[u] = 1
  72.  
  73. while m1< su:
  74. p = 0
  75. e = randint(0, ch-1)
  76. q = 0
  77. for l in t1:
  78. if e == t1[q]:
  79. p = 2
  80. q += 1
  81. t1[m1] = e
  82. if p != 2:
  83. m1 += 1
  84. for k in t1:
  85. y1[k] = 1
  86. print y1
  87. print t1
  88. plt.subplot(2,1,1)
  89. plt.bar(x,y,width=1,color='k',)
  90. plt.title('primary user')
  91. plt.ylabel=('y')
  92. plt.xlabel=('channels')
  93. plt.subplot(2,1,2)
  94. plt.bar(x,y1,width=1,color='k',)
  95. plt.title('secondary user spectrum sensing')
  96. plt.ylabel=('y')
  97. plt.xlabel=('channels')
  98. plt.style.use('ggplot')
  99.  
  100. plt.show()
  101.  
  102. ButtonChangeValues = Tk.Button(root, text="Submit Change and Graph", command=onSubmitChange)
  103. ButtonChangeValues.grid(row=5, columnspan=5)
  104.  
  105. Tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement