Created
August 3, 2021 13:11
-
-
Save kalesan/e1e5028676be12a86e7a4ae91134e951 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cvxpy as cp | |
import numpy as np | |
# Number of channels | |
N = 10 | |
N0 = 1 # Normalized noise level | |
SNR_dB = 10 # The signal to noise ratio in dB | |
P = 10**(SNR_dB/10) # Sum power budget defined via the SNR | |
# The channel specific gains drawn from Gaussian distribution | |
g = np.abs(np.random.randn(N, 1)) | |
G = np.diag(g[0:,0]) # Make gains a diagonal matrix | |
# Problem construction | |
# The individual power allocations as variables (N x 1 real vector) | |
p = cp.Variable(N) | |
objective = cp.Maximize(cp.sum(cp.log(1 + (G @ p) / N0))) | |
constraints = [] | |
constraints.append(p >= 0) # Positive powers constraint | |
constraints.append(cp.sum(p) <= P) # Total power budget | |
problem = cp.Problem(objective, constraints) | |
# Solve the problem | |
result = problem.solve() | |
# Print the optimal sum rate | |
# This has now natural log basis making the unit nats | |
print('Sum-rate (capacity) in nats', result) | |
# Show the power allocation | |
print('Power allocation', p.value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment