0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1 % TDFIT fit a set of smodels to a set of input and output signals..
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 3 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 4 % DESCRIPTION: TDFIT fit a set of smodels to a set of input and output signals.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 5 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 6 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 7 % CALL: b = tdfit(outputs, pl)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 8 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 9 % INPUTS: outputs - the AOs representing the outputs of a system.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 10 % pl - parameter list (see below)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 11 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 12 % OUTPUTs: b - a pest object containing the best-fit parameters,
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 13 % goodness-of-fit reduced chi-squared, fit degree-of-freedom
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 14 % covariance matrix and uncertainties. Additional
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 15 % quantities, like the Information Matrix, are contained
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 16 % within the procinfo. The best-fit model can be evaluated
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 17 % from pest\eval.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 18 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 19 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'tdfit')">Parameters Description</a>
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 20 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 21 % EXAMPLES:
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 22 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 23 % % 1) Sine-wave stimulus of a simple system
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 24 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 25 % % Sine-wave data
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 26 % data = ao(plist('tsfcn', 'sin(2*pi*3*t) + 0.01*randn(size(t))', 'fs', 100, 'nsecs', 10));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 27 % data.setName;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 28 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 29 % % System filter
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 30 % pzm = pzmodel(1, 1, 10);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 31 % f = miir(pzm);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 32 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 33 % % Make output signal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 34 % dataf = filter(data, f);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 35 % dataf.setName;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 36 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 37 % % fit model to output
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 38 % mdl = smodel('(a.*(b + 2*pi*i*f)) ./ (b*(a + 2*pi*i*f))');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 39 % mdl.setParams({'a', 'b'}, {2*pi 10*2*pi});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 40 % mdl.setXvar('f');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 41 % params = tdfit(dataf, plist('inputs', data, 'models', mdl, 'P0', [1 1]));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 42 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 43 % % Evaluate fit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 44 % mdl.setValues(params);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 45 % BestModel = fftfilt(data, mdl);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 46 % BestModel.setName;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 47 % iplot(data, dataf, BestModel, plist('linestyles', {'-', '-', '--'}))
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 48 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 49 % % recovered parameters (in Hz)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 50 % params.y/2/pi
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 51 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 52 % VERSION: $Id: tdfit.m,v 1.45 2011/05/26 12:57:27 congedo Exp $
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 53 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 54 % HISTORY: 05-10-2009 G. Congedo
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 55 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 57
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 58 % 'WhiteningFilters' - Use filter banks for whitening the outputs.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 59 % Note: you must fit the two channels at the same time
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 60 % and supply four filter banks.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 61
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 62
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 63 function varargout = tdfit(varargin)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 64
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 65 % Check if this is a call for parameters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 66 if utils.helper.isinfocall(varargin{:})
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 67 varargout{1} = getInfo(varargin{3});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 68 return
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 69 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 70
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 71 import utils.const.*
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 72 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 73
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 74 % Collect input variable names
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 75 in_names = cell(size(varargin));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 76 for ii = 1:nargin,in_names{ii} = inputname(ii);end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 77
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 78 % Collect all AOs and plists
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 79 [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 80 [pl, pl_invars, rest] = utils.helper.collect_objects(rest, 'plist', in_names);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 81
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 82 if nargout == 0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 83 error('### tdfit cannot be used as a modifier. Please give an output variable.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 84 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 85
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 86 % combine plists
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 87 pl = parse(pl, getDefaultPlist());
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 88
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 89 outputs = copy(as,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 90
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 91 % Extract necessary parameters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 92 inputs = pl.find('inputs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 93 TFmodels = pl.find('models');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 94 WhFlts = pl.find('WhFlts');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 95 Ncut = pl.find('Ncut');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 96 P0 = pl.find('P0');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 97 pnames = pl.find('pnames');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 98 inNames = pl.find('innames');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 99 outNames = pl.find('outnames');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 100 % ADDP = find(pl, 'ADDP');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 101 userOpts = pl.find('OPTSET');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 102 weights = find(pl, 'WEIGHTS');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 103 FitUnc = pl.find('FitUnc');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 104 UncMtd = pl.find('UncMtd');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 105 linUnc = pl.find('linUnc');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 106 FastHess = pl.find('FastHess');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 107 SymDiff = pl.find('SymDiff');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 108 DiffOrder = pl.find('DiffOrder');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 109 lb = pl.find('LB');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 110 ub = pl.find('UB');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 111 MCsearch = pl.find('MonteCarlo');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 112 Npoints = pl.find('Npoints');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 113 Noptims = pl.find('Noptims');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 114 Algorithm = pl.find('Algorithm');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 115 padRatio = pl.find('PadRatio');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 116 SISO = pl.find('SingleInputSingleOutput');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 117 GradSearch= pl.find('GradSearch');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 118 estimator = pl.find('estimator');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 119
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 120 % Convert yes/no, true/false, etc. to booleans
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 121 FitUnc = utils.prog.yes2true(FitUnc);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 122 linUnc = utils.prog.yes2true(linUnc);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 123 MCsearch = utils.prog.yes2true(MCsearch);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 124 SymDiff = utils.prog.yes2true(SymDiff);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 125 SISO = utils.prog.yes2true(SISO);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 126 GradSearch = utils.prog.yes2true(GradSearch);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 127
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 128 % consistency check on inputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 129 if isempty(TFmodels)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 130 error('### please specify at least a transfer function or a SSM model')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 131 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 132 if isempty(inputs)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 133 error('### please give the inputs of the system')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 134 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 135 if isempty(outputs)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 136 error('### please give the outputs of the system')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 137 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 138 % if isempty(pnames) || ~iscellstr(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 139 % error('### please give the parameter names in a cell-array of strings')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 140 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 141
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 142 % look for aliases within the models
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 143 if ~isa(TFmodels,'ssm')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 144 aliasNames = TFmodels(1).aliasNames;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 145 aliasValues = TFmodels(1).aliasValues;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 146 for ii=2:numel(TFmodels)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 147 if ~isempty(TFmodels(ii).aliasNames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 148 aliasNames = union(aliasNames,TFmodels(ii).aliasNames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 149 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 150 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 151 if ~isempty(aliasNames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 152 for kk=1:numel(aliasNames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 153 for ii=1:numel(TFmodels)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 154 ix = strcmp(TFmodels(ii).aliasNames,aliasNames{kk});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 155 if sum(ix)==0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 156 continue;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 157 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 158 aliasValues{kk} = TFmodels(ii).aliasValues{ix};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 159 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 160 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 161 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 162 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 163 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 164
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 165 % common params set
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 166 if isa(TFmodels, 'smodel')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 167 [TFmodels,pnames,P0] = cat_mdls(TFmodels,pnames,P0);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 168 elseif isa(TFmodels, 'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 169 [TFmodels,pnames,P0] = cat_mdls(TFmodels.objs,pnames,P0);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 170 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 171
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 172 % if isempty(P0) || ~isnumeric(P0) && ~MCsearch
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 173 % if isa(TFmodels, 'smodel')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 174 % if ~isempty(TFmodels(1).values)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 175 % P0 = TFmodels.values;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 176 % P0 = cell2mat(P0);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 177 % if numel(P0)~=numel(TFmodels(1).params)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 178 % error('### numbers of parameter values and names do not match')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 179 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 180 % else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 181 % error('### please give the initial guess in a numeric array')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 182 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 183 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 184 % if isa(TFmodels, 'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 185 % if ~isempty(TFmodels.objs(1).values)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 186 % P0 = TFmodels.objs(1).values;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 187 % P0 = cell2mat(P0);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 188 % if numel(P0)~=numel(TFmodels.objs(1).params)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 189 % error('### numbers of parameter values and names do not match')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 190 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 191 % else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 192 % error('### please give the initial guess in a numeric array')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 193 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 194 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 195 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 196 if ~isnumeric(lb) || ~isnumeric(ub)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 197 error('### please give lower and upper bounds in a numeric array')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 198 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 199 if numel(lb)~=numel(ub)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 200 error('### please give lower and upper bounds of the same length')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 201 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 202 if isa(TFmodels, 'smodel')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 203 pnames = TFmodels(1).params;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 204 Np = numel(pnames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 205 % for kk=2:numel(TFmodels)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 206 % if numel(TFmodels(kk).params)~=Np
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 207 % error('### number of parameters must be the same for all transfer function models')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 208 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 209 % if ~strcmp(TFmodels(kk).params,pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 210 % error('### all transfer function models must have the same parameters')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 211 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 212 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 213 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 214 if isa(TFmodels, 'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 215 pnames = TFmodels.objs(1).params;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 216 Np = numel(pnames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 217 for kk=2:(TFmodels.nrows*TFmodels.ncols)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 218 if numel(TFmodels.objs(kk).params)~=Np
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 219 error('### number of parameters must be the same for all transfer function models')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 220 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 221 if ~strcmp(TFmodels.objs(kk).params,pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 222 error('### all transfer function models must have the same parameters')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 223 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 224 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 225 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 226 if isa(TFmodels, 'ssm') && isempty(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 227 pnames = getKeys(TFmodels.params);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 228 Np = numel(pnames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 229 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 230
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 231 % check TFmodels, inputs and outputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 232 Nin = numel(inputs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 233 Nout = numel(outputs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 234 NTFmodels = numel(TFmodels);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 235 if isa(TFmodels, 'smodel') & size(TFmodels)~=[Nout,Nin]
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 236 error('### the size of the transfer function does not match with the number of inputs and outputs')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 237 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 238 if size(inputs)~=[Nin,1]
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 239 inputs = inputs';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 240 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 241 if size(outputs)~=[Nout,1]
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 242 outputs = outputs';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 243 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 244
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 245 % checks on inputs and outputs consistency
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 246 inLen = inputs(1).len;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 247 inXdata = inputs(1).x;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 248 inFs = inputs(1).fs;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 249 for kk=2:Nin
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 250 if inputs(kk).len~=inLen
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 251 error('### all inputs must have the same length')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 252 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 253 if inputs(kk).x~=inXdata
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 254 error('### x-fields of all inputs must be the same')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 255 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 256 if inputs(kk).fs~=inFs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 257 error('### fs-fields of all inputs must be the same')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 258 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 259 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 260 outLen = outputs(1).len;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 261 outXdata = outputs(1).x;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 262 outFs = outputs(1).fs;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 263 for kk=2:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 264 if outputs(kk).len~=outLen
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 265 error('### all outputs must have the same length')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 266 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 267 if outputs(kk).x~=outXdata
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 268 error('### x-fields of all outputs must be the same')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 269 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 270 if outputs(kk).fs~=outFs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 271 error('### fs-fields of all outputs must be the same')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 272 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 273 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 274 if inLen~=outLen
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 275 error('### inputs and outputs must have the same length')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 276 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 277 if inXdata~=outXdata
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 278 error('### x-fields of inputs and outputs must be the same')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 279 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 280 if inFs~=outFs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 281 error('### fs-fields of inputs and outputs must be the same')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 282 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 283
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 284 % check Whitening Filters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 285 Wf = ~isempty(WhFlts);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 286 Nwf = numel(WhFlts);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 287 if Wf
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 288 if isempty(Ncut)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 289 Ncut = 100;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 290 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 291 for ii=1:numel(WhFlts)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 292 if ~(isa(WhFlts(ii),'matrix')||isa(WhFlts(ii),'filterbank'))
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 293 error('### whitening filters must be array of matrix or filterbank class')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 294 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 295 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 296 if Nwf~=Nout % size(WhFlts)~=[Nout,Nout]
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 297 error('### the size of the whitening filter array does not match with the number of outputs to be filtered')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 298 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 299 % extract poles and residues
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 300 B = cell(Nout,1); % cell(Nout,Nin);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 301 A = B;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 302 for ii=1:Nwf
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 303 if isa(WhFlts(ii),'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 304 Nflt = max(WhFlts(ii).osize);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 305 elseif isa(WhFlts(ii),'filterbank')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 306 Nflt = numel(WhFlts(ii).filters);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 307 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 308 B{ii} = zeros(Nflt,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 309 A{ii} = B{ii};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 310 for jj=1:Nflt
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 311 if isa(WhFlts(ii),'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 312 B{ii}(jj) = WhFlts(ii).objs(jj).b(2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 313 A{ii}(jj) = WhFlts(ii).objs(jj).a(1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 314 elseif isa(WhFlts(ii),'filterbank')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 315 B{ii}(jj) = WhFlts(ii).filters(jj).b(2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 316 A{ii}(jj) = WhFlts(ii).filters(jj).a(1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 317 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 318 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 319 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 320 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 321
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 322
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 323 % Number of data before padding
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 324 Ndata = inLen;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 325 fs = inFs;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 326 % nsecs = Ndata/fs;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 327
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 328 % Extract inputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 329 inYdata = inputs.y;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 330 if size(inYdata)~=[inLen,Nin]
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 331 inYdata = inYdata';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 332 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 333 outYdata = outputs.y;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 334 if size(outYdata)~=[outLen,Nout]
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 335 outYdata = outYdata';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 336 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 337
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 338
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 339 if isa(TFmodels, 'smodel') || isa(TFmodels, 'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 340
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 341 % Zero-pad inputs before parameter estimation.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 342 % Pad-ratio is defined as the ratio between the number of zero-padding
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 343 % points and the data length
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 344
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 345 if ~isempty(padRatio)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 346 if ~isnumeric(padRatio)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 347 error('### please give a numeric pad ratio')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 348 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 349 if padRatio~=0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 350 Npad = round(padRatio * inLen);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 351 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 352 Npad = 0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 353 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 354 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 355 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 356 Npad = 0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 357 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 358
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 359 NdataPad = Ndata + Npad;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 360 Nfft = NdataPad; % 2^nextpow2(NdataPad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 361 Npad = Nfft - Ndata;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 362
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 363 zeroPad = zeros(Npad,Nin);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 364 inYdataPad = [inYdata;zeroPad];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 365
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 366 % Fft inputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 367 inFfts = fft(inYdataPad,Nfft);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 368 % zero through fs/2
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 369 % inFfts = inFfts(1:Nfft/2+1,:);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 370
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 371 % Sample TFmodels on fft-frequencies
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 372 % zero through fs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 373 ff = (0:(Nfft-1))'.*fs./Nfft;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 374 % zero through fs/2
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 375 % ff = [0:(Nfft/2)]'.*fs/(Nfft/2+1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 376 % ff = fs/2*linspace(0,1,Nfft/2+1)';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 377 for kk=1:NTFmodels
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 378 TFmodels(kk).setXvar('f');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 379 TFmodels(kk).setXvals(ff);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 380 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 381
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 382 % set values for aliases
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 383 if ~isempty(aliasNames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 384 for kk=1:numel(aliasNames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 385 aliasValues{kk}.setXvar('f');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 386 aliasValues{kk}.setXvals(ff);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 387 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 388 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 389 % assign aliases to variables
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 390 aliasTrue = 0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 391 if ~isempty(aliasNames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 392 alias = cell(numel(aliasNames),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 393 for kk=1:numel(aliasNames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 394 alias{kk} = aliasValues{kk}.double;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 395 % assignin('caller',aliasNames{kk},aliasValues{kk}.double);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 396 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 397 aliasTrue = 1;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 398 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 399
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 400 % Extract function_handles from TFmodels
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 401 TFmodelFuncs = cell(size(TFmodels));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 402 for ii=1:NTFmodels
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 403 % TFmodelFuncs{ii} = TFmodels(ii).fitfunc;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 404 % TFmodelFuncs{ii} =
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 405 % @(x)eval_mdl(TFmodels(ii).expr.s,TFmodels(ii).xvar,TFmodels(ii).xvals,TFmodels(ii).params,x);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 406 fcnstr = doSubsPnames(TFmodels(ii).expr.s,TFmodels(ii).params);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 407 if aliasTrue
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 408 fcnstr = doSubsAlias(fcnstr,aliasNames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 409 TFmodelFuncs{ii} = ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 410 eval_mdl_alias(fcnstr,TFmodels(ii).xvar{1},TFmodels(ii).xvals{1},alias);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 411 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 412 TFmodelFuncs{ii} = ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 413 eval_mdl(fcnstr,TFmodels(ii).xvar{1},TFmodels(ii).xvals{1});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 414 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 415 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 416
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 417 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 418
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 419 % If requested, compute the analytical gradient
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 420 if SymDiff || linUnc && (isa(TFmodels, 'smodel') || isa(TFmodels, 'matrix'))
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 421 % compute symbolic 1st-order differentiation
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 422 TFmodelDFuncsSmodel = cell(numel(pnames),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 423 for ll=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 424 for ss=1:size(TFmodels,1)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 425 for tt=1:size(TFmodels,2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 426 TFmodelDFuncsSmodel{ll}(ss,tt) = diff(TFmodels(ss,tt),pnames{ll});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 427 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 428 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 429 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 430 % extract anonymous function
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 431 TFmodelDFuncs = cell(numel(pnames),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 432 for ll=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 433 TFmodelDFuncs{ll} = cell(size(TFmodels));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 434 for ii=1:NTFmodels
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 435 if ~isempty(TFmodelDFuncsSmodel{ll})
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 436 fcnstr = doSubsPnames(TFmodelDFuncsSmodel{ll}(ii).expr.s,TFmodelDFuncsSmodel{ll}(ii).params);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 437 if aliasTrue
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 438 fcnstr = doSubsAlias(fcnstr,aliasNames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 439 TFmodelDFuncs{ll}{ii} = ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 440 eval_mdl_alias(fcnstr,TFmodelDFuncsSmodel{ll}(ii).xvar{1},TFmodelDFuncsSmodel{ll}(ii).xvals{1},alias);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 441 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 442 TFmodelDFuncs{ll}{ii} = ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 443 eval_mdl(fcnstr,TFmodelDFuncsSmodel{ll}(ii).xvar{1},TFmodelDFuncsSmodel{ll}(ii).xvals{1});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 444 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 445 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 446 TFmodelDFuncs{ll}{ii} = @(x)0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 447 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 448 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 449 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 450 if DiffOrder==2
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 451 % compute symbolic 2nd-order differentiation
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 452 TFmodelHFuncsSmodel = cell(numel(pnames));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 453 % for ii=1:NTFmodels
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 454 % p = TFmodels(ii).params;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 455 for mm=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 456 for ll=1:mm
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 457 for ss=1:size(TFmodels,1)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 458 for tt=1:size(TFmodels,2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 459 TFmodelHFuncsSmodel{ll,mm}(ss,tt) = diff(TFmodelDFuncsSmodel{ll}(ss,tt),pnames{mm});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 460 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 461 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 462 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 463 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 464 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 465 % extract anonymous function
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 466 TFmodelHFuncs = cell(numel(pnames));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 467 for mm=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 468 for ll=1:mm
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 469 TFmodelHFuncs{ll,mm} = cell(size(TFmodels));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 470 for ii=1:NTFmodels
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 471 if ~isempty(TFmodelHFuncsSmodel{ll,mm})
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 472 % TFmodelHFuncs{ll,mm}{ii} = TFmodelHFuncsSmodel{ii}(ll,mm).fitfunc; % inverted indexes are for practicalities
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 473 fcnstr = doSubsPnames(TFmodelHFuncsSmodel{ll,mm}(ii).expr.s,TFmodelHFuncsSmodel{ll,mm}(ii).params);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 474 if aliasTrue
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 475 fcnstr = doSubsAlias(fcnstr,aliasNames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 476 TFmodelHFuncs{ll,mm}{ii} = ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 477 eval_mdl_alias(fcnstr,TFmodelHFuncsSmodel{ll,mm}(ii).xvar{1},TFmodelHFuncsSmodel{ll,mm}(ii).xvals{1},alias);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 478 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 479 TFmodelHFuncs{ll,mm}{ii} = ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 480 eval_mdl(fcnstr,TFmodelHFuncsSmodel{ll,mm}(ii).xvar{1},TFmodelHFuncsSmodel{ll,mm}(ii).xvals{1});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 481 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 482 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 483 TFmodelHFuncs{ll,mm}{ii} = @(x)0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 484 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 485 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 486 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 487 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 488 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 489 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 490
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 491 % Build index for faster computation
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 492
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 493 if isa(TFmodels,'smodel')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 494 TFidx = compIdx(inYdata, Nout, TFmodels);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 495 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 496 if exist('TFmodelDFuncsSmodel','var')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 497 TFDidx = cell(numel(pnames),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 498 for ll=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 499 TFDidx{ll} = compIdx(inYdata, Nout, TFmodelDFuncsSmodel{ll});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 500 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 501 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 502 if exist('TFmodelHFuncsSmodel','var')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 503 TFHidx = cell(numel(pnames));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 504 for mm=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 505 for ll=1:mm
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 506 TFHidx{ll,mm} = compIdx(inYdata, Nout, TFmodelHFuncsSmodel{ll,mm});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 507 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 508 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 509 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 510
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 511
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 512 % Construct the output function handles from TFmodels as funtion of
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 513 % parameters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 514 % if ~Wf
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 515 outModelFuncs = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 516 % if Nout>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 517 if isa(TFmodels, 'smodel') || isa(TFmodels, 'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 518 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 519 if SISO
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 520 outModelFuncs{ii} = @(x)mdl_fftfilt_SISO(x, inFfts(:,ii), TFmodelFuncs{ii}, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 521 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 522 % outModelFuncs{ii} = @(x)mdl_fftfilt(x, ii, inFfts, TFmodelFuncs, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 523 outModelFuncs{ii} = @(x)mdl_fftfilt2(x, ii, inFfts, size(inFfts), TFmodelFuncs, TFidx, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 524 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 525 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 526 elseif isa(TFmodels, 'ssm')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 527 SSMmodels = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 528 plsym = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 529 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 530 plsym{ii} = plist('return outputs', outNames{ii}, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 531 'AOS VARIABLE NAMES', inNames{ii}, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 532 'AOS', inputs(ii), ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 533 'reorganize', false, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 534 'set', 'for simulate');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 535
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 536 % SSMmodelOptim = TFmodels.reorganize(plsym{ii});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 537 SSMmodels{ii} = TFmodels.reorganize(plsym{ii});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 538 % SSMmodels{ii} = SSMmodelOptim.clearNumParams;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 539
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 540 outModelFuncs{ii} = @(x)mdl_ssm(x, pnames, inputs(ii), SSMmodels{ii}, plsym{ii});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 541 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 542 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 543 % else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 544 % outModelFuncs{1} = @(x)mdl_fftfilt(x, ii, inFfts, TFmodelFuncs, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 545 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 546 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 547
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 548 % In case of symbolic differentiation, construct the output derivatives
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 549 if SymDiff || linUnc
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 550 outModelDFuncs = cell(numel(pnames),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 551 for ll=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 552 outModelDFuncs{ll} = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 553 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 554 if SISO
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 555 outModelDFuncs{ll}{ii} = @(x)mdl_fftfilt_SISO(x, inFfts(:,ii), TFmodelDFuncs{ll}{ii}, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 556 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 557 % outModelDFuncs{ll}{ii} = @(x)mdl_fftfilt(x, ii, inFfts, TFmodelDFuncs{ll}, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 558 outModelDFuncs{ll}{ii} = @(x)mdl_fftfilt2(x, ii, inFfts, size(inFfts), TFmodelDFuncs{ll}, TFDidx{ll}, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 559 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 560 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 561 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 562 if DiffOrder==2
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 563 outModelHFuncs = cell(numel(pnames));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 564 for mm=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 565 for ll=1:mm
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 566 outModelHFuncs{ll,mm} = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 567 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 568 if SISO
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 569 outModelHFuncs{ll,mm}{ii} = @(x)mdl_fftfilt_SISO(x, inFfts(:,ii), TFmodelFuncs{ll,mm}{ii}, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 570 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 571 % outModelHFuncs{ll,mm}{ii} = @(x)mdl_fftfilt(x, ii, inFfts, TFmodelHFuncs{ll,mm}, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 572 outModelHFuncs{ll,mm}{ii} = @(x)mdl_fftfilt2(x, ii, inFfts, size(inFfts), TFmodelHFuncs{ll,mm}, TFHidx{ll,mm}, Npad);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 573 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 574 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 575 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 576 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 577 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 578 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 579
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 580 % In case the whitening filters are provided do a filtering both on
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 581 % models and data
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 582 if Wf
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 583 % filter models
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 584 outModelFuncs_w = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 585 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 586 % outModelFuncs_w{ii} = @(x)filter_mdl(x, B, A, outModelFuncs{ii}, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 587 % outModelFuncs_w{ii} = @(x)mdl_fftfilt_wf(x, ii, inFfts, TFmodelFuncs, Npad, B, A, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 588 % off-diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 589 % outModelFuncs_w{ii} = @(x)mdl_fftfilt_wf(x, ii, outModelFuncs, B, A, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 590 % diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 591 outModelFuncs_w{ii} = @(x)filter_mdl2(x, B{ii}, A{ii}, outModelFuncs{ii}, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 592 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 593 % filter model derivatives
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 594 if SymDiff || linUnc
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 595 % whitening 1st derivatives
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 596 outModelDFuncs_w = cell(numel(pnames),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 597 for ll=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 598 outModelDFuncs_w{ll} = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 599 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 600 % off-diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 601 % outModelDFuncs_w{ll}{ii} = @(x)mdl_fftfilt_wf(x, ii, outModelDFuncs{ll}, B, A, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 602 % diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 603 outModelDFuncs_w{ll}{ii} = @(x)filter_mdl2(x, B{ii}, A{ii}, outModelDFuncs{ll}{ii}, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 604 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 605 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 606 if DiffOrder==2
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 607 % whitening 2nd derivatives
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 608 outModelHFuncs_w = cell(numel(pnames));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 609 for mm=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 610 for ll=1:mm
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 611 outModelHFuncs_w{ll,mm} = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 612 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 613 % off-diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 614 % outModelDFuncs_w{ll}{ii} = @(x)mdl_fftfilt_wf(x, ii, outModelDFuncs{ll}, B, A, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 615 % diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 616 outModelHFuncs_w{ll,mm}{ii} = @(x)filter_mdl2(x, B{ii}, A{ii}, outModelHFuncs{ll,mm}{ii}, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 617 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 618 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 619 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 620 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 621 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 622 % filter data
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 623 outYdata_w = zeros(size(outYdata));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 624 outYdata_w(1:Ncut,:) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 625 % off-diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 626 % for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 627 % for jj=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 628 % outYdata_w(:,ii) = outYdata_w(:,ii) + filter_data(B{ii,jj}, A{ii,jj}, outYdata(:,jj), Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 629 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 630 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 631 % diagonal
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 632 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 633 outYdata_w(:,ii) = filter_data(B{ii}, A{ii}, outYdata(:,ii), Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 634 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 635 % set filtered values to pass to xfit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 636 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 637 % outputs(ii).setY(outYdata_w(:,ii));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 638 outputs(ii) = ao(plist('yvals',outYdata_w(:,ii)));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 639 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 640 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 641
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 642 % set the proper function to pass to xfit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 643 if Wf
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 644 outModelFuncs_4xfit = outModelFuncs_w;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 645 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 646 outModelFuncs_4xfit = outModelFuncs;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 647 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 648 if SymDiff || linUnc
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 649 % 1st derivatives
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 650 outModelDFuncs_4xfit = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 651 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 652 outModelDFuncs_4xfit{ii} = cell(numel(pnames),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 653 for ll=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 654 if Wf
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 655 outModelDFuncs_4xfit{ii}{ll} = outModelDFuncs_w{ll}{ii};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 656 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 657 outModelDFuncs_4xfit{ii}{ll} = outModelDFuncs{ll}{ii};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 658 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 659 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 660 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 661 if DiffOrder==2
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 662 % 2nd derivatives
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 663 outModelHFuncs_4xfit = cell(Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 664 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 665 outModelHFuncs_4xfit{ii} = cell(numel(pnames));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 666 for mm=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 667 for ll=1:mm
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 668 if Wf
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 669 outModelHFuncs_4xfit{ii}{ll,mm} = outModelHFuncs_w{ll,mm}{ii};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 670 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 671 outModelHFuncs_4xfit{ii}{ll,mm} = outModelHFuncs{ll,mm}{ii};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 672 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 673 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 674 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 675 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 676 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 677 outModelHFuncs_4xfit = {};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 678 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 679 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 680 outModelDFuncs_4xfit = {};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 681 outModelHFuncs_4xfit = {};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 682 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 683
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 684 % replicate pnames, P0, LB, UB for xfit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 685 if Nout>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 686 % pnames
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 687 pnames_4xfit = cell(1,Nout);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 688 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 689 pnames_4xfit{ii} = pnames;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 690 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 691 % P0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 692 P0_4xfit = cell(1,Nout);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 693 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 694 P0_4xfit{ii} = P0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 695 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 696 % LB
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 697 if ~isempty(lb)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 698 lb_4xfit = cell(1,Nout);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 699 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 700 lb_4xfit{ii} = lb;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 701 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 702 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 703 lb_4xfit = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 704 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 705 % UB
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 706 if ~isempty(ub)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 707 ub_4xfit = cell(1,Nout);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 708 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 709 ub_4xfit{ii} = ub;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 710 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 711 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 712 ub_4xfit = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 713 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 714
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 715 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 716 pnames_4xfit = pnames;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 717 P0_4xfit = P0;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 718 lb_4xfit = lb;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 719 ub_4xfit = ub;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 720 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 721
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 722
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 723 % do fit with xfit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 724 fitpl = plist('Function', outModelFuncs_4xfit, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 725 'pnames', pnames_4xfit, 'P0', P0_4xfit, 'LB', lb_4xfit, 'UB', ub_4xfit, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 726 'Algorithm', Algorithm, 'FitUnc', FitUnc, 'UncMtd', UncMtd, 'linUnc', linUnc, 'FastHess', FastHess,...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 727 'SymGrad', outModelDFuncs_4xfit, 'SymHess', outModelHFuncs_4xfit,...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 728 'MonteCarlo', MCsearch, 'Npoints', Npoints, 'Noptims', Noptims, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 729 'OPTSET', userOpts, 'estimator', estimator, 'weights', weights);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 730
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 731 % Preliminary Gradient search
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 732 if GradSearch && exist('TFmodelDFuncs','var')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 733
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 734 % set new optimization options
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 735 userOpts1 = optimset(userOpts,'GradObj','on','LargeScale','on','FinDiffType','central');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 736 % 'PrecondBandWidth',0,'TolPCG',1e-4);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 737 fitpl1 = fitpl.pset('Algorithm','fminunc','OPTSET',userOpts1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 738
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 739 % fit
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 740 params = xfit(outputs, fitpl1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 741
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 742 % update initial guess
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 743 if Nout>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 744 P0_4xfit = cell(1,Nout);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 745 for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 746 P0_4xfit{ii} = params.y;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 747 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 748 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 749 P0_4xfit = params.y;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 750 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 751
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 752 % restore old optimization options
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 753 fitpl = fitpl.pset('Algorithm',Algorithm,'OPTSET',userOpts,'P0',P0_4xfit);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 754
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 755 % extract preliminary chain
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 756 chain = params.chain;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 757 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 758
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 759 % Final search
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 760 params = xfit(outputs, fitpl);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 761
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 762 % Make output pest
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 763 out = copy(params,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 764
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 765 % Concatenate chains and set it
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 766 if exist('chain','var')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 767 chain = [chain;params.chain];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 768 out.setChain(chain);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 769 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 770
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 771 % Set Name and History
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 772 mdlname = char(TFmodels(1).name);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 773 for kk=2:NTFmodels
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 774 mdlname = strcat(mdlname,[',' char(TFmodels(kk).name)]);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 775 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 776 out.name = sprintf('tdfit(%s)', mdlname);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 777 out.setNames(pnames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 778 out.addHistory(getInfo('None'), pl, ao_invars(:), [as(:).hist]);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 779
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 780 % Set outputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 781 if nargout > 0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 782 varargout{1} = out;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 783 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 784 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 785
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 786 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 787 % Included Functions
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 788 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 789
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 790 function outYdata = mdl_fftfilt(P, outIdx, inFfts, TFmdl, Npad)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 791
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 792 sz = size(inFfts);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 793 outFfts = zeros(sz);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 794 for ii=1:sz(2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 795 outFfts(:,ii) = inFfts(:,ii).*TFmdl{outIdx,ii}(P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 796 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 797 outFfts = sum(outFfts,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 798 outYdata = ifft(outFfts(:,1), 'symmetric');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 799 outYdata(end-Npad+1:end,:) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 800
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 801 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 802
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 803 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 804
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 805 function outYdata = mdl_fftfilt2(P, outIdx, inFfts, sz, TFmdl, TFidx, Npad)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 806
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 807 TFeval = zeros(sz);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 808 for ii=1:sz(2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 809 if TFidx(outIdx,ii)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 810 TFeval(:,ii) = TFmdl{outIdx,ii}(P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 811 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 812 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 813 outFfts = inFfts.*TFeval;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 814 outFfts = sum(outFfts,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 815 outYdata = ifft(outFfts(:,1), 'symmetric');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 816 outYdata(end-Npad+1:end,:) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 817
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 818 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 819
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 820 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 821
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 822 function idx = compIdx(inYdata, Nout, mdl)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 823
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 824 % what inputs are actually different from zero
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 825 b = any(inYdata);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 826 b = repmat(b,Nout,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 827 % what transfer functions are actually different from zero
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 828 sz = size(mdl);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 829 a = zeros(sz);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 830 for ii=1:numel(mdl)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 831 a(ii) = ~(strcmp(mdl(ii).expr.s,'[]') || strcmp(mdl(ii).expr.s,'0') || strcmp(mdl(ii).expr.s,'0.0'));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 832 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 833 % index for computation
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 834 idx = logical(a.*b);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 835
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 836 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 837
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 838 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 839
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 840 function outYdata = mdl_fftfilt_SISO(P, inFfts, TFmdl, Npad)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 841
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 842 % sz = size(inFfts);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 843 % outFfts = zeros(sz);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 844 % parfor ii=1:sz(2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 845 outFfts = inFfts.*TFmdl(P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 846 % outFfts = sum(outFfts,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 847 outYdata = ifft(outFfts(:,1), 'symmetric');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 848 outYdata(end-Npad+1:end,:) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 849
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 850 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 851
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 852 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 853
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 854 function outYdata = mdl_ssm(P, pnames, inputs, model, plsym)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 855
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 856 model.doSetParameters(pnames,P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 857 model.keepParameters();
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 858
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 859 % to numerical
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 860 fs = inputs(1).fs;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 861 % model.modifyTimeStep(plist('newtimestep',1/fs));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 862 model.modifyTimeStep(1/fs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 863
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 864 %%% get expected outputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 865 outYdata = simulate(model,plsym);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 866 outYdata = outYdata.objs(1).y;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 867
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 868 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 869
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 870 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 871
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 872 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 873
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 874 % function outYdata = Dmdl_fftfilt(P, outIdx, Dix, inFfts, TFmdl, Npad)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 875 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 876 % sz = size(inFfts);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 877 % outFfts = zeros(sz);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 878 % for ii=1:sz(2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 879 % outFfts(:,ii) = inFfts(:,ii).*TFmdl{outIdx,ii}{Dix}(P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 880 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 881 % outFfts = sum(outFfts,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 882 % outYdata = ifft(outFfts(:,1), 'symmetric');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 883 % outYdata(end-Npad+1:end,:) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 884 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 885 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 886
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 887 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 888
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 889 % function outYdata = mdl_fftfilt_wf(P, outIdx, inFfts, TFmdl, Npad, B, A, Ncut)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 890 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 891 % sz = size(inFfts);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 892 % outFfts = zeros(sz);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 893 % for ii=1:sz(2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 894 % outFfts(:,ii) = inFfts(:,ii).*TFmdl{outIdx,ii}(P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 895 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 896 % outYdata = ifft(outFfts, 'symmetric');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 897 % outYdata(end-Npad+1:end,:) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 898 % for ii=1:sz(2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 899 % outYdata_w(:,ii) = filter_data(B{outIdx,ii},A{outIdx,ii},outYdata(:,ii), Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 900 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 901 % outYdata = sum(outYdata_w,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 902 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 903 % % outYdata_w = zeros(size(outYdata,1),1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 904 % % outYdata_w(1:Ncut) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 905 % % for jj=1:sz(2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 906 % % outYdata_w = outYdata_w + filter_data(pol{outIdx,jj}, res{outIdx,jj}, outYdata(:,jj), Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 907 % % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 908 % % outYdata = sum(outYdata_w,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 909 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 910 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 911
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 912 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 913
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 914 % function outYdata = mdl_fftfilt_wf(P, outIdx, TFmdl, B, A, Ncut)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 915 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 916 % os = filter_mdl(P, B, A, TFmdl, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 917 % outYdata = os(:,outIdx);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 918 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 919 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 920
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 921 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 922
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 923 % function os = filter_mdl(P, B, A, oFuncs, Ncut)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 924 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 925 % Nout = numel(oFuncs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 926 % for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 927 % Y(:,ii) = oFuncs{ii}(P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 928 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 929 % os = zeros(size(Y));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 930 % os(1:Ncut,:) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 931 % for ii=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 932 % for jj=1:Nout
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 933 % os(:,ii) = os(:,ii) + filter_data(B{ii,jj}, A{ii,jj}, Y(:,jj), Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 934 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 935 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 936 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 937 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 938
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 939 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 940
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 941 % function outYdata = Dmdl_fftfilt_wf(P, outIdx, TFmdl, B, A, Ncut)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 942 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 943 % os = filter_mdl(P, B, A, TFmdl, Ncut);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 944 % outYdata = os(:,outIdx);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 945 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 946 % end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 947
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 948 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 949
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 950 function o = filter_data(B, A, X, Ncut)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 951
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 952 N = numel(X);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 953 M = numel(B);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 954 Y = zeros(N,M);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 955 % parfor ii=1:M
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 956 for ii=1:M
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 957 Y(:,ii) = filter(A(ii),[1 B(ii)],X);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 958 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 959 o = sum(Y,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 960 o(1:Ncut) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 961
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 962 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 963
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 964 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 965
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 966 function o = filter_mdl2(P, B, A, oFunc, Ncut)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 967
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 968 X = oFunc(P);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 969 N = numel(X);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 970 M = numel(B);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 971 Y = zeros(N,M);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 972 for ii=1:M
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 973 Y(:,ii) = filter(A(ii),[1 B(ii)],X);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 974 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 975 o = sum(Y,2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 976 o(1:Ncut) = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 977
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 978 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 979
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 980 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 981
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 982 function fcn = eval_mdl(str,xvar,xvals)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 983
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 984 fcn = eval(['@(P,',xvar,')(',str,')']);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 985 fcn = @(x)fcn(x,xvals);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 986
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 987 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 988
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 989 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 990
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 991 function fcn = eval_mdl_alias(str,xvar,xvals,alias)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 992
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 993 fcn = eval(['@(P,',xvar,',alias',')(',str,')']);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 994 fcn = @(x)fcn(x,xvals,alias);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 995
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 996 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 997 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 998
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 999 function str = doSubsPnames(str,params)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1000
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1001 lengths = zeros(1,numel(params));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1002 for ii=1:numel(params)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1003 lengths(ii) = length(params{ii});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1004 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1005 [dummy,ix] = sort(lengths,'descend');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1006 repstr = cell(1,numel(params));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1007 for ii=1:numel(params)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1008 repstr{ii} = ['P(' int2str(ii) ')'];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1009 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1010 str = regexprep(str,params(ix),repstr(ix));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1011 if isempty(str)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1012 str = '0';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1013 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1014
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1015 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1016
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1017 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1018
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1019 function str = doSubsAlias(str,alias)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1020
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1021 lengths = zeros(1,numel(alias));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1022 for ii=1:numel(alias)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1023 lengths(ii) = length(alias{ii});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1024 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1025 [dummy,ix] = sort(lengths,'descend');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1026 repstr = cell(1,numel(alias));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1027 for ii=1:numel(alias)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1028 repstr{ii} = ['alias{' int2str(ii) '}'];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1029 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1030 str = regexprep(str,alias(ix),repstr(ix));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1031
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1032 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1033
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1034 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1035
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1036 function [newMdls,pnames,P0]=cat_mdls(mdls,usedParams,P0)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1037
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1038 pnames = mdls(1).params;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1039
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1040 % union of all parameters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1041 for ii=2:numel(mdls)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1042 pnames = union(pnames,mdls(ii).params);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1043 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1044
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1045 pvalues = cell(1,numel(pnames));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1046 for kk=1:numel(pnames)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1047 for ii=1:numel(mdls)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1048 ix = strcmp(mdls(ii).params,pnames{kk});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1049 if sum(ix)==0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1050 continue;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1051 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1052 pvalues{kk} = mdls(ii).values{ix};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1053 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1054 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1055 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1056
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1057 % set the used one
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1058 for ii=1:numel(mdls)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1059 mdls(ii).setParams(pnames,pvalues);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1060 if ~isempty(usedParams)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1061 mdls(ii).subs(setdiff(pnames,usedParams));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1062 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1063 usedParams = pnames;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1064 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1065 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1066
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1067 % copy to new models
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1068 for ii=1:size(mdls,1)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1069 for jj=1:size(mdls,2)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1070 newMdls(ii,jj) = smodel(plist('expression',mdls(ii,jj).expr,...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1071 'xvar',mdls(ii,jj).xvar,'xvals',mdls(ii,jj).xvals,...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1072 'name',mdls(ii,jj).name));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1073 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1074 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1075
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1076 % set the same parameters for all
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1077 for ii=1:numel(newMdls)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1078 if ~isempty(P0)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1079 newMdls(ii).setParams(usedParams,P0);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1080 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1081 for kk=1:numel(usedParams)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1082 ix = strcmp(usedParams(kk),pnames);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1083 P0(kk) = pvalues{ix};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1084 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1085 newMdls(ii).setParams(usedParams,P0);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1086 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1087 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1088
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1089 pnames = usedParams;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1090
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1091 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1092
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1093 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1094 % Get Info Object
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1095 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1096 function ii = getInfo(varargin)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1097 if nargin == 1 && strcmpi(varargin{1}, 'None')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1098 sets = {};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1099 pl = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1100 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1101 sets = {'Default'};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1102 pl = getDefaultPlist;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1103 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1104 % Build info object
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1105 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: tdfit.m,v 1.45 2011/05/26 12:57:27 congedo Exp $', sets, pl);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1106 ii.setModifier(false);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1107 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1108
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1109 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1110 % Get Default Plist
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1111 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1112 function plout = getDefaultPlist()
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1113 persistent pl;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1114 if exist('pl', 'var')==0 || isempty(pl)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1115 pl = buildplist();
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1116 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1117 plout = pl;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1118 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1119
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1120 function pl = buildplist()
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1121
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1122 pl = plist();
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1123
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1124 % Inputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1125 p = param({'Inputs', 'An array of input AOs, one per each experiment.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1126 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1127
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1128 % Models
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1129 p = param({'Models', 'An array of transfer function SMODELs.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1130 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1131
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1132 % PadRatio
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1133 p = param({'PadRatio', ['PadRatio is defined as the ratio between the number of zero-pad points '...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1134 'and the data length.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1135 'Define how much to zero-pad data after the signal.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1136 'Being <tt>tdfit</tt> a fft-based algorithm, no zero-padding might bias the estimation, '...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1137 'therefore it is strongly suggested to do that.']}, 1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1138 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1139
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1140 % Whitening Filters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1141 p = param({'WhFlts', 'An array of FILTERBANKs containing the whitening filters per each output AO.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1142 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1143
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1144 % Parameters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1145 p = param({'Pnames', 'A cell-array of parameter names to fit.'}, paramValue.EMPTY_CELL);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1146 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1147
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1148 % P0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1149 p = param({'P0', 'An array of starting guesses for the parameters.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1150 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1151
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1152 % LB
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1153 p = param({'LB', ['Lower bounds for the parameters.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1154 'This improves convergency. Mandatory for Monte Carlo.']}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1155 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1156
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1157 % UB
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1158 p = param({'UB', ['Upper bounds for the parameters.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1159 'This improves the convergency. Mandatory for Monte Carlo.']}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1160 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1161
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1162 % Algorithm
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1163 p = param({'ALGORITHM', ['A string defining the fitting algorithm.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1164 '<tt>fminunc</tt>, <tt>fmincon</tt> require ''Optimization Toolbox'' to be installed.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1165 '<tt>patternsearch</tt>, <tt>ga</tt>, <tt>simulannealbnd</tt> require ''Genetic Algorithm and Direct Search'' to be installed.<br>']}, ...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1166 {1, {'fminsearch', 'fminunc', 'fmincon', 'patternsearch', 'ga', 'simulannealbnd'}, paramValue.SINGLE});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1167 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1168
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1169 % OPTSET
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1170 p = param({'OPTSET', ['An optimisation structure to pass to the fitting algorithm.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1171 'See <tt>fminsearch</tt>, <tt>fminunc</tt>, <tt>fmincon</tt>, <tt>optimset</tt>, for details.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1172 'See <tt>patternsearch</tt>, <tt>psoptimset</tt>, for details.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1173 'See <tt>ga</tt>, <tt>gaoptimset</tt>, for details.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1174 'See <tt>simulannealbnd</tt>, <tt>saoptimset</tt>, for details.']}, paramValue.EMPTY_STRING);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1175 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1176
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1177 % SymDiff
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1178 p = param({'SymDiff', 'Use symbolic derivatives or not. Only for gradient-based algorithm or for LinUnc option.'}, paramValue.NO_YES);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1179 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1180
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1181 % DiffOrder
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1182 p = param({'DiffOrder', 'Symbolic derivative order. Only for SymDiff option.'}, {1, {1,2}, paramValue.SINGLE});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1183 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1184
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1185 % FitUnc
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1186 p = param({'FitUnc', 'Fit parameter uncertainties or not.'}, paramValue.YES_NO);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1187 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1188
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1189 % UncMtd
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1190 p = param({'UncMtd', ['Choose the uncertainties estimation method.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1191 'For multi-channel fitting <tt>hessian</tt> is mandatory.']}, {1, {'hessian', 'jacobian'}, paramValue.SINGLE});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1192 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1193
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1194 % LinUnc
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1195 p = param({'LinUnc', 'Force linear symbolic uncertainties.'}, paramValue.YES_NO);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1196 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1197
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1198 % GradSearch
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1199 p = param({'GradSearch', 'Do a preliminary gradient-based search using the BFGS Quasi-Newton method.'}, paramValue.NO_YES);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1200 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1201
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1202 % MonteCarlo
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1203 p = param({'MonteCarlo', ['Do a Monte Carlo search in the parameter space.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1204 'Useful when dealing with high multiplicity of local minima. May be computer-expensive.<br>'...
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1205 'Note that, if used, P0 will be ignored. It also requires to define LB and UB.']}, paramValue.NO_YES);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1206 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1207
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1208 % Npoints
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1209 p = param({'Npoints', 'Set the number of points in the parameter space to be extracted.'}, 100000);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1210 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1211
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1212 % Noptims
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1213 p = param({'Noptims', 'Set the number of optimizations to be performed after the Monte Carlo.'}, 10);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1214 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1215
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1216 % SISO
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1217 p = param({'SingleInputSingleOutput', 'Specify whether the model should be considered as Single-Input/Single-Output model. This is for performance.'}, paramValue.NO_YES);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1218 pl.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1219
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1220 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1221 % END