⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arpat.m

📁 一维、二维阵列方向图计算
💻 M
📖 第 1 页 / 共 2 页
字号:
      qphx=xsix;
      xsiy = -(2*[1:Ny] - (Ny + 1))/2*psiy;
      xminy = min(xsiy(1),xsiy(Ny));
      xsiy(1:Ny)=xsiy(1:Ny)-xminy;
      qphy=xsiy;
      
% number of bits is nbit; number of phase states is 2**nbit; each bit
% is 360/(2^nbit) degrees
        	nstates = 2^nbits;
        	bitsize = 2*pi/nstates;
         if iph == 2 
			qphx = truncate(Nx,bitsize,xsix);
			qphy = truncate(Ny,bitsize,xsiy);
		 end
         if (iph == 3 | iph == 4)
            qphx = rro(iph,Nx,nstates,bitsize,xsix);
			qphy = rro(iph,Ny,nstates,bitsize,xsiy);
         end
% save quantized and unquantized phases if desired
%  save Qfaz.m qphx -ASCII
%  save Lfaz.m xsix -ASCII
      % begin Pattern loop
      for i1=1:ip
    	for i2=1:it
         figure(hwait);
         waitbar(((i1-1)*ip+i2)/(ip*it),hwait);
         phi(i1,i2) = pstart + (i1 - 1)*delp;
	      phr = phi(i1,i2)*rad;
   	      theta(i1,i2)=tstart + (i2 - 1)*delt;
      	   thr = theta(i1,i2)*rad;
         	st = sin(thr);		ct = cos(thr);
	        cp = cos(phr);		sp = sin(phr);
   	        u = st*cp; 			v = st*sp; 			w = ct;
            U(i1,i2) = u; 		V(i1,i2) = v; 		W(i1,i2)=w;          
         	uu = ct*cp; 		vv = ct*sp; 		ww = -st;
	        sumx = 0;
% sum to get array factor -- begin array loop ---
      		for n = 1:Nx
				nn = (2*n - (Nx + 1))/2;
		        argx = bk*dx*u*nn;
				for m = 1:Ny
					mm = (2*m - (Ny+1))/2;
					argy = bk*dy*v*mm;
% for difference distribution add 180 deg to half the elements
         			phase = qphx(n) + qphy(m); flpx=0; flpy=0;
         			if ixdist == 4 & n > Nx/2, flpx = pi;, end
         			if iydist == 4 & m > Ny/2, flpy = pi;, end
                    pherror(n,m)= phase - xsix(n) - xsiy(m);
		 			sumx = sumx + ampxn(n)*ampyn(m)*exp(j*(phase + flpx + flpy + argx + argy));
	   			end
      		end  % end array loop -----
            
% normalize the pattern to the number of elements
% (i.e., uniform array is reference level for pattern plot)
        		ev(i1,i2) = abs(sumx);
                eva(i1,i2) = sumx;
        		ee = ev(i1,i2)^2;
        		edb(i1,i2) = 10*log10(ee + 1e-10);
	 		end
		end    % end of pattern loop 
        % close waitbar
        close(hwait);
        
        
  		dbmax = max(max(edb));
% plot dB relative to a uniform array; set dynamic range to pmin
		pmin = -50;
		edb = edb - dbmax;

      for i1 = 1:ip
    		for i2 = 1:it
      		if edb(i1,i2) < pmin, edb(i1,i2) = pmin; end
    		end
  		end


% calculate phase quantization loss at scan angle (assume uniform array)
     AF = abs(sum(sum(exp(j*pherror))))/Nx/Ny;
     qloss=-20*log10(AF);
     disp(['phase shifter quantization loss (dB): ',num2str(qloss)])
     save arraydat
      if (it == 1 | ip == 1)
         reply = questdlg('Select Plot Type','Plot Type Selection','Rectangular','Polar','Rectangular');
         switch reply
            case 'Rectangular'
              answer=1;
                        
            case 'Polar'
              answer=0;
          
        end%switch
      end %if
      % export pattern data to file patdata
      reva=real(eva); ieva=imag(eva);
      save patdata theta phi reva ieva -ASCII
      if ip == 1
   		figure(3),clf
	   	if answer == 1, plot(theta,edb),grid 
 	 			axis([tstart,tstop,pmin,0])
    			xlabel('Pattern Angle, theta (deg)')
    			ylabel('Normalized Pattern (dB)')
   		end
   		if answer == 0, polardb(theta,edb,'k-'), end
   		title(['phi = ',num2str(pstart),', aperture efficiency= ',num2str(eta)])
 		end
       
      if it == 1
   		figure(3),clf
   		if answer == 1, plot(phi,edb),grid
    			axis([pstart,pstop,pmin,0])
    			xlabel('Pattern Angle, phi (deg)')
    			ylabel('Normalized Pattern (dB)')
   		end
   		if answer == 0, polardb(phi,edb,'k-'), end
   		title(['theta = ',num2str(tstart),', aperture efficiency= ',num2str(eta)])
  		end
                
      if ip > 1 & it > 1
   		figure(3),clf
			meshc(U,V,edb),grid,axis([-1 1 -1 1 -60,0]),grid
    		axis square
    		xlabel('U = sin(theta)*cos(phi)')
    		ylabel('V = sin(theta)*sin(phi)')
			zlabel('|AF|, dB')
			view(45,45)
			if ixdist == 1, xlab='in x: Uniform distribution'; end
			if ixdist == 2, xlab='in x: Taylor distribution'; end
			if ixdist == 3, xlab='in x: Cosine distribution'; end
			if ixdist == 4, xlab='in x: Bayliss distribution'; end
			if ixdist == 5, xlab='in x: Triangular distribution'; end
			if iydist == 1, ylab='in y: Uniform distribution'; end
			if iydist == 2, ylab='in y: Taylor distribution'; end
			if iydist == 3, ylab='in y: Cosine distribution'; end
			if iydist == 4, ylab='in y: Bayliss distribution'; end
			if iydist == 5, ylab='in y: Triangular distribution'; end
			title([xlab,';   ',ylab])
   	end
        
   case 'Close'       
      h_figs = get(0,'children');    
      for fig = h_figs'              
            delete(fig);      
	   end             
                  
   case 'Print'
      h_figs = get(0,'children');
		for fig = h_figs'
         if strcmp(get(fig,'Tag'),'Array2d')
            figure(fig);  
            print;
            break;
         end
      end   
      
end % switch
  
% >>>>>>>>>>>>>>>> Validation of input values <<<<<<<<<<<<<<<<<<<
% validates phi starting angle
function o_pstart = getPStart(start) 
  
  temp1 = str2num(start);
  temp2 = str2num(get(findobj(gcf,'Tag','PStop'),'String'));

  if (isempty(temp1)) | temp1 < 0 | temp1 > 360
  		errordlg('Enter a Phi Starting angle between 0 and 360 degrees.', ...
        		  'Angle Status', 'error');
    	temp1 = 0; % default phi start angle
  elseif temp1 == temp2
 		set(findobj(gcf,'Tag','Delp'),'String',num2str(1));
      msgbox('For a phi-cut, increment is set to 1 degree.', ...
         	 'Phi-Cut Set','help');        
  elseif (start == 'i' | start == 'j')
     errordlg('Enter a Phi Starting angle between 0 and 360 degrees.', ...
        		  'Angle Status', 'error');
     temp1 = 0; % default phi start angle
  elseif temp1 > temp2   % phi start greater than phi stop angle
     errordlg('Phi starting angle is greater than ending angle!', ...
        		  'Angle Status','error'); 
     temp1 = 0; % default phi ending angle             
  end 
  o_pstart = temp1;
% end getPStart  
  
% validates phi ending angle 
function o_pstop = getPStop(stop)  
  
  temp1 = str2num(stop);
  temp2 = str2num(get(findobj(gcf,'Tag','PStart'),'String'));
  
  if (isempty(temp1)) | temp1 < 0 | temp1 > 360
     errordlg('Enter a Phi ending angle between starting angle and 360 degrees.', ...
        		  'Angle Status', 'error');
     temp1 = 180; 
  elseif temp1 == temp2 % pstop angle = pstart angle
		set(findobj(gcf,'Tag','Delp'),'String',num2str(1));
      msgbox('For a phi-cut, increment is set to 1 degree.', ...
         	 'Phi-Cut Set','help');        
  elseif temp2 > temp1   % phi start greater than phi stop angle
     errordlg('Phi ending angle is less than starting angle!', ...
        		  'Angle Status','error'); 
     temp1 = 180; % default phi ending angle
  elseif (stop == 'i' | stop == 'j')
     errordlg('Enter a Phi ending angle between 0 and 360 degrees.', ...
        		  'Angle Status', 'error');
     temp1 = 180; % default phi ending angle
  end 
  o_pstop = temp1;
% end getPStop  
  
% validates phi increment angle
function o_delp = getDelp(inc)   
  temp3 = str2num(inc);
  temp1 = str2num(get(findobj(gcf,'Tag','PStart'),'String'));
  temp2 = str2num(get(findobj(gcf,'Tag','PStop'),'String'));
  del = temp2 - temp1;
   
  if temp1 == temp2
     if (temp3 ~= 1)
        msgbox('For a phi-cut, increment is set to 1 degree.', ...
           		'Phi-Cut Set','help');
        del = 1;  % default value for phi-cut
     end     
  elseif isempty(temp3) | (temp3 <= 0) | (temp3 > del)
     errordlg('Enter an increment angle less than the diference between starting and ending angles.',...
        		  'Angle Status', 'error');         
     del = 3;  % default phi increment
  elseif (inc == 'i' | inc == 'j')
     errordlg('Enter an increment angle less than the diference between starting and ending angles.', ...
     			  'Angle Status', 'error');     
     del = 3; % default phi increment angle
  else
     del = temp3;
  end % if
  o_delp = del;
% end getDelp  
   
   % validates theta starting angle
function o_tstart = getTStart(start)    

  temp1 = str2num(start);
  temp2 = str2num(get(findobj(gcf,'Tag','TStop'),'String'));

  if (isempty(temp1)) | temp1 < -360 | temp1 > 360
  		errordlg('Enter a Theta Starting angle between -360 and 360 degrees.', ...
        		  'Angle Status', 'error');
    	temp1 = 0; % default theta start angle
  elseif temp1 == temp2
 		set(findobj(gcf,'Tag','Delt'),'String',num2str(1));
      msgbox('For a theta-cut, increment is set to 1 degree.', ...
         	 'Phi-Cut Set','help');  
% allowing negative theta values by commenting out
     elseif (start == 'i' | start == 'j')
     errordlg('Enter a Theta Starting angle between -360 and 360 degrees.', ...
        		  'Angle Status', 'error');
     temp1 = 0; % default theta start angle
  elseif temp1 > temp2   % theta start greater than theta stop angle
     errordlg('Theta starting angle is greater than ending angle!', ...
        		  'Angle Status','error'); 
     temp1 = 0; % default theta ending angle             
  end 
  o_tstart = temp1;
% end getTStart  
    
% validates theta ending angle
function o_tstop = getTStop(stop)   
  
  temp1 = str2num(stop);
  temp2 = str2num(get(findobj(gcf,'Tag','TStart'),'String'));
       
  if (isempty(temp1)) | (temp1 < 0) | (temp1 > 360)
     errordlg('Enter a Theta ending angle between starting angle and 360 degrees.', ...
        		  'Theta Stop Angle Status', 'error');
     temp1 = 180; 		% default theta stop angle
  elseif temp1 == temp2	% tstop angle = tstart angle
		set(findobj(gcf,'Tag','Delt'),'String',num2str(1));
      msgbox('For a theta-cut, increment is set to 1 degree.', ...
         	 'Theta-Cut Set','help');
  elseif (temp2 > temp1)   % theta stop less than theta start angle
     errordlg('Theta ending angle is less than starting angle!', ...
        		  'Theta Stop Angle Status','error'); 
     temp1 = 180; % default theta stop angle 
% allowing negative values 
  elseif (stop == 'i' | stop == 'j')
        errordlg('Enter a Theta Ending angle between -360 and 360 degrees.', ...
        		  'Theta Stop Angle Status', 'error');
        temp1 = 180; % default theta ending angle
  end 
  o_tstop = temp1;
% end getTStop  
  
% validates theta increment angle
function o_delt = getDelt(inc)    
   temp3 = str2num(inc);
   temp1 = str2num(get(findobj(gcf,'Tag','TStart'),'String'));
   temp2 = str2num(get(findobj(gcf,'Tag','TStop'),'String'));
   del = temp2 - temp1;
   
   if temp1 == temp2 	% tstart == tstop
      if temp3 ~= 1
         msgbox('For a theta-cut, increment is set to 1 degree.', ...
            	 'Theta-Cut Set','help');
         del = 1;  % default value for theta-cut
      end
   elseif isempty(temp3) | (temp3 <= 0) | (temp3 > del)
      errordlg('Enter an increment angle less than the diference between starting and ending angles.', ...
         		'Angle Status', 'error');     
      del = 3;  % default theta increment angle
   elseif (inc == 'i' | inc == 'j')
      errordlg('Enter an increment angle less than the difference between starting and ending angle.', ...
         		'Angle Status', 'error');
      del = 3; % default theta increment angle
   else         
      del = temp3;
   end % if
   o_delt = del;
% end getDelt  

   
% validates Number of Elemets
function o_nel = getNEL(nx_str)    
  
  	temp = str2num(nx_str);
   if (isempty(temp)) | (floor(temp) <= 0)
      errordlg('Enter a postive integer.', ...
         		'Number of Elements', 'error');
      temp = 10; % default          
   end 
   o_nel = floor(temp);
% end getNEL  
   
% validates Array Element Spacing
function o_del = getSpacing(str)   
  
   temp = str2num(str);
   if (isempty(temp)) | (floor(temp) < 0)      
      errordlg('Please check spacing of array elements.',...
         		'  Element Spacing', 'error');
      temp = 1; % default  
   end 
   o_del = temp;
% end getSpacing  
 
% validates Scan Angle for Theta and Phi
function o_scan = getScanAngle(start)    
  
  temp = str2num(start);
  if (isempty(temp)) | (temp < 0) | (temp > 360)
     errordlg('Enter a Scan Angle between 0 and 360 degrees.', ...
        		  '  Scan Angle', 'error');
     temp = 30; % default theta start angle
  elseif (start == 'i' | start == 'j')
     errordlg('Enter a Scan Angle between 0 and 360 degrees.', ...
        		  '  Scan Angle', 'error');
     temp = 30; % default theta start angle
  end 
  o_scan = temp;
% end getScanAngle  

⌨️ 快捷键说明

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