Home > classes > @ssm > ssm2iirpz.m

ssm2iirpz

PURPOSE ^

ssm2iirpz converts a statespace model object to an miir or a pzmodel

SYNOPSIS ^

function varargout = ssm2iirpz(varargin)

DESCRIPTION ^

 ssm2iirpz converts a statespace model object to an miir or a pzmodel
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 DESCRIPTION: ssm2iirpz converts a statespace model object to an miir or a
              pzmodel object.

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

 INPUT :

           ssm     - a ssm object
           options - a plist with parameters 'inputs', 'states' and 
                     'outputs' to indicate which inputs, states and output 
                     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
 - an array of pzm object if the timestep is zero

 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')

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

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003