timeModify is the generic function to decalre or load a subsystem. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: ltpda_ss_modify_time_setup enables to change the timestep values of a subsystem, and updates the A and B matrices suppsing there is no aliasing issue. Otherwise (eg for white noise) this has to be treated another way. CALL: subsys = makeSubsystem(varargin) INPUTS: 2 possibilites varargin(1) - (array of) plist describing a subsystem varargin(2) - (array of) plist giving new timestep value (param name '') OUTPUTS: subsys - (array of) subsystem dscribed by a plist subsystem plist format (More updated infos might be available in the test_subsys function): plist('TYPE', TYPE ,'NAME', NAME ,'TIMESTEP', TIMESTEP ,... 'PARAMNAMES', PARAMNAMES ,'PARAMVALUES', PARAMVALUES ,'PARAMSIGMAS', PARAMSIGMAS ,... 'NBINPUTS', NBINPUTS ,'INPUTNAMES', INPUTNAMES ,'INPUTSIZES', INPUTSIZES ,'INPUTISUSED', INPUTISUSED ,... 'AMAT', AMAT ,'BMATS', BMATS ,'CMAT', CMAT ,'DMATS', DMATS );% PARAMETERS: 'TYPE' should be 'SUBSYSTEM' 'NAME' is a string 'TIMESTEP' is a real positive integer, set to zero in continuous case 'PARAMNAMES' cell array of strings describing parameter variables 'PARAMVALUES' array of doubles (means expected of parameters) 'PARAMSIGMAS' array of doubles (variance expected of parameters) 'NBINPUTS' integer number of inputs 'INPUTNAMES' cell array of strings (name of the inputs) 'INPUTSIZES'array of integers (nb of dimensions of the inputs), 'INPUTISUSED' double array (binary to indicate which inputs are used) 'AMAT' cell array (contains A matrix) 'BMATS' cell array (contains B matrices) 'CMAT' cell array (contains C matrix) 'DMATS' cell array (contains D matrices) ***** THERE ARE NO DEFAULT PARAMETERS ***** VERSION: $Id: ltpda_ss_modify_time_setup.html,v 1.4 2008/03/31 10:27:35 hewitson Exp $ HISTORY: 08-02-2008 A Grynagier 24-01-2008 A Grynagier Creation 16-01-2008 A Grynagier to do : modify for noise shape filter case or HF inputs with aliasing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % standard calls for LTPDA function data
0001 function varargout = ltpda_ss_modify_time_setup(varargin) 0002 % timeModify is the generic function to decalre or load a subsystem. 0003 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0004 % 0005 % DESCRIPTION: ltpda_ss_modify_time_setup enables to change the timestep 0006 % values of a subsystem, and updates the A and B matrices suppsing there is 0007 % no aliasing issue. Otherwise (eg for white noise) this has to be treated 0008 % another way. 0009 % 0010 % CALL: subsys = makeSubsystem(varargin) 0011 % 0012 % INPUTS: 2 possibilites 0013 % varargin(1) - (array of) plist describing a subsystem 0014 % varargin(2) - (array of) plist giving new timestep value (param name '') 0015 % 0016 % OUTPUTS: subsys - (array of) subsystem dscribed by a plist 0017 % 0018 % subsystem plist format (More updated infos might be available in the 0019 % test_subsys function): 0020 % plist('TYPE', TYPE ,'NAME', NAME ,'TIMESTEP', TIMESTEP ,... 0021 % 'PARAMNAMES', PARAMNAMES ,'PARAMVALUES', PARAMVALUES ,'PARAMSIGMAS', PARAMSIGMAS ,... 0022 % 'NBINPUTS', NBINPUTS ,'INPUTNAMES', INPUTNAMES ,'INPUTSIZES', INPUTSIZES ,'INPUTISUSED', INPUTISUSED ,... 0023 % 'AMAT', AMAT ,'BMATS', BMATS ,'CMAT', CMAT ,'DMATS', DMATS );% PARAMETERS: 0024 % 'TYPE' should be 'SUBSYSTEM' 0025 % 'NAME' is a string 0026 % 'TIMESTEP' is a real positive integer, set to zero in continuous case 0027 % 'PARAMNAMES' cell array of strings describing parameter variables 0028 % 'PARAMVALUES' array of doubles (means expected of parameters) 0029 % 'PARAMSIGMAS' array of doubles (variance expected of parameters) 0030 % 'NBINPUTS' integer number of inputs 0031 % 'INPUTNAMES' cell array of strings (name of the inputs) 0032 % 'INPUTSIZES'array of integers (nb of dimensions of the inputs), 0033 % 'INPUTISUSED' double array (binary to indicate which inputs are used) 0034 % 'AMAT' cell array (contains A matrix) 0035 % 'BMATS' cell array (contains B matrices) 0036 % 'CMAT' cell array (contains C matrix) 0037 % 'DMATS' cell array (contains D matrices) 0038 % ***** THERE ARE NO DEFAULT PARAMETERS ***** 0039 % 0040 % VERSION: $Id: ltpda_ss_modify_time_setup.html,v 1.4 2008/03/31 10:27:35 hewitson Exp $ 0041 % 0042 % HISTORY: 08-02-2008 A Grynagier 0043 % 24-01-2008 A Grynagier 0044 % Creation 16-01-2008 A Grynagier 0045 % 0046 % to do : modify for noise shape filter case or HF inputs with aliasing 0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0048 %% standard calls for LTPDA function data 0049 0050 ALGONAME = mfilename; 0051 VERSION = '$Id: ltpda_ss_modify_time_setup.html,v 1.4 2008/03/31 10:27:35 hewitson Exp $'; 0052 CATEGORY = 'STATESPACE'; 0053 display(['starting ' ALGONAME]); 0054 0055 if not(isempty(varargin)) 0056 if isequal( varargin{1}, 'Version') 0057 varargout = VERSION; 0058 return; 0059 elseif isequal(varargin{1}, 'Params') 0060 varargout = plist('TIMESTEP',0.1); 0061 return; 0062 elseif isequal(varargin{1}, 'Category') 0063 varargout = CATEGORY; 0064 return; 0065 end 0066 else 0067 error('no input argument!') 0068 end 0069 0070 systems_out = plist(); 0071 Systems = varargin{1}; 0072 plists_options = varargin{2}; 0073 for i_system = 1:length(Systems) 0074 for i_option = 1:length(plists_options) 0075 System = Systems(i_system); 0076 plist_options = plists_options(i_option); 0077 0078 %% retrieving input data 0079 plist_options = combine(plist_options, plist('TIMESTEP',0.1)); 0080 NewTimeStep = find(varargin{2},'TIMESTEP'); 0081 % Options = varargin{3}; % to do for white noise!!! problem otherwise because amplitude depends on frequency of noise. 0082 0083 SystemTimestep = find(System,'TIMESTEP'); 0084 AMAT = find(System,'AMAT'); 0085 BMATS = find(System,'BMATS'); 0086 0087 %% take different actions depending on old and new timestep 0088 if SystemTimestep == NewTimeStep 0089 action = 'DoNothing'; 0090 elseif NewTimeStep == 0 0091 action = 'MakeContinuous'; 0092 display('warning because system is sent back to continuous time'); 0093 elseif SystemTimestep == 0 0094 action = 'Discretize'; 0095 elseif floor(NewTimeStep/SystemTimestep) == NewTimeStep/SystemTimestep 0096 action = 'TakeMultiple'; 0097 elseif NewTimeStep > SystemTimestep 0098 action = 'MakeLonger'; 0099 else 0100 action = 'MakeShorter'; 0101 display('warning because system is sent back to shorter time step'); 0102 end 0103 0104 %% proceed with matrix modifications 0105 if isequal(action,'DoNothing') 0106 elseif isequal(action,'Discretize') 0107 A_mat = AMAT{1}; 0108 A_mat_d = expm(A_mat * NewTimeStep); 0109 NSubstep = 15; 0110 A_mat_input_d = zeros( size(A_mat) ); 0111 for i = 1:NSubstep 0112 position = NewTimeStep*(2*i-1)/(NSubstep); 0113 A_mat_input_d = A_mat_input_d + expm( A_mat*position)/NSubstep; 0114 end 0115 AMAT{1} = A_mat_d; 0116 for i=1:length(BMATS) 0117 BMATS{i} = A_mat_input_d * BMATS{i}; 0118 end 0119 elseif isequal(action,'TakeMultiple') 0120 A_mat_1 = AMAT{1}; 0121 multiple = NewTimeStep/SystemTimestep; 0122 A_mat_2 = A_mat_1^multiple; 0123 A_mat_input_2 = zeros( size(A_mat_2) ); 0124 for i = 1:multiple 0125 A_mat_input_2 = A_mat_input_2 + A_mat_2^(i-1); 0126 end 0127 AMAT{1} = A_mat_2; 0128 for i=1:length(BMATS) 0129 BMATS{i} = A_mat_input_2 * BMATS{i}; 0130 end 0131 elseif isequal(action,'MakeContinuous') 0132 A_mat_d = AMAT{1}; 0133 [V, E] = eig(A_mat_d); 0134 A_mat = V * diag(diag(log(E))) * inv(V)/SystemTimestep; 0135 NSubstep = 15; 0136 A_mat_input_d = zeros( size(A_mat) ); 0137 for i = 1:NSubstep 0138 position = NewTimeStep*(2*i-1)/(NSubstep); 0139 A_mat_input_d = A_mat_input_d + expm( A_mat*position)/NSubstep; 0140 end 0141 A_mat_input_d2c = inv(A_mat_input_d); 0142 AMAT{1} = A_mat; 0143 for i=1:length(BMATS) 0144 BMATS{i} = A_mat_input_d2c * BMATS{i}; 0145 end 0146 elseif isequal(action,'MakeLonger')||isequal(action,'MakeShorter') 0147 A_mat_1 = AMAT{1}; 0148 [V, E] = eig(A_mat_1); 0149 A_mat = V * diag(diag(log(E))) * inv(V); 0150 A_mat_2 = expm( A_mat * NewTimeStep/SystemTimestep); 0151 NSubstep = 15; 0152 A_mat_input_1 = zeros( size(A_mat) ); 0153 A_mat_input_2 = zeros( size(A_mat) ); 0154 for i = 1:NSubstep 0155 position_1 = NewTimeStep*(2*i-1)/(NSubstep); 0156 position_2 = SystemTimestep*(2*i-1)/(NSubstep); 0157 A_mat_input_1 = A_mat_input_1 + expm( A_mat*position_1 )/NSubstep; 0158 A_mat_input_2 = A_mat_input_2 + expm( A_mat*position_2 )/NSubstep; 0159 end 0160 AMAT{1} = A_mat_2; 0161 A_mat_input_2inv = inv(A_mat_input_2); 0162 for i=1:length(BMATS) 0163 BMATS{i} = A_mat_input_2 * A_mat_input_2inv * BMATS{i}; 0164 end 0165 end 0166 0167 %% Save Matrix modifications 0168 System = pset(System,'AMAT',AMAT); 0169 System = pset(System,'BMATS',BMATS); 0170 end 0171 systems_out(i_system, i_option) = pset(System,'TIMESTEP',NewTimeStep); 0172 end 0173 varargout = {systems_out}; 0174 end