BPallocRNew.m
上传用户:xinxin4122
上传日期:2013-04-03
资源大小:464k
文件大小:2k
源码类别:

邮电通讯系统

开发平台:

Matlab

  1. % Taken from paper "a new loaing algorithm for discrete multitone transmission"
  2. %功率比特分配
  3. function [Palloc,Ralloc]=BPallocRNew(CNR,Nt,Ptotmax,Rtarget)
  4. % Ppermax,which is the peak power limit on each subchannel, is not used in this file.
  5. Palloc=zeros(1,Nt);
  6. Ralloc=zeros(1,Nt);
  7. Rallocdelta=zeros(1,Nt);
  8. Rdelta=2;
  9. Rpermax=6;
  10. Iset=[1:Nt];
  11. N=1./CNR;
  12. D=Nt;
  13. LDN=log2(N);
  14. E=1e-3;
  15. flag=1;
  16. while flag==1
  17.     flag=0;
  18.     for ii=1:length(Iset)
  19.         sumLDN=0;
  20.         for jj=1:length(Iset)
  21.             sumLDN=sumLDN+LDN(Iset(jj));
  22.         end
  23.         Ralloc(Iset(ii))=(Rtarget+sumLDN)/D-LDN(Iset(ii));
  24.         if Ralloc(Iset(ii))<=0
  25.             D=D-1;
  26.             Iset(ii)=[];
  27.             flag=1;
  28.             break;
  29.         end
  30.     end
  31. end
  32. for ii=1:Nt
  33.     Rconti=Ralloc(ii);
  34. %         QUANT(R)
  35.     if Rconti>=Rpermax-0.5
  36.         Ralloc(ii)=Rpermax;
  37.     elseif Rconti<0.5*Rdelta
  38.         Ralloc(ii)=0;
  39.         Iset=setdiff(Iset,ii);
  40.     else
  41.         Ralloc(ii)=round(Rconti/Rdelta)*Rdelta;
  42.     end
  43.     Rallocdelta(ii)=Rconti-Ralloc(ii);
  44. end
  45. Rsum=sum(Ralloc);
  46. Rallocdeltmp=[[1:Nt];Rallocdelta];
  47. if Rsum>Rtarget
  48.     while abs(Rsum-Rtarget)>E
  49.         [minRdel,minPos]=min(Rallocdeltmp(2,:));
  50.         Antsel=Rallocdeltmp(1,minPos);
  51.         if Ralloc(Antsel)>0
  52.             Ralloc(Antsel)=Ralloc(Antsel)-Rdelta;
  53.             if Ralloc(Antsel)<E
  54.                 Iset=setdiff(Iset,Antsel);
  55.             end
  56.             Rsum=Rsum-Rdelta;
  57.             Rallocdeltmp(2,minPos)=Rallocdeltmp(2,minPos)+Rdelta;
  58.         else
  59.             Rallocdeltmp(:,minPos)=[];
  60.         end
  61.     end
  62. elseif Rsum<Rtarget
  63.     while abs(Rsum-Rtarget)>E
  64.         [maxRdel,maxPos]=max(Rallocdeltmp(2,:));
  65.         Antsel=Rallocdeltmp(1,maxPos);
  66.         if Ralloc(Antsel)<Rpermax
  67.             Ralloc(Antsel)=Ralloc(Antsel)+Rdelta;
  68.             Rsum=Rsum+Rdelta;
  69.             Rallocdeltmp(2,maxPos)=Rallocdeltmp(2,maxPos)-Rdelta;
  70.             if sum(ismember(Iset, Antsel))==0
  71.                 Iset=[Iset Antsel];
  72.             end                
  73.         else
  74.             Rallocdeltmp(:,maxPos)=[];
  75.         end
  76.     end
  77. end
  78. NMsum=0;
  79. for ii=1:length(Iset)
  80.     NMsum=NMsum+2^Ralloc(Iset(ii))/CNR(Iset(ii));
  81. end
  82. for ii=1:length(Iset)
  83.     Palloc(Iset(ii))=Ptotmax*2^Ralloc(Iset(ii))/CNR(Iset(ii))/NMsum;
  84. end