% Determines the optimal power allocation on a
% channel with a pool of subchannels subjeted to different noise powers. The
% optimum power allocation is the one that maximizes the channel capacity.
clear all;
n=10; % number of subchannels
s=rand(n,1); % vector of noise powers across the subchannels
Pt=5; % total transmit power
cvx_begin
variable P(n) % the optimum power allocation vector
%maximize sum(log(1+P./s))
maximize sum(log(s+P))-sum(log(s)) % see Boyd p. 245
subject to
P >= 0;
sum(P) == Pt;
cvx_end
hold on
bar(P+s);
bar(s, 'red');