adaptive.m
上传用户:look542
上传日期:2009-06-04
资源大小:784k
文件大小:1k
源码类别:

传真(Fax)编程

开发平台:

Matlab

  1. function C=adaptive(H,N,R)
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % 功能:   自适应的比特分配:按照信道响应降序排列,子载波间争夺比特和功率
  4. %         步长为2
  5. % 输入:   H为信道的参数
  6. %         N为子载波数
  7. % 输出:   C,得到的比特分配
  8. % 作者:郭莹,2004.3
  9. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  10. dex=zeros(N,1);
  11. x=zeros(N,1);
  12. H=abs(H);
  13. for a=1:N
  14.    x(a)=sum((H>H(a)))+1;
  15.    for t=1:20
  16.    if dex(x(a))~=0
  17.        x(a)=x(a)+1;
  18.    else break
  19.    end
  20.   end
  21.    dex(x(a))=a;
  22. end
  23. C=R/N*ones(N,1);
  24. for m=1:N-1
  25.     for n=N:-1:m+1
  26.         if C(dex(m))>3
  27.             break
  28.         end
  29.         if C(dex(n))==0
  30.            continue
  31.         end
  32.         a=H(dex(m))^2;
  33.         b=H(dex(n))^2; 
  34.         switch (C(dex(n)))
  35.           case 1 
  36.              if a>2*b
  37.               C(dex(m))=C(dex(m))+1;
  38.               C(dex(n))=C(dex(n))-1;
  39.             end
  40.           case 2
  41.             if a>3*b
  42.             C(dex(m))=C(dex(m))+1;
  43.             C(dex(n))=C(dex(n))-1;
  44.            end
  45.         end
  46.     end 
  47. end