Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Iram'
- import matplotlib
- matplotlib.use('TkAgg')
- from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
- from matplotlib import pyplot as plt
- from numpy import arange, sin, pi
- from matplotlib.figure import Figure
- from random import randint
- import Tkinter as Tk
- x=[2,3,4,5,6,7,8,9,10]
- y=[6,6,6,6,6,6,6,6,6]
- y1=[6,6,6,6,6,6,6,6,6]
- root = Tk.Tk()
- root.wm_title("Primary User Generator")\
- channelsDescription = Tk.Label(root,text="Channels")
- channelsDescription.grid(row=0, column=1)
- primary_userDescription = Tk.Label(root,text="Primary User")
- primary_userDescription.grid(row=0,column=2)
- secondary_userDescription = Tk.Label(root,text="Secondary User Spectrum Sensing")
- secondary_userDescription.grid(row=0, column=3)
- pBWDescription = Tk.Label(root,text="pBW")
- pBWDescription.grid(row=2,column=1)
- pWBDescription = Tk.Label(root,text="pWB")
- pWBDescription.grid(row=2, column=2)
- sideDescription = Tk.Label(root,text="Set Values:")
- sideDescription.grid(row=1,column=0)
- sideDescription = Tk.Label(root,text="Probabilities:")
- sideDescription.grid(row=3,column=0)
- channelsInput = Tk.Entry(root)
- channelsInput.grid(row=1,column=1)
- primary_userInput = Tk.Entry(root)
- primary_userInput.grid(row=1,column=2)
- secondary_userInput = Tk.Entry(root)
- secondary_userInput.grid(row=1,column=3)
- pBWInput = Tk.Entry(root)
- pBWInput.grid(row=3,column=1)
- pWBInput = Tk.Entry(root)
- pWBInput.grid(row=3,column=2)
- def onSubmitChange():
- ch = int(channelsInput.get())
- pu = int(primary_userInput.get())
- su = int(secondary_userInput.get())
- if ch >= su and ch >= pu:
- plt.close()
- x = [p for p in range(ch)]
- y = [0 for i in range(ch)]
- y1 = [0 for i in range(ch)]
- t = [ch + 1 for i in range(pu)]
- t1 = [ch + 1 for i in range(su)]
- m = 0
- m1 = 0
- while m < pu:
- p = 0
- e = randint(0, ch-1)
- q = 0
- for l in t:
- if e == t[q]:
- p = 2
- q += 1
- t[m] = e
- if p != 2:
- m += 1
- for u in t:
- y[u] = 1
- while m1< su:
- p = 0
- e = randint(0, ch-1)
- q = 0
- for l in t1:
- if e == t1[q]:
- p = 2
- q += 1
- t1[m1] = e
- if p != 2:
- m1 += 1
- for k in t1:
- y1[k] = 1
- print y1
- print t1
- plt.subplot(2,1,1)
- plt.bar(x,y,width=1,color='k',)
- plt.title('primary user')
- plt.ylabel=('y')
- plt.xlabel=('channels')
- plt.subplot(2,1,2)
- plt.bar(x,y1,width=1,color='k',)
- plt.title('secondary user spectrum sensing')
- plt.ylabel=('y')
- plt.xlabel=('channels')
- plt.style.use('ggplot')
- plt.show()
- ButtonChangeValues = Tk.Button(root, text="Submit Change and Graph", command=onSubmitChange)
- ButtonChangeValues.grid(row=5, columnspan=5)
- Tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement