|
12 | 12 | % ├─────.timing: a multiple condition file name (single session) OR |
13 | 13 | % │ a cell array of multiple condition file names OR |
14 | 14 | % │ a struct (single session) with fields .names, .onsets, |
15 | | -% │ and (optional) .durations OR |
| 15 | +% │ and (optional) duration OR |
16 | 16 | % │ a cell array of struct OR |
17 | 17 | % │ a struct with fields 'markerinfos', 'markervalues', |
18 | 18 | % │ 'names' OR |
|
83 | 83 | % Introduced In PsPM 4.2 |
84 | 84 | % Written in 2020 by Ivan Rojkov (University of Zurich) |
85 | 85 | % Maintained in 2022 by Teddy |
| 86 | +% Maintained in 2026 by Bernhard A. von Raußendorf |
86 | 87 | % ● Developer |
87 | 88 | % The fitting process is a residual least square minimisation where the |
88 | 89 | % predicted value is calculated as following: |
|
126 | 127 | return |
127 | 128 | end |
128 | 129 |
|
| 130 | +% 2.3 check .... |
| 131 | +std_exp_cond = []; |
| 132 | + |
| 133 | +if ~(ischar(model.std_exp_cond) && strcmpi(model.std_exp_cond, 'none')) |
| 134 | + if ischar(model.std_exp_cond) |
| 135 | + std_exp_cond.ind = find(strcmpi( model.std_exp_cond, model.timing{1}.names), 1); |
| 136 | + else |
| 137 | + std_exp_cond.ind = model.std_exp_cond; |
| 138 | + end |
| 139 | + std_exp_cond.name = model.timing{1}.names{std_exp_cond.ind}; |
| 140 | +end |
| 141 | + |
129 | 142 | %% Loading files |
130 | 143 |
|
131 | 144 | fprintf('Computing Trial Average Model: %s \n', model.modelfile); |
|
163 | 176 | % Checking if the sampling rate is the same for all samples. |
164 | 177 | if n_file > 1 && any(diff(sr) ~= 0) % not any(diff(sr) > 0) |
165 | 178 | if (ischar(model.filter.down) && strcmpi(model.filter.down, 'none')) || ... % if filter.down is none |
166 | | - (isnumeric(model.filter.down) && model.filter.down > min(sr)) % if filter.down is less than the minimal sr |
| 179 | + (isnumeric(model.filter.down) && model.filter.down > min(sr)) % if filter.down is less than the minimal sr |
167 | 180 |
|
168 | 181 | model.filter.down = min(sr); |
169 | 182 | fprintf('\nSampling rate differs between sessions. Data will be downsampled.\n') |
|
202 | 215 | tmp_data.mean = s.segments{i,1}.mean; % why not eg 50x1 |
203 | 216 | tmp_data.std = s.segments{i,1}.std;% why not eg 50x1 |
204 | 217 | tmp_data.sem = s.segments{i,1}.sem;% why not eg 50x1 |
205 | | - tmp_data.t = s.segments{i,1}.t; |
| 218 | + tmp_data.t = s.segments{i,1}.t; % |
206 | 219 | % a cell array of struct and of size (n_file x n_exp_cond) where each |
207 | 220 | % line correspond to a given file and each column to an |
208 | 221 | % experimental condition |
|
215 | 228 |
|
216 | 229 | %% Downsample the data |
217 | 230 | % if a filter was specified or if the data differ in sr |
218 | | -fprintf('Filtering ...\n') |
219 | | -for i = 1:n_exp_cond |
220 | | - for k = 1:n_file |
221 | 231 |
|
222 | | - model.filter.sr = sr(k); |
| 232 | +fprintf('Filtering ...\n') % maybe only if there is a filtering? |
223 | 233 |
|
224 | | - [lsts, segm{k,i}, ~] = structfun(@(x) pspm_prepdata(x, model.filter),segm{k,i},'UniformOutput',false); |
225 | | - if any(structfun(@(x) x<1,lsts)), warning('ID:error_prepdata','An error occured in pspm_prepdata.'); return; end |
226 | 234 |
|
227 | | - clear new_sr lsts |
| 235 | +fields = {'mean', 'std', 'sem'}; |
| 236 | +for i = 1:n_exp_cond |
| 237 | + for k = 1:n_file |
| 238 | + model.filter.sr = sr(k); % adds the corresponding sr to the filer |
| 239 | + |
| 240 | + for f = 1:numel(fields) |
| 241 | + field = fields{f}; |
| 242 | + [lsts, segm{k,i}.(field), new_sr(k)] = pspm_prepdata(segm{k,i}.(field), model.filter); |
| 243 | + if lsts < 1; warning('ID:error_prepdata', 'An error occured in pspm_prepdata.'); return; end |
| 244 | + end |
| 245 | + [llsts, segm{k,i}.t , new_sr(k) ] = pspm_downsample(segm{k,i}.t, sr(k), new_sr(k) ); % does not need to be filtered! |
| 246 | + if llsts < 1; warning('ID:error_downsample', 'An error occured in pspm_downsample.'); return; end |
| 247 | + |
228 | 248 | end |
229 | 249 | end |
230 | 250 |
|
231 | | -% changing the sampling rate |
232 | | -if isnumeric(model.filter.down) |
233 | | - sr = model.filter.down * ones(size(sr)); % needs to be tested |
234 | | -end |
| 251 | +sr = new_sr; % maybe test upstream if all new_sr are the same! |
| 252 | +% % changing the sampling rate |
| 253 | +% if isnumeric(model.filter.down) |
| 254 | +% sr = model.filter.down * ones(size(new_sr)); % needs to be tested why not the values of prepdata? |
| 255 | +% end |
| 256 | + |
| 257 | +clear new_sr |
235 | 258 |
|
236 | 259 | %% Determining mean values |
237 | 260 | fprintf('Preparing for fitting ...\n') |
238 | 261 |
|
239 | 262 | baseline_index = floor(sr(1)*model.baseline)+1; |
240 | 263 |
|
241 | | -if exist('std_exp_cond','var') |
| 264 | + |
| 265 | +if ~isempty(std_exp_cond) |
242 | 266 | tmp_data = [segm{:,std_exp_cond.ind}]; |
243 | 267 |
|
244 | | - std_exp_cond.data = mean([tmp_data.mean],2, 'omitnan'); %nanmean([tmp_data.mean],2); |
| 268 | + std_exp_cond.data = mean([tmp_data.mean],2, 'omitnan'); |
245 | 269 | std_exp_cond.std = mean([tmp_data.std],2, 'omitnan'); |
246 | 270 | std_exp_cond.sem = mean([tmp_data.sem],2, 'omitnan'); |
247 | 271 | end |
|
256 | 280 | tmp_data_new.t = mean([tmp_data.t],2, 'omitnan'); |
257 | 281 |
|
258 | 282 | % Subtracting the standard experimental condition |
259 | | - if exist('std_exp_cond','var') && i~=std_exp_cond.ind |
| 283 | + if ~isempty(std_exp_cond) && i~=std_exp_cond.ind |
260 | 284 | tmp_data_new.data = tmp_data_new.data - std_exp_cond.data; |
261 | 285 | tmp_data_new.std = tmp_data_new.std + std_exp_cond.std; % the error adds up |
262 | 286 | tmp_data_new.sem = tmp_data_new.sem + std_exp_cond.sem; % the error adds up |
|
266 | 290 | tmp_data_new.data = tmp_data_new.data - tmp_data_new.data(baseline_index); |
267 | 291 |
|
268 | 292 | % Dividing by the max value |
269 | | - if model.norm_max |
270 | | - [tmp_max,tmp_max_ind] = max(tmp_data_new.data); |
| 293 | + if model.norm_max |
| 294 | + [tmp_max,tmp_max_ind] = max(tmp_data_new.data); % this does not give us the first peak!!! |
| 295 | + % maybe add if tmp_max == 0 |
271 | 296 | tmp_data_new.data = tmp_data_new.data/tmp_max; |
272 | | - tmp_data_new.std = tmp_data_new.std + tmp_data_new.std(tmp_max_ind); % the error adds up |
273 | | - tmp_data_new.sem = tmp_data_new.sem + tmp_data_new.sem(tmp_max_ind); % the error adds up |
| 297 | + tmp_data_new.std = tmp_data_new.std + tmp_data_new.std(tmp_max_ind); % the error adds up . why not /abs(tmp_max) |
| 298 | + tmp_data_new.sem = tmp_data_new.sem + tmp_data_new.sem(tmp_max_ind); % the error adds up . why not /abs(tmp_max) |
274 | 299 | end |
275 | 300 |
|
276 | 301 | mean_data{1,i} = tmp_data_new; |
|
355 | 380 | tam.data.normd = model.norm; |
356 | 381 | tam.data.norm = model.norm; |
357 | 382 |
|
358 | | -if exist('std_exp_cond','var') |
| 383 | +if ~isempty(std_exp_cond) |
359 | 384 | tam.data.std_exp_cond.name = std_exp_cond.name; |
360 | 385 | tam.data.std_exp_cond.ind = std_exp_cond.ind; |
361 | 386 | else |
|
0 commit comments