Home > classes > @ssm > ssm2iirpz.m

ssm2iirpz

PURPOSE ^

ssm2iirpz converts a statespace model object to a miir or a pz

SYNOPSIS ^

function varargout = ssm2iirpz(varargin)

DESCRIPTION ^

 ssm2iirpz converts a statespace model object to a miir or a pz
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: ssm2iirpz converts a statespace model object to a miir or a
 pz

 CALL:
              >> varargout = ssm2iirpz(ssm, options);

 INPUT :

 ssm -     a ssm object
 plist with parameters 'inputs', 'states' and 'outputs' to indicate which
 inputs, states and outputs variables are taken in account. This requires
 proper variable naming. If a variable called appears more that once it
 will be used once only.
 The field may be :
              - a cellstr containing the resp. input/state/output *variable* names
              - a logical indexing the resp. input/state/output *variables*
              names. Index is stored in a cell array, each cell
              correponding to one input/state/output block.
              - a double indexing the resp. input/state/output *variables*
              names. Index is stored in a cell array, each cell
              correponding to one input/state/output block.
              - 'ALL', this string indicates all i/o variables will be
              given

 OUTPUT:

 an array of miir object if the timestep is greater than zero
 a array of pzm object if the timestep is zero

 VERSION:     $Id: ssm2ss.m,v 1.3 2008/04/21 12:38:57 adrien Exp $

 M-FILE INFO: Get information about this methods by calling
              >> ssm.getInfo('ssm2iirpz')

              Get information about a specified set-plist by calling:
              >> ssm.getInfo('ssm2iirpz', 'Default')

 HISTORY: 21-04-2008 A Grynagier

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % ssm2iirpz converts a statespace model object to a miir or a pz
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % DESCRIPTION: ssm2iirpz converts a statespace model object to a miir or a
0005 % pz
0006 %
0007 % CALL:
0008 %              >> varargout = ssm2iirpz(ssm, options);
0009 %
0010 % INPUT :
0011 %
0012 % ssm -     a ssm object
0013 % plist with parameters 'inputs', 'states' and 'outputs' to indicate which
0014 % inputs, states and outputs variables are taken in account. This requires
0015 % proper variable naming. If a variable called appears more that once it
0016 % will be used once only.
0017 % The field may be :
0018 %              - a cellstr containing the resp. input/state/output *variable* names
0019 %              - a logical indexing the resp. input/state/output *variables*
0020 %              names. Index is stored in a cell array, each cell
0021 %              correponding to one input/state/output block.
0022 %              - a double indexing the resp. input/state/output *variables*
0023 %              names. Index is stored in a cell array, each cell
0024 %              correponding to one input/state/output block.
0025 %              - 'ALL', this string indicates all i/o variables will be
0026 %              given
0027 %
0028 % OUTPUT:
0029 %
0030 % an array of miir object if the timestep is greater than zero
0031 % a array of pzm object if the timestep is zero
0032 %
0033 % VERSION:     $Id: ssm2ss.m,v 1.3 2008/04/21 12:38:57 adrien Exp $
0034 %
0035 % M-FILE INFO: Get information about this methods by calling
0036 %              >> ssm.getInfo('ssm2iirpz')
0037 %
0038 %              Get information about a specified set-plist by calling:
0039 %              >> ssm.getInfo('ssm2iirpz', 'Default')
0040 %
0041 % HISTORY: 21-04-2008 A Grynagier
0042 %
0043 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0044 
0045 function varargout = ssm2iirpz(varargin)
0046 
0047   %% starting initial checks
0048   utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]);
0049 
0050   % Check if this is a call for parameters
0051   if utils.helper.isinfocall(varargin{:})
0052     varargout{1} = getInfo(varargin{3});
0053     return
0054   end
0055 
0056   % checking number of inputs work data
0057   if ~nargin==2, error('wrong number of inputs!'), end
0058 
0059   if ~isequal(class(varargin{1}),'ssm'), error(['argument is not a ssm but a ', class(varargin{1})]),end
0060   if ~isequal(class(varargin{2}),'plist'), error(['argument is not a plist but a ', class(varargin{2})]),end
0061 
0062   sys = varargin{1};
0063   options = combine(varargin{2}, getDefaultPlist('Default'));
0064   %% begin function body
0065 
0066   %% convert to double
0067   % Convert to double arrays
0068   [A,B,C,D,Ts,inputvarnames,ssvarnames,outputvarnames] = double(sys, options);
0069 
0070 
0071   Ninputs_out  = length(inputvarnames);
0072   Noutputs_out = length(outputvarnames);
0073 
0074   if Ts > 0
0075     %% convert to miir
0076     miir_out(Noutputs_out, Ninputs_out ) = miir();
0077     for i_inputs=1:Ninputs_out
0078       for i_outputs=1:Noutputs_out
0079         sys_loc =ss( A,B(:,i_inputs),C(i_outputs,:),D(i_outputs, i_inputs ),Ts);
0080         sys_loc = minreal(sys_loc);
0081         [A_loc, B_loc, C_loc, D_loc]=ssdata(sys_loc);
0082         [a,b] = ss2tf(A_loc, B_loc, C_loc, D_loc);
0083         name = [sys.name,' : ',inputvarnames{i_inputs},' -> ',outputvarnames{i_outputs}];
0084         if b==0
0085           m = miir();
0086         else
0087           m = miir(real(a), real(b), 1/sys.timestep);
0088         end
0089         m.addHistory(ssm.getInfo(mfilename), options , {''}, sys.hist );
0090         m.name = name;
0091         miir_out(i_outputs, i_inputs) = m;
0092       end
0093     end
0094     varargout = {miir_out};
0095   else
0096     %% convert to pzm
0097     pzm_out(Noutputs_out, Ninputs_out) = pzmodel();
0098     for i_inputs=1:Ninputs_out
0099       for i_outputs=1:Noutputs_out
0100         [b,a] = ss2tf(A,B(:,i_inputs),C(i_outputs,:),D(i_inputs, i_outputs));
0101         p = roots(b);
0102         p = roots2poly(p);
0103         z = roots(a);
0104         z = roots2poly(z);
0105         Gain = a(1)/b(1);
0106         name = [sys.name,'_',num2str(i_inputs),':',num2str(i_outputs)];
0107         p = pzmodel(Gain,p,z,name);
0108         p.addHistory(ssm.getInfo(mfilename), options , {''}, sys.hist );
0109         pzm_out(i_outputs,i_inputs) = p;
0110       end
0111     end
0112     varargout = {pzm_out};
0113   end
0114 
0115 end
0116 
0117 
0118 function varargout = roots2poly(roots)
0119   poly = pz();
0120   i=1;
0121   while i < length(roots)+1
0122     if isreal(roots(i))
0123       poly = [poly pz(roots(i))]; %#ok<AGROW>
0124       i = i+1;
0125     else
0126       f = norm(roots(i))*sign(real(roots(i)));
0127       Q = norm(roots(i))/abs(2*real(roots(i)));
0128       poly = [poly pz(f,Q)]; %#ok<AGROW>
0129       i = i+2; %#ok<FXSET>
0130     end
0131   end
0132   varargout = {poly};
0133 end
0134 
0135 
0136 function ii = getInfo(varargin)
0137   if nargin == 1 && strcmpi(varargin{1}, 'None')
0138     sets = {};
0139     pls   = [];
0140   elseif nargin == 1 && ~isempty(varargin{1}) && ischar(varargin{1})
0141     sets{1} = varargin{1};
0142     pls = getDefaultPlist(sets{1});
0143   else
0144     sets = {'Default'};
0145     pls = [];
0146     for kk=1:numel(sets)
0147       pls = [pls getDefaultPlist(sets{kk})];
0148     end
0149   end
0150   % Build info object
0151   ii = minfo(mfilename, 'ssm', '', 'STATESPACE', '$Id: resp.m,v 1.17 2008/07/22 10:22:38 ingo Exp $', sets, pls);
0152 end
0153 
0154 function plo = getDefaultPlist(set)
0155   switch set
0156     case 'Default'
0157       plo = ssm.getInfo('reduce_model', 'Default').plists;
0158     otherwise
0159       error('### Unknown parameter set [%s].', set);
0160   end
0161 end
0162

Generated on Mon 25-Aug-2008 22:39:29 by m2html © 2003