bpallocrnew.m

来自「对Vblast—oFdm系统地仿真」· M 代码 · 共 89 行

M
89
字号
% Taken from paper "a new loaing algorithm for discrete multitone transmission"
%功率比特分配
function [Palloc,Ralloc]=BPallocRNew(CNR,Nt,Ptotmax,Rtarget)

% Ppermax,which is the peak power limit on each subchannel, is not used in this file.

Palloc=zeros(1,Nt);
Ralloc=zeros(1,Nt);
Rallocdelta=zeros(1,Nt);
Rdelta=2;
Rpermax=6;
Iset=[1:Nt];

N=1./CNR;
D=Nt;
LDN=log2(N);
E=1e-3;
flag=1;
while flag==1
    flag=0;
    for ii=1:length(Iset)
        sumLDN=0;
        for jj=1:length(Iset)
            sumLDN=sumLDN+LDN(Iset(jj));
        end
        Ralloc(Iset(ii))=(Rtarget+sumLDN)/D-LDN(Iset(ii));
        if Ralloc(Iset(ii))<=0
            D=D-1;
            Iset(ii)=[];
            flag=1;
            break;
        end
    end
end

for ii=1:Nt
    Rconti=Ralloc(ii);
%         QUANT(R)
    if Rconti>=Rpermax-0.5
        Ralloc(ii)=Rpermax;
    elseif Rconti<0.5*Rdelta
        Ralloc(ii)=0;
        Iset=setdiff(Iset,ii);
    else
        Ralloc(ii)=round(Rconti/Rdelta)*Rdelta;
    end
    Rallocdelta(ii)=Rconti-Ralloc(ii);
end
Rsum=sum(Ralloc);
Rallocdeltmp=[[1:Nt];Rallocdelta];
if Rsum>Rtarget
    while abs(Rsum-Rtarget)>E
        [minRdel,minPos]=min(Rallocdeltmp(2,:));
        Antsel=Rallocdeltmp(1,minPos);
        if Ralloc(Antsel)>0
            Ralloc(Antsel)=Ralloc(Antsel)-Rdelta;
            if Ralloc(Antsel)<E
                Iset=setdiff(Iset,Antsel);
            end
            Rsum=Rsum-Rdelta;
            Rallocdeltmp(2,minPos)=Rallocdeltmp(2,minPos)+Rdelta;
        else
            Rallocdeltmp(:,minPos)=[];
        end
    end
elseif Rsum<Rtarget
    while abs(Rsum-Rtarget)>E
        [maxRdel,maxPos]=max(Rallocdeltmp(2,:));
        Antsel=Rallocdeltmp(1,maxPos);
        if Ralloc(Antsel)<Rpermax
            Ralloc(Antsel)=Ralloc(Antsel)+Rdelta;
            Rsum=Rsum+Rdelta;
            Rallocdeltmp(2,maxPos)=Rallocdeltmp(2,maxPos)-Rdelta;
            if sum(ismember(Iset, Antsel))==0
                Iset=[Iset Antsel];
            end                
        else
            Rallocdeltmp(:,maxPos)=[];
        end
    end
end

NMsum=0;
for ii=1:length(Iset)
    NMsum=NMsum+2^Ralloc(Iset(ii))/CNR(Iset(ii));
end
for ii=1:length(Iset)
    Palloc(Iset(ii))=Ptotmax*2^Ralloc(Iset(ii))/CNR(Iset(ii))/NMsum;
end

⌨️ 快捷键说明

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