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

📄 done_blk.m

📁 ipr函数库与仿真实验程序,都是要用到的库函数。
💻 M
📖 第 1 页 / 共 2 页
字号:
    disp(' 6 <= examine work space')
    calc_type = input...
    ('Select type of calculation or enter 0 for top-level menu: ');

%+++++++++++++++++ no, or no more calculations ++++++++++++++++++++
if (isempty(calc_type) | calc_type == 0),
   disp('Completed calculations')
   activity = -1;   % return to activity menu
   break     % terminate "while calc_type...." loop
end    % of "calc_type == 0"

%++++++++++++++++++++ calculate num & den ++++++++++++++
  if calc_type == 1,
     disp('Numerator, denominator, & sample period of H(z) are:')
     [num_calc,den_calc,Ts_calc] = tfdata(H,'v')
     disp('********>');pause
  end    % of "calc_type == 1"

%++++++++++++++++++++ calculate zeros, poles, and gain ++++++++
  if calc_type == 2,
     disp('Zeros, poles, gain, & sample period of H(z) are:')
     [zer_calc,pol_calc,gain_calc,Ts_calc] = zpkdata(H,'v')
     disp('********>');pause
  end    % of "calc_type == 2"

%+++++++ calculate  Residues, poles, and "other part"+++++++++++
  if calc_type == 3,
     disp('Residues, poles, and "other part" of H(z)/z are:')
     [num,den] = tfdata(H,'v');
     [residues,poles,other] = residue(num,[den 0])
  end    % of "calc_type == 3"

%+++++++++++++ calculate state-space model +++++++++++++
  if calc_type == 4,
     disp('ABCD matrices of state-space form of H(z) are:')
     [A,B,C,D] = ssdata(H)
     disp('********>');pause
  end    % of "calc_type == 4"

%++++++++++ calculate damping ratio & natural freq ++++++++
  if calc_type == 5,
     if (exist('H')),
        [wn,zeta] = damp(H);
       elseif (exist('pol'))  
        [wn,zeta] = damp(pol);    
       else
         disp('Require model as LTI object for this selection')
     end     % of "if exist.....
     if exist('H') | exist('pol'),
        disp('  Undamped ')
        disp('   natural    damping')
        disp('  frequency    ratio ')
        disp('  --------------------')
        disp([wn zeta])
        disp('  --------------------')
     end % if exist('H') | exist('pol')
     disp('********>');pause
  end    % of "calc_type == 5"

%+++++++++++++++++ activate keyboard ++++++++++++++++++++
if calc_type == 6 ,
  disp('keyboard is active to allow:')
  disp('  * examining workspace')
  disp('  * entry of externally-defined model')
  disp('  * use of any Matlab command')
  disp('To resume, enter "return"')
  keyboard
end    % of "calc_type == 6"

calc_type = -1; % force calc menu to appear
%----------
end    % of "while calc_type ...."
end    % of "if activity == 2"

%============= end of calculations ===================

%=========== plots ===============
if activity == 3,
   if ~exist('H')
       disp('Need to enter a model as LTI object first. Rerun.')
       break 
   end   % if ~exist 
  disp('  ')
  disp('Select plots to be done for model')
  disp('When the plot appears the keyboard will be active')
  disp('You may enter a title, add grid lines, and make')
  disp('a hard copy of the plot')
  disp('To resume, i.e., to return from the "keyboard" command')
  disp('Enter "return" for Unix, or use CTRL-Z for DOS')
  disp('  ')
  plot_type = -1;  % force plot menu to appear
  while (plot_type < 1) | (plot_type > 7),
    disp(' 1 <= Impulse response')
    disp(' 2 <= Step response')
    disp(' 3 <= Bode plot')
    disp(' 4 <= Nyquist plot')
    disp(' 5 <= Nichols plot')
    disp(' 6 <= Root locus')
    disp(' 7 <= Pole-zero map')
  plot_type = input...
    ('Select type of plot or enter 0 for top-level menu: ');

%+++++++++++++++++ no more plots ++++++++++++++++++++
if (isempty(plot_type) | plot_type == 0),
  disp('Completed plots')
  activity = -1;   % return to activity menu
  break    % terminate "while plot_type ..." loop
end   

%++++++++++++++++++++ impulse response ++++++++++++++
  if plot_type == 1,
     figure %clf
     title_plot = 'Open-Loop Impulse Response';
     H_plot = H; % H(z) is open-loop by default, unless HOL exists
     if exist('HOL'), % then, H(z):Closed-loop and HOL(z):Open-Loop
        disp('Hit "Enter" to plot Closed-Loop Impulse Response');
        plot_resp = input('Or, enter "OL" to plot the Open-Loop Response: ','s');
        if strcmpi(plot_resp,'OL'), 
           H_plot = HOL; 
        else   
           title_plot = 'Closed-Loop Impulse Response';
        end % if strcmpi..
     end % if exist('HOL')
     
     [y,k] = impulse(H_plot);
     stem(k,y,'filled');grid; title(title_plot);
     %-- add H(z) values to plot
     [num_plot,den_plot,Ts_plot] = tfdata(H_plot,'v');
     num_str = vec2str(num_plot);
     den_str = vec2str(den_plot);
     Ts_str = num2str(Ts_plot);
     text('Units','Norm','Pos',[0.2 0.95],'String',['num = ' num_str])
     text('Units','Norm','Pos',[0.2 0.90],'String',['den = ' den_str])
     text('Units','Norm','Pos',[0.2 0.85],'String',['Ts = ' Ts_str])
     plot_type = -1;   % force plot_type menu to reappear
  end   

%++++++++++++++++++++ step response ++++++++
  if plot_type == 2,
     figure %clf
     title_plot = 'Open-Loop Step Response';
     H_plot = H; % H(z) is open-loop by default, unless HOL exists
     if exist('HOL'), % then, H(z):Closed-loop and HOL(z):Open-Loop
        disp('Hit "Enter" to plot Closed-Loop Step Response');
        plot_resp = input('Or, enter "OL" to plot the Open-Loop Response: ','s');
        if strcmpi(plot_resp,'OL'), 
           H_plot = HOL; 
        else   
           title_plot = 'Closed-Loop Step Response';
        end % if strcmpi..
     end % if exist('HOL')

     [y,k] = step(H_plot);
     stem(k,y,'filled');grid; title(title_plot);
     %-- add H(z) values to plot
     [num_plot,den_plot,Ts_plot] = tfdata(H_plot,'v');
     num_str = vec2str(num_plot);
     den_str = vec2str(den_plot);
     Ts_str = num2str(Ts_plot);
     text('Units','Norm','Pos',[0.3 0.95],'String',['num = ' num_str])
     text('Units','Norm','Pos',[0.3 0.90],'String',['den = ' den_str])
     text('Units','Norm','Pos',[0.3 0.85],'String',['Ts = ' Ts_str])
     plot_type = -1;   % force plot_type menu to reappear
  end  

%+++++++ Bode plot +++++++++++
  if plot_type == 3,
     %clf
     title_plot = 'Open-Loop Bode Plot';
     H_plot = H; % H(z) is open-loop by default, unless HOL exists
     if exist('HOL'), % Now, H(z):Closed-loop and HOL(z):Open-Loop
        disp('Hit "Enter" for Bode plot of the Closed-Loop system');
        plot_resp = input('Or, enter "OL" for Bode plot of Open-Loop: ','s');
        if strcmpi(plot_resp,'OL'), 
           H_plot = HOL; 
        else   
           title_plot = 'Closed-Loop Bode Plot';
        end % if strcmpi..
     end % if exist('HOL')
     
     [mag,ph,w] = bode(H_plot);
     %-- use squeeze cmd to convert 3-dimen array to 2-dim 
     %	 so we can plot it
     mag_db = 20*log10(squeeze(mag));
     ph = squeeze(ph);
     figure; subplot(2,1,1)
     semilogx(w,mag_db);grid
     title(title_plot)
     xlabel('frequency (rad/s)')
     ylabel('Magnitude (db)')
     subplot(2,1,2)
     semilogx(w,ph);grid
     xlabel('frequency (rad/s)')
     ylabel('Phase (deg)')
     %-- add H(z) values to plot
     [num_plot,den_plot,Ts_plot] = tfdata(H_plot,'v');
     num_str = vec2str(num_plot);
     den_str = vec2str(den_plot);
     Ts_str = num2str(Ts_plot);
     text('Units','Norm','Pos',[0.05 0.25],'String',['num = ' num_str])
     text('Units','Norm','Pos',[0.05 0.15],'String',['den = ' den_str])
     text('Units','Norm','Pos',[0.05 0.05],'String',['Ts = ' Ts_str])
     plot_type = -1;   % force plot_type menu to reappear
  end   

%+++++++++++++ Nyquist plot +++++++++++++
  if plot_type == 4,
     %clf
     H_plot = H; % H(z) is open-loop by default, unless HOL exists
     if exist('HOL'), H_plot = HOL; end 

     figure, nyquist(H_plot); grid; title('Nyquist Plot');
     %-- add H(z) values to plot
     [num_plot,den_plot,Ts_plot] = tfdata(H_plot,'v');
     num_str = vec2str(num_plot);
     den_str = vec2str(den_plot);
     Ts_str = num2str(Ts_plot);
     text('Units','Norm','Pos',[0.05 0.15],'String',['num = ' num_str])
     text('Units','Norm','Pos',[0.05 0.10],'String',['den = ' den_str])
     text('Units','Norm','Pos',[0.05 0.05],'String',['Ts = ' Ts_str])
     plot_type = -1;   % force plot_type menu to reappear
  end   

%++++++++++ Nichols plot ++++++++
  if plot_type == 5,
     %clf
     plot([-200 100],[0 0],'--')
     hold on
     plot([-180 -180],[-10 15],'--')
     H_plot = H; % H(z) is open-loop by default, unless HOL exists
     if exist('HOL'), H_plot = HOL; end 
     
     figure, nichols(H_plot)
     hold off
     ngrid; title('Nichols plot')
     %-- add H(z) values to plot
     text('Units','Norm','Pos',[0.05 0.15],'String',['num = ' num_str])
     text('Units','Norm','Pos',[0.05 0.10],'String',['den = ' den_str])
     text('Units','Norm','Pos',[0.05 0.05],'String',['Ts = ' Ts_str])
     plot_type = -1;   % force plot_type menu to reappear
  end   

%++++++++++ root locus plot ++++++++
  if plot_type == 6,
     %clf
     disp('Use "rlocfind" command after plot has been drawn and')
     disp('keyboard is active to find gains at various points')
     disp('Syntax is "[k,p]=rlocfind(H)" where ')
     disp('    k = gain at selected point')
     disp('    p = closed-loop poles for that value of gain')
     H_plot = H; % H(z) is open-loop by default, unless HOL exists
     if exist('HOL'), H_plot = HOL; end 
     
     figure, ucircle, hold on
     rlocus(H_plot)
     hold off
     title('Root Locus')
     %-- add H(z) values to plot
     text('Units','Norm','Pos',[0.05 0.55],'String',['num = ' num_str])
     text('Units','Norm','Pos',[0.05 0.10],'String',['den = ' den_str])
     text('Units','Norm','Pos',[0.05 0.05],'String',['Ts = ' Ts_str])
     keyboard		% allow use of rlocfind cmd
    plot_type = -1;   % force plot_type menu to reappear
  end   

%++++++++++ pole-zero map ++++++++
if plot_type == 7,
     %clf
     title_plot = 'Pole-Zero Map of the Open-Loop System';
     H_plot = H; % H(z) is open-loop by default, unless HOL exists
     if exist('HOL'), % then, H(z):Closed-loop and HOL(z):Open-Loop
        disp('Hit "Enter" to plot Closed-Loop Step Response');
        plot_resp = input('Or, enter "OL" to plot the Open-Loop Response: ','s');
        if strcmpi(plot_resp,'OL'), 
           H_plot = HOL; 
        else   
           title_plot = 'Pole-Zero Map of the Closed-Loop System';
        end % if strcmpi..
     end % if exist('HOL')

     figure, ucircle		% draw unit circle
     hold on
     pzmap(H_plot)
     hold off
     title(title_plot); %title('Pole-zero map from TF form')
     %-- add H(z), or HOL(z), values to plot
     text('Units','Norm','Pos',[0.05 0.15],'String',['num = ' num_str])
     text('Units','Norm','Pos',[0.05 0.10],'String',['den = ' den_str])
     text('Units','Norm','Pos',[0.05 0.05],'String',['Ts = ' Ts_str])
    plot_type = -1;   % force plot_type menu to reappear
  end    % of "plot_type == 7"
%-----
end    % of while plot_type ....
end    % of if activity == 3
%================================
end  % of while for activity menu

%%%%%%%%%%%%%%%%%% end of done_blk.m%%%%%%%%%%%%%%%%%

⌨️ 快捷键说明

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