📄 bpallocrnew.m
字号:
% 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -