0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 1 % tdChi2 computes the chi-square for a parameter estimate.
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: tdChi2 computes the chi-square in time domain for an input
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 5 % pest. The system measured outputs, inputs and models must be
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 6 % contained in the plist. Also whitening filters for each
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 7 % output may be taken into account.
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 8 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 9 % CALL: obj = tdChi2(objs,pl);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 10 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 11 % INPUTS: obj - must be a single pest
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 12 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 13 % <a href="matlab:utils.helper.displayMethodInfo('pest', 'tdChi2')">Parameters Description</a>
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 14 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 15 % VERSION: $Id: tdChi2.m,v 1.5 2011/04/08 08:56:25 hewitson Exp $
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 16 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 17 % HISTORY: 08-02-2011 G. Congedo
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 18 %
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 19 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 20
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 21 function varargout = tdChi2(varargin)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 22
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 23 %%% Check if this is a call for parameters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 24 if utils.helper.isinfocall(varargin{:})
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 25 varargout{1} = getInfo(varargin{3});
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 26 return
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 27 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 28
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 29 import utils.const.*
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 30 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 31
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 32 % Collect input variable names
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 33 in_names = cell(size(varargin));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 34 for ii = 1:nargin,in_names{ii} = inputname(ii);end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 35
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 36 % Collect all AOs and plists
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 37 [pests, pest_invars] = utils.helper.collect_objects(varargin(:), 'pest', in_names);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 38 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 39
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 40
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 41 % combine plists
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 42 pl = parse(pl, getDefaultPlist());
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 43
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 44 % Extract necessary parameters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 45 inputs = pl.find('inputs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 46 outputs = pl.find('outputs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 47 models = pl.find('models');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 48 WF = pl.find('WhiteningFilters');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 49 Ncut = pl.find('Ncut');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 50 Npad = pl.find('Npad');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 51
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 52 if nargout == 0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 53 error('### tdChi2 cannot be used as a modifier. Please give an output variable.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 54 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 55
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 56 if ~all(isa(pests, 'pest'))
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 57 error('### tdChi2 must be only applied to pest objects.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 58 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 59
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 60 % Determine the class
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 61 outClass = class(outputs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 62
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 63 % Check ouputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 64 if isempty(outputs)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 65 error('### Please give the outputs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 66 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 67 switch outClass
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 68 case 'ao'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 69 N = numel(outputs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 70 if N>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 71 error('### Please give the outputs in a MATRIX');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 72 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 73 case 'matrix'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 74 N = numel(outputs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 75 if N>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 76 error('### Please give the outputs in a COLLECTION of MATRIXs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 77 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 78 if outputs.ncols>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 79 outputs = outputs.';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 80 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 81 case 'collection'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 82 N = numel(outputs.objs);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 83 for ii=1:N
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 84 if outputs.objs{ii}.ncols>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 85 outputs.objs{ii} = outputs.objs{ii}.';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 86 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 87 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 88 otherwise
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 89 error('### Unknown class for outputs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 90 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 91
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 92 % Check inputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 93 if isempty(inputs)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 94 error('### Please give the inputs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 95 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 96 if ~strcmp(class(inputs),outClass)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 97 error('### Please give inputs as the same class of outputs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 98 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 99 switch outClass
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 100 case 'ao'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 101 if numel(inputs)>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 102 error('### Please give the inputs in a MATRIX');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 103 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 104 case 'matrix'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 105 if numel(inputs)>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 106 error('### Please give the inputs in a COLLECTION of MATRIXs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 107 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 108 if inputs.ncols>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 109 inputs = inputs.';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 110 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 111 case 'collection'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 112 for ii=1:numel(inputs.objs)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 113 if inputs.objs{ii}.ncols>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 114 inputs.objs{ii} = inputs.objs{ii}.';
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 115 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 116 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 117 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 118
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 119 % Check models
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 120 if isempty(models)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 121 error('### Please give the transfer function models');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 122 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 123 switch outClass
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 124 case 'ao'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 125 if ~strcmp(class(models),'smodel')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 126 error('### Please, give the transfer function in a SMODEL.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 127 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 128 if numel(models)>1
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 129 error('### The size of the transfer function SMODEL does not match with the number of inputs/outputs.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 130 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 131 case {'matrix','collection'}
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 132 if ~strcmp(class(models),'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 133 error('### Please, give the transfer function in a MATRIX of SMODELs.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 134 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 135 for ii=1:N
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 136 if strcmp(outClass,'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 137 checkSz = models.nrows~=outputs.nrows || models.ncols~=inputs.nrows;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 138 elseif strcmp(outClass,'collection')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 139 checkSz = models.nrows~=outputs.objs{ii}.nrows || models.ncols~=inputs.objs{ii}.nrows;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 140 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 141 if checkSz
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 142 error('### The size of the transfer function MATRIX does not match with the number of inputs/outputs.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 143 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 144 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 145 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 146
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 147 % Check whitening filters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 148 whiten = ~isempty(WF);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 149 if whiten
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 150 switch outClass
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 151 case 'ao'
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 152 if numel(WF)>1 || ~any(strcmp(class(WF),{'miir','fiir','filterbank'}))
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 153 error('### Please give the whitening filters in a FIIR, MIIR or FILTERBANK');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 154 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 155 case {'matrix','collection'}
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 156 if ~strcmp(class(WF),'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 157 error('### Please give the whitening filters in a MATRIX of FIIRs, MIIRs or FILTERBANKs');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 158 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 159 for ii=1:N
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 160 if strcmp(outClass,'matrix')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 161 checkSz = WF.nrows~=outputs.nrows && WF.ncols~=outputs.nrows;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 162 elseif strcmp(outClass,'collection')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 163 checkSz = WF.nrows~=outputs.objs{ii}.nrows && WF.ncols~=outputs.objs{ii}.nrows;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 164 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 165 if checkSz
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 166 error('### The size of the whitening filters MATRIX does not match with the number of outputs.');
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 167 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 168 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 169 end
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
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 173 % Actual computation
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 174
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 175 chi2 = zeros(N,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 176 Ndata = zeros(N,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 177
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 178 % Subs unwanted params
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 179 if strcmp(outClass,'matrix') || strcmp(outClass,'collection')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 180 for kk=1:numel(models.objs)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 181 models.objs(kk).setParams(pests.names,pests.y);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 182 models.objs(kk).subs(setdiff(models.objs(kk).params,pests.names));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 183 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 184 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 185 models.setParams(pests.names,pests.y);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 186 models.subs(setdiff(models.params,pests.names));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 187 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 188
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 189 for ii=1:N
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 190
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 191 % Time-domain template
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 192 if strcmp(outClass,'matrix') || strcmp(outClass,'collection')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 193 template = fftfilt(inputs.objs{ii},models,plist('Npad',Npad));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 194 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 195 template = fftfilt(inputs,models,plist('Npad',Npad));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 196 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 197
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 198 % Residues
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 199 if strcmp(outClass,'matrix') || strcmp(outClass,'collection')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 200 res = template-outputs.objs{ii};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 201 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 202 res = template-outputs;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 203 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 204
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 205 % Whiten
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 206 if whiten
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 207 res = filter(res,WF);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 208 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 209
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 210 % Split-out transients
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 211 if ~isempty(Ncut) || Ncut~=0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 212 res = split(res,plist('samples',[Ncut+1,Inf]));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 213 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 214
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 215 % Compute chi2 & dof
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 216 if strcmp(outClass,'matrix') || strcmp(outClass,'collection')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 217 chi2(ii) = sum(sum((res.objs.y).^2));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 218 Ndata(ii) = max(size(res.objs.y))*min(size(res.objs.y));
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 219 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 220 chi2(ii) = sum((res.y).^2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 221 Ndata(ii) = numel(res.y);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 222 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 223
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 224 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 225
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 226 % Compute total chi2 & dof
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 227 chi2 = sum(chi2);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 228 dof = sum(Ndata)-numel(pests.y);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 229
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 230 % Output pest
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 231 out = copy(pests,1);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 232 out = out.setChi2(chi2/dof);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 233 out = out.setDof(dof);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 234 out = out.setName(['tdChi2(' pests.name ')']);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 235
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 236 out.addHistory(getInfo('None'), pl, pest_invars(:), [pests(:).hist]);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 237
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 238 % Set outputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 239 if nargout > 0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 240 varargout{1} = out;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 241 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 242
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 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 246 % Get Info Object
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 247 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 248 function ii = getInfo(varargin)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 249 if nargin == 1 && strcmpi(varargin{1}, 'None')
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 250 sets = {};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 251 pl = [];
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 252 else
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 253 sets = {'Default'};
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 254 pl = getDefaultPlist;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 255 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 256 % Build info object
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 257 ii = minfo(mfilename, 'pest', 'ltpda', utils.const.categories.helper, '$Id: tdChi2.m,v 1.5 2011/04/08 08:56:25 hewitson Exp $', sets, pl);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 258 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 259
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 260 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 261 % Get Default Plist
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 262 %--------------------------------------------------------------------------
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 263 function plout = getDefaultPlist()
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 264 persistent pl;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 265 if exist('pl', 'var')==0 || isempty(pl)
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 266 pl = buildplist();
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 267 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 268 plout = pl;
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 269 end
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 270
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 271 function plo = buildplist()
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 272 plo = plist();
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 273
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 274 % Outputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 275 p = param({'Outputs', 'The system outputs. Must be an AO, a MATRIX or a COLLECTION of MATRIXs, one per each experiment.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 276 plo.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 277
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 278 % Inputs
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 279 p = param({'Inputs', 'The system inputs. Must be an AO, a MATRIX or a COLLECTION of MATRIXs, one per each experiment.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 280 plo.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 281
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 282 % Models
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 283 p = param({'Models', 'The system transfer function SMODELs. Must be a SMODEL or a MATRIX of SMODELs.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 284 plo.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 285
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 286 % Whitening filters
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 287 p = param({'WhiteningFilters', 'The output whitening filters. Must be a MIIR, FIIR, FILTERBANK or a MATRIX.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 288 plo.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 289
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 290 % Ncut
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 291 p = param({'Ncut', 'The number of points to cut out initial whitening filter transients.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 292 plo.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 293
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 294 % Npad
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 295 p = param({'Npad', 'The number of points to zero-pad the input for ifft. If left empty, a data length is assumed.'}, paramValue.EMPTY_DOUBLE);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 296 plo.append(p);
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 297
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
+ − 298 end