-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproblem_2_1.py
More file actions
87 lines (62 loc) · 2.09 KB
/
problem_2_1.py
File metadata and controls
87 lines (62 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import numpy
import power_control
import discrete_time
reload(power_control)
reload(discrete_time)
def findPhistory(number_of_epochs, gamma):
reload(power_control)
reload(discrete_time)
A = power_control.findA(gamma)
b = power_control.findB(gamma)
p = 0.0004 * numpy.ones((power_control.n, 1))
epoch_range = range(number_of_epochs)
p_history = numpy.zeros(shape=(power_control.n,number_of_epochs))
for i in epoch_range:
p_history[:, i] = p.T
p = discrete_time.xtPlus1(p, A, b)
return p_history
def findSinrHistory(number_of_epochs, gamma):
p_history = findPhistory(number_of_epochs, gamma)
epoch_range = range(number_of_epochs)
sinr_history = numpy.zeros(shape=(power_control.n,number_of_epochs))
for i in epoch_range:
p = p_history[:, i]
sinr = power_control.findSinr(p)
sinr_history[:, i] = sinr.T
return sinr_history
number_of_epochs = 50
gamma = 3
alpha_gamma = power_control.alpha * gamma * numpy.ones(number_of_epochs)
phistory = findPhistory(number_of_epochs, gamma)
sinr_history = findSinrHistory(number_of_epochs, gamma)
import matplotlib.pyplot as plt
plt.clf()
plt.cla()
plt.plot(sinr_history[0,:], label= 'S_0')
plt.plot(sinr_history[1,:], label= 'S_1')
plt.plot(sinr_history[2,:], label= 'S_2')
plt.plot(alpha_gamma, label = 'alpha x gamma')
plt.legend()
plt.title('SINR vs. t for gamma = ' + str(gamma))
plt.xlabel('t (epochs)')
plt.ylabel('SINR')
plt.draw()
plt.show()
plt.figure()
plt.plot(phistory[0,:], label= 'p0')
plt.plot(phistory[1,:], label= 'p1')
plt.plot(phistory[2,:], label= 'p2')
plt.legend()
plt.draw()
plt.show()
#def findPhistoryTheOtherWay(number_of_epchs):
# p = numpy.ones((power_control.n, 1))
# epoch_range = range(number_of_epochs)
#
# p_history = numpy.zeros(shape=(power_control.n,number_of_epochs))
#
# for i in epoch_range:
# p_history[:, i] = p.T
# p = p * power_control.alpha * power_control.gamma / power_control.findSinr(p)
#
# return p_history