wongsuballo.m

来自「I. C. Wong, Z. Shen, J. G. Andrews, and 」· M 代码 · 共 89 行

M
89
字号
% Author: Ian C. Wong 
% Copyright (C) 2004   Ian C. Wong
% 
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
% 
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
% GNU General Public License for more details.
% 
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
% 
% You may reach the author at wongic@mail.utexas.edu.
% Or visit his website at www.ece.utexas.edu/~iwong

function [capacity,suballo] = wongsuballo (Ptot, ch, N, K, noise, gamma)

suballo=reshape(zeros(1,K*N),K,N);
capacity=zeros(1,K);
occupy=zeros(1,N);
ch=ch/noise;
p=Ptot/N;
% gamma = gamma/min(gamma);
% multiplier = floor(N/sum(gamma));
% num_carriers_per_user = gamma.*multiplier;
num_carriers_per_user = floor(N*gamma/sum(gamma));
unallocated = N - sum(num_carriers_per_user);

used=zeros(1,N);

gammaVector=gamma;

% for each user, find me the subcarrier with best gain
for i=1:K
    [temp maxindex] = max(ch(i,:).*not(occupy));
    capacity(i)=1/N*log2(1+p*ch(i,maxindex));
    occupy(maxindex)=1;
    used(maxindex)=i;
    suballo(i,maxindex)=1;
end

num_carriers_per_user = num_carriers_per_user - 1;

capacity=capacity(:);
temp_capa = capacity;
gammaVector=gammaVector(:);
while (sum(occupy)<N-unallocated),
    [temp minuser] = min(temp_capa./gammaVector);   
    if num_carriers_per_user(minuser) > 0,
        [temp maxindex] = max(ch(minuser,:) .* not(occupy));
        capacity(minuser)=capacity(minuser)+1/N*log2(1+p*ch(minuser,maxindex));
        temp_capa = capacity;
        occupy(maxindex)=1;
        used(maxindex)=minuser;
        suballo(minuser,maxindex)=1;
        num_carriers_per_user(minuser) = num_carriers_per_user(minuser) - 1;
    else,
        temp_capa(minuser) = inf;
    end;
    if sum(temp_capa == inf)==K,
        break;
    end;
end;
idx = find(not(occupy));

% for i = 1:unallocated,
%     [temp minuser] = min(capacity./gammaVector);
%     capacity(minuser)=capacity(minuser)+1/N*log2(1+p*ch(minuser,idx(i)));
%     suballo(minuser, idx(i)) = 1;    
% end;
myturn = ones(K,1);
for i =  1:unallocated,
    [temp maxuser] = max(myturn.*ch(:,idx(i)));
    capacity(maxuser)=capacity(maxuser)+1/N*log2(1+p*ch(maxuser,idx(i)));
    suballo(maxuser, idx(i)) = 1;
    myturn(maxuser) = 0;
end;
capacity = capacity';
    
    
    


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?