


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) - plist describing a subsystem
varargin(2) - plist giving new timestep value (param name '')
OUTPUTS: subsys - 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.m,v 1.3 2008/02/25 12:43:44 adrien 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) - plist describing a subsystem 0014 % varargin(2) - plist giving new timestep value (param name '') 0015 % 0016 % OUTPUTS: subsys - 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.m,v 1.3 2008/02/25 12:43:44 adrien 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.m,v 1.3 2008/02/25 12:43:44 adrien Exp $'; 0052 CATEGORY = 'STATESPACE'; 0053 display(['starting ' ALGONAME]); 0054 0055 if isequal( varargin{1}, 'Version') 0056 varargout = VERSION; 0057 return; 0058 elseif isequal(varargin{1}, 'Params') 0059 varargout = plist(); 0060 return; 0061 elseif isequal(varargin{1}, 'Category') 0062 varargout = CATEGORY; 0063 return; 0064 end 0065 0066 0067 %% retriving input data 0068 0069 System = varargin{1}; 0070 NewTimeStep = find(varargin{2},'TIMESTEP'); 0071 % Options = varargin{3}; % to do for white noise!!! problem otherwise because amplitude depends on frequency of noise. 0072 0073 SystemTimestep = find(System,'TIMESTEP'); 0074 AMAT = find(System,'AMAT'); 0075 BMATS = find(System,'BMATS'); 0076 0077 %% take different actions depending on old and new timestep 0078 if SystemTimestep == NewTimeStep 0079 action = 'DoNothing'; 0080 elseif NewTimeStep == 0 0081 action = 'MakeContinuous'; 0082 display('warning because system is sent back to continuous time'); 0083 elseif SystemTimestep == 0 0084 action = 'Discretize'; 0085 elseif floor(NewTimeStep/SystemTimestep) == NewTimeStep/SystemTimestep 0086 action = 'TakeMultiple'; 0087 elseif NewTimeStep > SystemTimestep 0088 action = 'MakeLonger'; 0089 else 0090 action = 'MakeShorter'; 0091 display('warning because system is sent back to shorter time step'); 0092 end 0093 0094 %% proceed with matrix modifications 0095 if isequal(action,'DoNothing') 0096 elseif isequal(action,'Discretize') 0097 A_mat = AMAT{1}; 0098 A_mat_d = expm(A_mat * NewTimeStep); 0099 NSubstep = 15; 0100 A_mat_input_d = zeros( size(A_mat) ); 0101 for i = 1:NSubstep 0102 position = NewTimeStep*(2*i-1)/(NSubstep); 0103 A_mat_input_d = A_mat_input_d + expm( A_mat*position)/NSubstep; 0104 end 0105 AMAT{1} = A_mat_d; 0106 for i=1:length(BMATS) 0107 BMATS{i} = A_mat_input_d * BMATS{i}; 0108 end 0109 elseif isequal(action,'TakeMultiple') 0110 A_mat_1 = AMAT{1}; 0111 multiple = NewTimeStep/SystemTimestep; 0112 A_mat_2 = A_mat_1^multiple; 0113 A_mat_input_2 = zeros( size(A_mat_2) ); 0114 for i = 1:multiple 0115 A_mat_input_2 = A_mat_input_2 + A_mat_2^(i-1); 0116 end 0117 AMAT{1} = A_mat_2; 0118 for i=1:length(BMATS) 0119 BMATS{i} = A_mat_input_2 * BMATS{i}; 0120 end 0121 elseif isequal(action,'MakeContinuous') 0122 A_mat_d = AMAT{1}; 0123 [V, E] = eig(A_mat_d); 0124 A_mat = V * diag(diag(log(E))) * inv(V)/SystemTimestep; 0125 NSubstep = 15; 0126 A_mat_input_d = zeros( size(A_mat) ); 0127 for i = 1:NSubstep 0128 position = NewTimeStep*(2*i-1)/(NSubstep); 0129 A_mat_input_d = A_mat_input_d + expm( A_mat*position)/NSubstep; 0130 end 0131 A_mat_input_d2c = inv(A_mat_input_d); 0132 AMAT{1} = A_mat; 0133 for i=1:length(BMATS) 0134 BMATS{i} = A_mat_input_d2c * BMATS{i}; 0135 end 0136 elseif isequal(action,'MakeLonger')||isequal(action,'MakeShorter') 0137 A_mat_1 = AMAT{1}; 0138 [V, E] = eig(A_mat_1); 0139 A_mat = V * diag(diag(log(E))) * inv(V); 0140 A_mat_2 = expm( A_mat * NewTimeStep/SystemTimestep); 0141 NSubstep = 15; 0142 A_mat_input_1 = zeros( size(A_mat) ); 0143 A_mat_input_2 = zeros( size(A_mat) ); 0144 for i = 1:NSubstep 0145 position_1 = NewTimeStep*(2*i-1)/(NSubstep); 0146 position_2 = SystemTimestep*(2*i-1)/(NSubstep); 0147 A_mat_input_1 = A_mat_input_1 + expm( A_mat*position_1 )/NSubstep; 0148 A_mat_input_2 = A_mat_input_2 + expm( A_mat*position_2 )/NSubstep; 0149 end 0150 AMAT{1} = A_mat_2; 0151 A_mat_input_2inv = inv(A_mat_input_2); 0152 for i=1:length(BMATS) 0153 BMATS{i} = A_mat_input_2 * A_mat_input_2inv * BMATS{i}; 0154 end 0155 end 0156 0157 %% Save Matrix modifications 0158 System = pset(System,'AMAT',AMAT); 0159 System = pset(System,'BMATS',BMATS); 0160 varargout = pset(System,'TIMESTEP',NewTimeStep); 0161 end