


SSM statespace model class constructor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: SSM statespace model class constructor.
** This class is written using the new OO structures of MATLAB R2008a and
will not work with earlier MATLAB versions.
Public properties (read-only):
Public properties (read/write):
name - name of analysis object
Possible constructors:
s = ssm() - creates an empty statespace model
s = ssm('a1.xml') - creates a new statespace model by loading the
object from disk.
s = ssm('a1.mat') - creates a new statespace model by loading the
object from disk.
a = ssm(plist) - creates a statespace model from the description
given in the parameter list
a = ssm(struct) - creates a statespace model from the
structure returned by struct(ssm).
Parameter sets for plist constructor (in order of priority):
From XML File
-------------
Construct a statespace model by loading it from an XML file.
'filename' - construct a statespace model from a filename.
Example: plist('filename', 'ss1.xml')
[default: empty string]
From MAT File
-------------
Construct a statespace model by loading it from a MAT file.
'filename' - construct a statespace model from a filename.
Example: plist('filename', 'ss1.mat')
[default: empty string]
From Built-in System
----------------
Construct a statespace model by specifying one of the built-in system names.
'Buit-in' - A system name.
Example: plist('filename', 'model_LPF_Dynamics_noparams')
Example: plist('Built-in', ' ')
will show the names of all the existing systems
From Repository
---------------
Construct a statespace model by retrieving it from an LTPDA repository.
'Hostname' - the repository hostname. Only those objects which
are statespace models are returned.
[default: 'localhost'];
Additional parameters:
'Database' - The database name [default: 'ltpda']
'ID' - A vector of object IDs. [default: []]
From a Miir
---------------
Construct a statespace model out of a MIIR object.
example : sys = ssm(themiir);
From PZ model
---------------
Construct a statespace model by retrieving it from an LTPDA repository.
example : sys=ssm(thepzmodel);
From Description
----------------
Construct a statespace model from a full description of the system.
'isADescription' >> special filed to tell the constructor which set to use
compulsory fields:
'name','ssnames', 'outputnames', 'inputnames', 'timestep', 'amats', ...
'bmats', 'cmats', 'dmats', 'paramnames', 'paramvalues'
optionnals fields :
'mmats' 'amats_handles' 'bmats_handles' 'cmats_handles' 'dmats_handles'...
'inputvarnames' 'ssvarnames' 'ssini' 'outputvarnames' 'paramsigmas'
example :
name = 'sys';
ssnames = {'ss1' 'ss2' 'ss3'};
ssvarnames = {{'ssvar1'} {'ssvar2'} {'ssvar31' 'ssvar32'}};
inputnames = {'input1' 'input2' 'input3'};
inputvarnames = {{'inputvar1'} {'inputvar2'} {'inputvar31' 'inputvar32'}};
outputnames = {'output1' 'output2' 'output3'};
outputvarnames = {{'outputvar1'} {'outputvar2'} {'outputvar31' 'outputvar32'}};
timestep = 0;
paramnames = {};
paramvalues = [];
amats = cell(3,3);
bmats = cell(3,3);
cmats = cell(3,3);
dmats = cell(3,3);
amats{1,1} = -1;
amats{2,2} = -2;
amats{3,3} = -3*eye(2);
amats{3,1} = [-1;-3];
bmats{1,1} = 1;
bmats{2,2} = 2;
bmats{3,3} = 3*eye(2);
cmats{1,1} = 1;
cmats{2,2} = 1;
cmats{3,3} = eye(2);
dmats{1,3} = [6 6];
dmats{2,1} = 6;
dmats{3,2} = [6;6];
sys = ssm(plist('isADescription', '' ,'name', name , ...
'timestep', timestep , 'paramnames', paramnames ,'paramvalues', paramvalues ,...
'inputnames', inputnames , 'outputnames',outputnames ,'ssnames', ssnames,...
'inputvarnames', inputvarnames , 'outputvarnames',outputvarnames ,'ssvarnames', ssvarnames,...
'amats', amats ,'bmats', bmats ,'cmats', cmats ,'dmats', dmats ));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


0001 % SSM statespace model class constructor. 0002 % 0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0004 % 0005 % DESCRIPTION: SSM statespace model class constructor. 0006 % 0007 % ** This class is written using the new OO structures of MATLAB R2008a and 0008 % will not work with earlier MATLAB versions. 0009 % 0010 % Public properties (read-only): 0011 % 0012 % Public properties (read/write): 0013 % name - name of analysis object 0014 % 0015 % Possible constructors: 0016 % 0017 % s = ssm() - creates an empty statespace model 0018 % s = ssm('a1.xml') - creates a new statespace model by loading the 0019 % object from disk. 0020 % s = ssm('a1.mat') - creates a new statespace model by loading the 0021 % object from disk. 0022 % a = ssm(plist) - creates a statespace model from the description 0023 % given in the parameter list 0024 % a = ssm(struct) - creates a statespace model from the 0025 % structure returned by struct(ssm). 0026 % 0027 % Parameter sets for plist constructor (in order of priority): 0028 % 0029 % From XML File 0030 % ------------- 0031 % Construct a statespace model by loading it from an XML file. 0032 % 0033 % 'filename' - construct a statespace model from a filename. 0034 % Example: plist('filename', 'ss1.xml') 0035 % [default: empty string] 0036 % 0037 % From MAT File 0038 % ------------- 0039 % Construct a statespace model by loading it from a MAT file. 0040 % 0041 % 'filename' - construct a statespace model from a filename. 0042 % Example: plist('filename', 'ss1.mat') 0043 % [default: empty string] 0044 % 0045 % From Built-in System 0046 % ---------------- 0047 % Construct a statespace model by specifying one of the built-in system names. 0048 % 0049 % 'Buit-in' - A system name. 0050 % Example: plist('filename', 'model_LPF_Dynamics_noparams') 0051 % Example: plist('Built-in', ' ') 0052 % will show the names of all the existing systems 0053 % 0054 % 0055 % From Repository 0056 % --------------- 0057 % Construct a statespace model by retrieving it from an LTPDA repository. 0058 % 0059 % 'Hostname' - the repository hostname. Only those objects which 0060 % are statespace models are returned. 0061 % [default: 'localhost']; 0062 % 0063 % Additional parameters: 0064 % 0065 % 'Database' - The database name [default: 'ltpda'] 0066 % 'ID' - A vector of object IDs. [default: []] 0067 % 0068 % From a Miir 0069 % --------------- 0070 % Construct a statespace model out of a MIIR object. 0071 % 0072 % example : sys = ssm(themiir); 0073 % 0074 % From PZ model 0075 % --------------- 0076 % Construct a statespace model by retrieving it from an LTPDA repository. 0077 % 0078 % example : sys=ssm(thepzmodel); 0079 % 0080 % 0081 % From Description 0082 % ---------------- 0083 % Construct a statespace model from a full description of the system. 0084 % 0085 % 'isADescription' >> special filed to tell the constructor which set to use 0086 % 0087 % compulsory fields: 0088 % 'name','ssnames', 'outputnames', 'inputnames', 'timestep', 'amats', ... 0089 % 'bmats', 'cmats', 'dmats', 'paramnames', 'paramvalues' 0090 % 0091 % optionnals fields : 0092 % 'mmats' 'amats_handles' 'bmats_handles' 'cmats_handles' 'dmats_handles'... 0093 % 'inputvarnames' 'ssvarnames' 'ssini' 'outputvarnames' 'paramsigmas' 0094 % 0095 % example : 0096 % name = 'sys'; 0097 % ssnames = {'ss1' 'ss2' 'ss3'}; 0098 % ssvarnames = {{'ssvar1'} {'ssvar2'} {'ssvar31' 'ssvar32'}}; 0099 % inputnames = {'input1' 'input2' 'input3'}; 0100 % inputvarnames = {{'inputvar1'} {'inputvar2'} {'inputvar31' 'inputvar32'}}; 0101 % outputnames = {'output1' 'output2' 'output3'}; 0102 % outputvarnames = {{'outputvar1'} {'outputvar2'} {'outputvar31' 'outputvar32'}}; 0103 % timestep = 0; 0104 % paramnames = {}; 0105 % paramvalues = []; 0106 % amats = cell(3,3); 0107 % bmats = cell(3,3); 0108 % cmats = cell(3,3); 0109 % dmats = cell(3,3); 0110 % amats{1,1} = -1; 0111 % amats{2,2} = -2; 0112 % amats{3,3} = -3*eye(2); 0113 % amats{3,1} = [-1;-3]; 0114 % bmats{1,1} = 1; 0115 % bmats{2,2} = 2; 0116 % bmats{3,3} = 3*eye(2); 0117 % cmats{1,1} = 1; 0118 % cmats{2,2} = 1; 0119 % cmats{3,3} = eye(2); 0120 % dmats{1,3} = [6 6]; 0121 % dmats{2,1} = 6; 0122 % dmats{3,2} = [6;6]; 0123 % sys = ssm(plist('isADescription', '' ,'name', name , ... 0124 % 'timestep', timestep , 'paramnames', paramnames ,'paramvalues', paramvalues ,... 0125 % 'inputnames', inputnames , 'outputnames',outputnames ,'ssnames', ssnames,... 0126 % 'inputvarnames', inputvarnames , 'outputvarnames',outputvarnames ,'ssvarnames', ssvarnames,... 0127 % 'amats', amats ,'bmats', bmats ,'cmats', cmats ,'dmats', dmats )); 0128 % 0129 % 0130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0131 classdef ssm < ltpda_uoh 0132 0133 %-------- Public (read/write) Properties ------- 0134 properties 0135 description = ''; 0136 end % End (read/write) Properties 0137 0138 %-------- Private read-only Properties -------- 0139 properties %(SetAccess = protected) 0140 %l inear system matrices 0141 amats = {}; 0142 mmats = {}; 0143 bmats = {}; 0144 cmats = {}; 0145 dmats = {}; 0146 isnumerical = false; 0147 timestep = 0; 0148 % nonlinear system function handles 0149 amats_handles = {}; 0150 bmats_handles = {}; 0151 cmats_handles = {}; 0152 dmats_handles = {}; 0153 % input variables data array 0154 inputnames = {}; 0155 inputvarnames = {}; 0156 inputsizes = []; 0157 Ninputs = 0; 0158 % state space variables data arrays 0159 ssnames = {}; 0160 ssvarnames = {}; 0161 sssizes = []; 0162 ssini = {}; 0163 Nss = 0; 0164 % output variables data arrays 0165 outputnames = {}; 0166 outputvarnames = {}; 0167 outputsizes = []; 0168 Noutputs = 0; 0169 % parameter data arrays 0170 paramnames = {}; 0171 paramvalues = []; 0172 paramsigmas = []; 0173 Nparams = 0; 0174 end % End read only properties 0175 0176 0177 %-------- Private Properties --------- 0178 properties (GetAccess = protected, SetAccess = protected) 0179 end 0180 0181 methods 0182 0183 end 0184 0185 %-------- Public Methods ------ 0186 methods(Access = public) 0187 %% Class constructor 0188 function s = ssm(varargin) 0189 utils.helper.msg(utils.const.msg.MNAME, ['running ', mfilename]); 0190 % Check the supported version 0191 utils.helper.checkMatlabVersion; 0192 %%% Call superclass 0193 s = s@ltpda_uoh(varargin{:}); %to inherit properties 0194 % Execute appropriate constructor 0195 switch nargin 0196 case 0 % Empty constructor 0197 s.addHistory(ssm.getInfo('ssm', 'None'), plist, {''}, []); 0198 case 1 % Plist, pzmodel, ... 0199 vin = varargin{1}; 0200 if isa(vin, 'ssm') % copy constructor 0201 s = copy(vin, 1); 0202 elseif isstruct(vin) % Struct constructor 0203 fnames = fieldnames(vin); 0204 for jj = 1:length(fnames) 0205 f = fnames{jj}; 0206 s.(f) = vin.(f); 0207 end 0208 elseif isa(vin, 'plist') % constructor with a plist 0209 if isparam(vin, 'Filename') 0210 % filename constructor 0211 s = ssm.ssmFromFilename(vin); 0212 elseif isparam(vin, 'Built-in') 0213 % Construct from built-in 0214 s = ssm.ssmFromBuiltinSystem(vin); 0215 elseif isparam(vin, 'Hostname') 0216 % Retrieve from repository 0217 s = ssm.ssmFromRepository(vin); 0218 elseif isparam(vin, 'amats') 0219 % construct from plist description 0220 s = ssm.ssmFromDescription(vin); 0221 else 0222 display('### Unknown constructor ###') 0223 display('### could not find a valid parameter key ###') 0224 display('### these are : ''Filename'', ''Built-in'' ###') 0225 display('### these are : ''amats'', ''Hostname'' ###') 0226 error('See above message ^^'); 0227 end 0228 elseif isa(vin, 'pzmodel') % Plist constructor 0229 s = ssm.ssmFromPzmodel(vin); 0230 elseif isa(vin, 'miir') % Plist constructor 0231 s = ssm.ssmFromMiir(vin); 0232 elseif ischar(vin) % from file 0233 filename = varargin{1}; 0234 [path, name, ext] = fileparts(filename); 0235 switch ext 0236 case '.mat' 0237 s = load(filename); 0238 s = s.a; 0239 case '.xml' 0240 root_node = xmlread(filename); 0241 s = utils.helper.xmlread(root_node, 'ssm'); 0242 otherwise 0243 error('### Unknown file type.'); 0244 end 0245 else 0246 error(['### Error: ssm constructor can''t handle input of type : ',class(vin)]); 0247 end 0248 % Now validate this object 0249 s = s.validate(); 0250 otherwise 0251 error('### Unknown number of constructor arguments.'); 0252 end 0253 end 0254 %% copying one ssm 0255 varargout = copy(varargin) 0256 %% makes an executable string 0257 varargout = string(varargin) 0258 %% change timestep 0259 varargout = modiftimestep(varargin) 0260 %% change and subsitute parameters 0261 varargout = modifparams(varargin) 0262 %% assemble systems 0263 varargout = assemble(varargin) 0264 %% transform into a pzmodel or a iir 0265 varargout = ssm2iirpz(varargin) 0266 %% transform into ABCD doubles/symb 0267 varargout = double(varargin) 0268 %% transform into a matlab ss object 0269 varargout = ssm2ss(varargin) 0270 %% model modification executing a string 0271 varargout = modify(varargin) 0272 %% simulation 0273 varargout = simulate(varargin) 0274 %% kalman filter 0275 varargout = kalman(varargin) 0276 %% model simplification (states) 0277 varargout = reduce(varargin) 0278 %% model simplification (variables) 0279 varargout = reduce_model(varargin) 0280 %% char 0281 varargout = char(varargin) 0282 %% display 0283 varargout = display(varargin) 0284 %% give minimal realization (right now needs control toolbox) 0285 varargout = minreal(varargin) 0286 %% tells if ssm is stable 0287 varargout = isstable(varargin) 0288 end 0289 0290 %-------- Declaration of private methods -------- 0291 methods (Access = private) 0292 %% completion and error check 0293 varargout = validate(varargin) 0294 end 0295 0296 0297 %-------- Declaration of Public Static methods -------- 0298 methods (Static=true, Access=public) 0299 function ii = getInfo(varargin) 0300 ii = utils.helper.generic_getInfo(varargin{:}, 'ssm'); 0301 end 0302 0303 function out = VEROUT() 0304 out = '$Id: ssm.m,v 1.54 2008/08/21 19:47:16 adrien Exp $'; 0305 end 0306 0307 function out = SETS() 0308 out = {... 0309 'From XML File', ... 0310 'From MAT File', ... 0311 'From Built-in Model', ... 0312 'From Description', ... 0313 'From Plist', ... 0314 'From Repository',... 0315 'From Pzmodel',... 0316 'From Miir'}; 0317 end 0318 0319 function pl = getDefaultPlist(set) 0320 sets = ssm.SETS; 0321 % Select parameter set 0322 switch set 0323 case sets{1} % XML file 0324 pl = plist('filename', ''); 0325 case sets{2} % MAT file 0326 pl = plist('filename', ''); 0327 case sets{3} % built-in 0328 pl = plist('Built-in', 'LPF Dynamics No Params'); 0329 case sets{4} % description 0330 plist('isADescription', '' ,'name','me','ssnames',{'my state'} ,... 0331 'outputnames',{'force'}, 'inputnames',{'air','food'} ,'timestep',{0}, ... 0332 'amats',{-0.001}, 'bmats', {0 ,1},'cmats',{1}, 'dmats',{1 , 0}, ... 0333 'paramnames',{'health'}, 'paramvalues',1,... 0334 ... %second part, here facultative fields: 0335 'mmats', {80}, 'amats_handles',cell(1,1), 'bmats_handles',cell(1,2),... 0336 'cmats_handles',cell(1,1), 'dmats_handles',cell(1,2),... 0337 'inputvarnames',{'02','hamburger'}, ... 0338 'ssvarnames', {'energy left'},'ssini', {'1'}, ... 0339 'outputvarnames', {'force left to click on the mouse'},... 0340 'paramsigmas', 1); 0341 pl = plist(); 0342 case sets{5} % plist 0343 pl = plist('plist', plist()); 0344 case sets{6} % repository 0345 pl = plist('hostname', 'localhost', 'database', 'ltpda', 'ID', []); 0346 case sets{7} % pzmodel 0347 pl = plist(); 0348 case sets{8} % miir 0349 pl = plist(); 0350 otherwise 0351 error('### Unknown parameter set requested.'); 0352 end 0353 end 0354 0355 %% other usefull subroutines 0356 varargout = cellstrfind(c,s,option) 0357 varargout = update_struct(varargin) 0358 %% subroutines for block defined matrix calculus 0359 a_out = cell_recut(a, rowsizes, colsizes) 0360 a_out = cell_fusion(a, rowsizes, colsizes) 0361 c = cell_mult(a,b) 0362 a = cell_add(a,b) 0363 [cell_mat_out, rowsizes_out, colsizes_out] = cell_select(varargin) 0364 %% ssm constructor + predefined model reduction 0365 varargout = ssm_reduced_builtIn(varargin) 0366 end % End public static methods 0367 0368 0369 0370 0371 %-------- Declaration of Private Static methods -------- 0372 methods (Static=true, Access=private) 0373 % Built-in systems 0374 [sys, VERSION] = model_LPF_Dynamics 0375 [sys, VERSION] = model_LPF_Dynamics_noparams 0376 [sys, VERSION] = model_MPS 0377 [sys, VERSION] = model_TMActuation 0378 [sys, VERSION] = model_TMActuation_xcpl 0379 [sys, VERSION] = model_ST_readout 0380 [sys, VERSION] = model_IS_readout 0381 [sys, VERSION] = model_IS_readout_xcpl 0382 [sys, VERSION] = model_Interferometer_readout 0383 [sys, VERSION] = model_Interferometer_readout_xcpl 0384 [sys, VERSION] = model_NSF_solar 0385 [sys, VERSION] = model_NSF_infrared 0386 [sys, VERSION] = model_NSF_TMActuation 0387 [sys, VERSION] = model_NSF_TM 0388 [sys, VERSION] = model_NSF_TM_SC 0389 [sys, VERSION] = model_NSF_Interferometer_readout 0390 [sys, VERSION] = model_NSF_ST_readout 0391 [sys, VERSION] = model_NSF_IS_readout 0392 [sys, VERSION] = model_delay 0393 [sys, VERSION] = model_delay_ST_readout 0394 [sys, VERSION] = model_delay_IS_readout 0395 [sys, VERSION] = model_delay_Ifo_readout 0396 [sys, VERSION] = model_DFACS_5_Science_Mode_1_All_Optical_Readouts 0397 [sys, VERSION] = model_DFACS_4_Science_Mode_2_M1_Performance 0398 [sys, VERSION] = model_DFACS_3_Science_Mode_2_M1_Transition 0399 [sys, VERSION] = model_DFACS_2_Science_Mode_1_M3 0400 [sys, VERSION] = model_DFACS_1_Normal_Mode 0401 [sys, VERSION] = model_standard_system_params 0402 [sys, VERSION] = model_standard_system_noparams 0403 % Rotation operations for dynamics 0404 direction_cosine = T_ZYX_rot(vector) 0405 S = skew(Vector) 0406 B = B_a2w(Vector) 0407 B = B_a2w_inv(Vector) 0408 % retrieve from repository 0409 sys = ssmFromRepository( pl) 0410 % load from file 0411 sys = ssmFromFilename( pl) 0412 % create from built-in system 0413 sys = ssmFromBuiltinSystem( pli) 0414 % create from miir 0415 sys = ssmFromMiir(miirsin) 0416 % create from plist 0417 sys = ssmFromDescription(pl) 0418 % create from pzmodel 0419 sys = ssmFromPzmodel(pzmodelsin) 0420 end 0421 0422 end % End classdef 0423 0424