power_allocate.m
上传用户:cjx922
上传日期:2017-12-13
资源大小:205k
文件大小:6k
源码类别:

通讯编程

开发平台:

Matlab

  1. function [Ps,Pr]=power_allocate(P,asd,asr,ard,combining_type,al_method,transMode,sd_weight);
  2. %根据接收端不同的接收合并方式进行最优功率分配
  3. %MRC方式
  4. switch transMode
  5.     case 'AAF'
  6.         switch combining_type
  7.            case 'MRC'
  8.               for(i=1:1:size(asd,2))
  9.                  switch al_method
  10.                      case 'Best'
  11.                        if(((asd(i)*ard(i)+asr(i)*ard(i)-asd(i)*asr(i))>0)&&((asr(i)*ard(i)*P-asr(i)*asd(i)*P-asd(i))>0))
  12.                          Ps(i)=(asr(i)*ard(i)*P+asd(i)*ard(i)*P+asd(i))/(asd(i)*ard(i)+asr(i)*ard(i)-asd(i)*asr(i)+sqrt((asd(i)*ard(i)+asr(i)*ard(i)-asd(i)*asr(i))*asr(i)*ard(i)*(asr(i)*P+1)/(ard(i)*P+1)));
  13.                          Pr(i)=(asr(i)*ard(i)*P-asr(i)*asd(i)*P-asd(i))/(asd(i)*ard(i)+asr(i)*ard(i)-asd(i)*asr(i)+sqrt((asd(i)*ard(i)+asr(i)*ard(i)-asd(i)*asr(i))*asr(i)*ard(i)*(ard(i)*P+1)/(asr(i)*P+1)));
  14.                        else
  15.                         Ps(i)=P/2;
  16.                         Pr(i)=P/2;
  17.                        end
  18.                     case 'equal'
  19.                        Ps(i)=P/2;
  20.                        Pr(i)=P/2;
  21.                     case 'onlys'
  22.                        Ps(i)=P;
  23.                        Pr(i)=0;
  24.                     otherwise
  25.                        error('No such power allocate method'); 
  26.                  end
  27.               end
  28.             case 'ERC'
  29.                 for(i=1:1:size(asd,2))
  30.                     switch al_method
  31.                         case 'Best'
  32.                             if(((asd(i)-ard(i))*(asd(i)-2*asr(i))>0)&&(2*asr(i)*ard(i)*P-2*asd(i)-2*asd(i)*asr(i)*P-asd(i)*ard(i)*P>0))
  33.                                Ps(i)=(asr(i)*ard(i)*P+asd(i))/(asr(i)*ard(i)-asr(i)*asd(i)+sqrt((asr(i)*P+1)*(asd(i)-ard(i))*(asd(i)-2*asr(i))*asr(i)*ard(i)/(ard(i)*P+2)));
  34.                                Pr(i)=(2*asr(i)*ard(i)*P-2*asd(i)-2*asd(i)*asr(i)*P-asd(i)*ard(i)*P)/(2*asr(i)*ard(i)-2*asr(i)*asd(i)+sqrt((ard(i)*P+2)*(asd(i)-ard(i))*(asd(i)-2*asr(i))*ard(i)*asr(i)/(asr(i)*P+1)));
  35.                             else
  36.                                Ps(i)=P/2;
  37.                                Pr(i)=P/2;
  38.                             end
  39.                         case 'equal'
  40.                             Ps(i)=P/2;
  41.                             Pr(i)=P/2;
  42.                         case 'onlys'
  43.                             Ps(i)=P;
  44.                             Pr(i)=0;
  45.                         otherwise
  46.                             error('No such power allocate method'); 
  47.                     end                           
  48.                 end
  49.             case 'FRC'
  50.                 for(i=1:1:size(asd,2))
  51.                     switch al_method
  52.                         case 'Best'
  53.                             if(((asd(i)*sd_weight^2-ard(i))*(asd(i)*sd_weight^2-sd_weight^2*asr(i)-asr(i))>0)&&((P*asr(i)*ard(i)-asd(i)*sd_weight^2)*(sd_weight^2+1)-P*sd_weight^2*asd(i)*(asr(i)*sd_weight^2+asr(i)+ard(i))>0))
  54.                                Ps(i)=(asr(i)*ard(i)*P+sd_weight^2*asd(i))/(asr(i)*ard(i)-asr(i)*sd_weight^2*asd(i)+sqrt((asr(i)*P+1)*(asd(i)*sd_weight^2-ard(i))*(sd_weight^2*asd(i)-sd_weight^2*asr(i)-asr(i))*asr(i)*ard(i)/(ard(i)*P+sd_weight^2+1)));
  55.                                Pr(i)=((P*asr(i)*ard(i)-asd(i)*sd_weight^2)*(sd_weight^2+1)-P*sd_weight^2*asd(i)*(asr(i)*sd_weight^2+asr(i)+ard(i)))/((asr(i)*ard(i)-asd(i)*asr(i)*sd_weight^2)*(sd_weight^2+1)+sqrt((asd(i)*asr(i)*sd_weight^2-asr(i)*ard(i))*(ard(i)*P+sd_weight^2+1)*(sd_weight^2*asd(i)-sd_weight^2*asr(i)-asr(i))*ard(i)/(asr(i)*P+1)));
  56.                             else
  57.                                Ps(i)=P/2;
  58.                                Pr(i)=P/2;
  59.                             end
  60.                         case 'equal'
  61.                             Ps(i)=P/2;
  62.                             Pr(i)=P/2;
  63.                         case 'onlys'
  64.                             Ps(i)=P;
  65.                             Pr(i)=0;
  66.                         otherwise
  67.                             error('No such power allocate method'); 
  68.                     end                     
  69.                 end
  70.             case 'ESNRC'
  71.                 for(i=1:1:size(asd,2))
  72.                     switch al_method
  73.                       case 'Best'
  74.                            if(((asd(i)-ard(i))*(asd(i)-2*asr(i))>0)&&(2*asr(i)*ard(i)*P-2*asd(i)-2*asd(i)*asr(i)*P-asd(i)*ard(i)*P>0))
  75.                                basic_ps(i)=(asr(i)*ard(i)*P+asd(i))/(asr(i)*ard(i)-asr(i)*asd(i)+sqrt((asr(i)*P+1)*(asd(i)-ard(i))*(asd(i)-2*asr(i))*asr(i)*ard(i)/(ard(i)*P+2)));
  76.                                basic_pr(i)=(2*asr(i)*ard(i)*P-2*asd(i)-2*asd(i)*asr(i)*P-asd(i)*ard(i)*P)/(2*asr(i)*ard(i)-2*asr(i)*asd(i)+sqrt((ard(i)*P+2)*(asd(i)-ard(i))*(asd(i)-2*asr(i))*ard(i)*asr(i)/(asr(i)*P+1)));
  77.                                if(0.1<asd(i)*(asr(i)*basic_ps(i)+ard(i)*basic_pr(i)+1)/(basic_pr(i)*asr(i)*ard(i))&&(asd(i)*(asr(i)*basic_ps(i)+ard(i)*basic_pr(i)+1)/(asr(i)*ard(i)*basic_pr(i))<10))
  78.                                    Ps(i)=(asr(i)*ard(i)*P+asd(i))/(asr(i)*ard(i)-asr(i)*asd(i)+sqrt((asr(i)*P+1)*(asd(i)-ard(i))*(asd(i)-2*asr(i))*asr(i)*ard(i)/(ard(i)*P+2)));
  79.                                    Pr(i)=(2*asr(i)*ard(i)*P-2*asd(i)-2*asd(i)*asr(i)*P-asd(i)*ard(i)*P)/(2*asr(i)*ard(i)-2*asr(i)*asd(i)+sqrt((ard(i)*P+2)*(asd(i)-ard(i))*(asd(i)-2*asr(i))*ard(i)*asr(i)/(asr(i)*P+1)));
  80.                                else
  81.                                    Ps(i)=P/2;
  82.                                    Pr(i)=P/2;
  83.                                end
  84.                            else
  85.                                Ps(i)=P/2;
  86.                                Pr(i)=P/2;
  87.                            end  
  88.                         case 'equal'
  89.                            Ps(i)=P/2;
  90.                            Pr(i)=P/2;
  91.                         case 'onlys'
  92.                            Ps(i)=P;
  93.                            Pr(i)=0;
  94.                         otherwise
  95.                             error('No such power allocate method'); 
  96.                     end
  97.                 end                        
  98.             otherwise
  99.                error(['Unknown relay-type:',combining_type]);
  100.         end
  101.     case 'DAF'
  102.         for(i=1:1:size(asd,2))
  103.             Ps(i)=P/2;
  104.             Pr(i)=P/2;
  105.         end
  106.     otherwise
  107.         error('No such tran Mode'); 
  108. end
  109.             
  110.             
  111.             
  112.