|
23 | 23 |
|
24 | 24 |
|
25 | 25 | function success = autoProcessSignal()
|
26 |
| -% do all the autoprocessing. Use the fiducials in the fiducialed beat to find all other beats of |
27 |
| -% that run and fiducialise those beats, too. Handle & save the autoprocessed beats just like the |
28 |
| -% beat done by the user. |
| 26 | +% do all the autoprocessing. Use the fiducials in the fiducialed beat to find |
| 27 | +% all other beats of that run and fiducialise those beats, too. Handle & save |
| 28 | +% the autoprocessed beats just like the beat done by the user. |
29 | 29 |
|
30 | 30 | %set up globals
|
31 | 31 | clear global AUTOPROCESSING % just in case, so previous stuff doesnt mess anything up
|
32 | 32 | global TS SCRIPTDATA AUTOPROCESSING
|
33 | 33 |
|
34 | 34 | unslicedDataIndex = SCRIPTDATA.unslicedDataIndex;
|
35 | 35 | templateFids = TS{SCRIPTDATA.CURRENTTS}.fids;
|
36 |
| -templateBeatEnvelope = [TS{SCRIPTDATA.CURRENTTS}.selframes(1), TS{SCRIPTDATA.CURRENTTS}.selframes(2)]; |
| 36 | +templateBeatEnvelope = [TS{SCRIPTDATA.CURRENTTS}.selframes(1), ... |
| 37 | + TS{SCRIPTDATA.CURRENTTS}.selframes(2)]; |
37 | 38 | badLeads = (find(TS{SCRIPTDATA.unslicedDataIndex}.leadinfo > 0))';
|
38 | 39 |
|
39 | 40 |
|
|
55 | 56 | settings.RunNumber = SCRIPTDATA.ACQNUM;
|
56 | 57 |
|
57 | 58 |
|
58 |
| -[AUTOPROCESSING.beats, AUTOPROCESSING.allFids, info, success] = getBeatsAndFids(TS{unslicedDataIndex}.potvals, templateBeatEnvelope, templateFids, badLeads, settings); |
| 59 | +[AUTOPROCESSING.beats, AUTOPROCESSING.allFids, info, success] = getBeatsAndFids(... |
| 60 | + TS{unslicedDataIndex}.potvals, templateBeatEnvelope, templateFids, badLeads, settings); |
59 | 61 | if ~success, return, end
|
60 | 62 |
|
61 | 63 | AUTOPROCESSING.leadsToAutofiducialize = info.leadsToAutofiducialize;
|
|
76 | 78 | success = 1;
|
77 | 79 | return;
|
78 | 80 | end
|
79 |
| - save(SCRIPTDATA.SCRIPTFILE,'SCRIPTDATA') % save settings.. in case user made a change in autofiducializing window |
| 81 | + % save settings.. in case user made a change in autofiducializing window |
| 82 | + save(SCRIPTDATA.SCRIPTFILE,'SCRIPTDATA') |
80 | 83 | end
|
81 | 84 |
|
82 | 85 | %%%%% main loop: process each beat.
|
83 |
| -global times % to do: remove this? this global is only there to measure time efficiency.. |
| 86 | +% to do: remove this? this global is only there to measure time efficiency.. |
| 87 | +global times |
84 | 88 | times=struct();
|
85 | 89 | times(1).count=1;
|
86 | 90 |
|
87 |
| -for beatNumber=2:length(AUTOPROCESSING.beats) % skip the first beat, as this is the user fiducialized one |
| 91 | +% skip the first beat, as this is the user fiducialized one |
| 92 | +for beatNumber=2:length(AUTOPROCESSING.beats) |
88 | 93 | b=tic;
|
89 | 94 | success = processBeat(beatNumber);
|
90 | 95 | t2=toc(b);
|
|
103 | 108 |
|
104 | 109 |
|
105 | 110 |
|
106 |
| - |
107 |
| - |
108 |
| - |
109 |
| - |
110 |
| - |
111 |
| - |
112 |
| - |
113 |
| - |
114 |
| - |
115 |
| - |
116 |
| - |
117 |
| - |
118 |
| - |
119 |
| - |
120 |
| - |
121 |
| - |
122 |
| - |
123 |
| - |
124 | 111 |
|
125 | 112 |
|
126 | 113 |
|
127 | 114 | %%%%%%%%%%% functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
128 | 115 |
|
129 | 116 | function getFaultyBeats
|
130 |
| -% determine the beats, where autoprocessing didn't quite work ( eg those with very high variance) |
| 117 | +% determine the beats, where autoprocessing didn't quite work |
| 118 | +% ( eg those with very high variance) |
131 | 119 | % fill AUTOPROCESSING.faultyBeatInfo and AUTOPROCESSING.faultyBeatIndeces with info
|
132 | 120 |
|
133 | 121 | global AUTOPROCESSING SCRIPTDATA
|
|
141 | 129 | %%%% set up variables
|
142 | 130 | treshold_variance = SCRIPTDATA.TRESHOLD_VAR;
|
143 | 131 | faultyBeatIndeces =[]; % the indeces in .Beats of faulty beats
|
144 |
| -faultyBeatInfo = {}; % which fiducials (which types) in the beat are bad? e.g faultyBeatInfo = { [2 4], [5 6 7],.. } |
145 |
| -faultyBeatValues = {}; % correspondes with faultyBeatInfo, but contains the value instead of type |
| 132 | +% which fiducials (which types) in the beat are bad? |
| 133 | +% e.g faultyBeatInfo = { [2 4], [5 6 7],.. } |
| 134 | +faultyBeatInfo = {}; |
| 135 | +% correspondes with faultyBeatInfo, but contains the value instead of type |
| 136 | +faultyBeatValues = {}; |
146 | 137 | numBeats = length(AUTOPROCESSING.beats);
|
147 | 138 |
|
148 | 139 | if ~isempty(AUTOPROCESSING.allFids)
|
|
163 | 154 | faultyBeatInfo{end+1} = faultyFids;
|
164 | 155 |
|
165 | 156 | %%%% get the faultyValues of that faulty beat
|
166 |
| - faultyIndeces = faultyIndeces + numFids; % now faultyIndeces are indeces of global bad fiducials |
| 157 | + % now faultyIndeces are indeces of global bad fiducials |
| 158 | + faultyIndeces = faultyIndeces + numFids; |
167 | 159 | faultyValues = [AUTOPROCESSING.allFids{beatNumber}(faultyIndeces).value];
|
168 | 160 | faultyBeatValues{end+1}=faultyValues;
|
169 | 161 | end
|
|
191 | 183 | %%%% slice "complete ts" into beat (in TS{newBeatIdx} )
|
192 | 184 | a=tic;
|
193 | 185 | newBeatIdx=tsNew(1);
|
194 |
| -beatframes=AUTOPROCESSING.beats{beatNumber}(1):AUTOPROCESSING.beats{beatNumber}(2); % all time frames of the beat |
| 186 | +% all time frames of the beat |
| 187 | +beatframes=AUTOPROCESSING.beats{beatNumber}(1):AUTOPROCESSING.beats{beatNumber}(2); |
195 | 188 |
|
196 | 189 | TS{newBeatIdx}=TS{SCRIPTDATA.unslicedDataIndex};
|
197 | 190 | TS{newBeatIdx}.potvals=TS{newBeatIdx}.potvals(:,beatframes);
|
|
218 | 211 | for fidIdx=1:length(fids)
|
219 | 212 | fids(fidIdx).value=fids(fidIdx).value - reference + 1; % fids now in relative frame
|
220 | 213 | end
|
221 |
| -if isfield(fids,'variance'), fids=rmfield(fids,'variance'); end %variance not wanted in the output |
| 214 | +%variance not wanted in the output |
| 215 | +if isfield(fids,'variance'), fids=rmfield(fids,'variance'); end |
222 | 216 | TS{newBeatIdx}.fids=fids;
|
223 | 217 | t=toc(a);
|
224 | 218 | times(times(1).count).b_MakeFidsLocalAndRemvoeVariance=t;
|
|
276 | 270 | %%%% split TS{newIdx} into numGroups smaller ts in grIndices
|
277 | 271 | splitgroup = [];
|
278 | 272 | for p=1:length(SCRIPTDATA.GROUPNAME{SCRIPTDATA.CURRENTRUNGROUP})
|
279 |
| - if SCRIPTDATA.GROUPDONOTPROCESS{SCRIPTDATA.CURRENTRUNGROUP}{p} == 0, splitgroup = [splitgroup p]; end |
| 273 | + if SCRIPTDATA.GROUPDONOTPROCESS{SCRIPTDATA.CURRENTRUNGROUP}{p} == 0, ... |
| 274 | + splitgroup = [splitgroup p]; end |
280 | 275 | end
|
281 | 276 | % splitgroup is now eg [1 3] if there are 3 groups but the 2 should
|
282 | 277 | % not be processed
|
283 | 278 | channels=SCRIPTDATA.GROUPLEADS{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup);
|
284 | 279 | grIndices = tsSplitTS(newBeatIdx, channels);
|
285 | 280 | % update the filenames (add '-groupextension' to filename)
|
286 |
| -tsDeal(grIndices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup))); |
| 281 | +tsDeal(grIndices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{... |
| 282 | + SCRIPTDATA.CURRENTRUNGROUP}(splitgroup))); |
287 | 283 | tsClear(newBeatIdx);
|
288 | 284 |
|
289 | 285 | t=toc(a);
|
|
296 | 292 | ts=TS{grIdx};
|
297 | 293 | fullFilename=fullfile(SCRIPTDATA.MATODIR, ts.filename);
|
298 | 294 | fprintf('Saving file: %s\n',ts.filename)
|
| 295 | + SCRIPTDATA.OUTFILENAME{end+1} = ts.filename; |
299 | 296 | save(fullFilename,'ts','-v6')
|
300 | 297 | end
|
301 | 298 | t=toc(a);
|
|
309 | 306 | if SCRIPTDATA.DO_INTEGRALMAPS == 1
|
310 | 307 | a=tic;
|
311 | 308 | if SCRIPTDATA.DO_DETECT == 0
|
312 |
| - msg=sprintf('Need fiducials (at least QRS wave or T wave) to do integral maps for %s. Aborting..', filename); |
| 309 | + msg=sprintf(['Need fiducials (at least QRS wave or T wave) to do integral ' ... |
| 310 | + 'maps for %s. Aborting..'], filename); |
313 | 311 | errordlg(msg)
|
314 | 312 | success = 0;
|
315 | 313 | return
|
316 | 314 | end
|
317 | 315 | mapindices = fidsIntAll(grIndices);
|
318 | 316 | if length(splitgroup)~=length(mapindices)
|
319 |
| - msg=sprintf('Fiducials (QRS wave or T wave) necessary to do integral maps. However, for %s there are no fiducials for all groups. Aborting...',filename); |
| 317 | + msg=sprintf(['Fiducials (QRS wave or T wave) necessary to do integral maps. '... |
| 318 | + 'However, for %s there are no fiducials for all groups. Aborting...'],filename); |
320 | 319 | errordlg(msg)
|
321 | 320 | success = 0;
|
322 | 321 | return
|
323 | 322 | end
|
324 | 323 |
|
325 | 324 |
|
326 |
| - fnames=ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-itg'); |
| 325 | + fnames=ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{... |
| 326 | + SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-itg'); |
327 | 327 |
|
328 | 328 | tsDeal(mapindices,'filename',fnames);
|
329 | 329 | tsSet(mapindices,'newfileext','');
|
|
333 | 333 | ts=TS{mapIdx};
|
334 | 334 | fullFilename=fullfile(SCRIPTDATA.MATODIR, ts.filename);
|
335 | 335 | fprintf('Saving file: %s\n',ts.filename)
|
| 336 | + SCRIPTDATA.ITGFILENAME{end+1} = ts.filename; |
336 | 337 | save(fullFilename,'ts','-v6')
|
337 | 338 | end
|
338 | 339 | tsClear(mapindices);
|
|
349 | 350 | a=tic;
|
350 | 351 |
|
351 | 352 | if SCRIPTDATA.DO_DETECT == 0 % 'Detect fiducials must be selected'
|
352 |
| - errordlg('Fiducials needed to do Activationsmaps! Select the ''Do Fiducials'' button to do Activationmaps. Aborting...') |
| 353 | + errordlg(['Fiducials needed to do Activationsmaps! Select the ''Do Fiducials'' '... |
| 354 | + 'button to do Activationmaps. Aborting...']) |
353 | 355 | return
|
354 | 356 | end
|
355 | 357 |
|
356 | 358 | %%%% make new ts at TS(mapindices). That new ts is like the old
|
357 | 359 | %%%% one, but has ts.potvals=[act rec act-rec]
|
358 | 360 | [mapindices, success] = sigActRecMap(grIndices);
|
359 | 361 | if ~success,return, end
|
360 |
| - tsDeal(mapindices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-ari')); |
| 362 | + tsDeal(mapindices,'filename',ioUpdateFilename('.mat',filename,SCRIPTDATA.GROUPEXTENSION{... |
| 363 | + SCRIPTDATA.CURRENTRUNGROUP}(splitgroup),'-ari')); |
361 | 364 | tsSet(mapindices,'newfileext','');
|
362 | 365 |
|
363 | 366 | %%%% save the 'new act/rec' ts as eg 'Run0009-gr1-ari.mat and clearTS{mapindex}
|
364 | 367 | for mapIdx=mapindices
|
365 | 368 | ts=TS{mapIdx};
|
366 | 369 | fullFilename=fullfile(SCRIPTDATA.MATODIR, ts.filename);
|
367 | 370 | fprintf('Saving file: %s\n',ts.filename)
|
| 371 | + SCRIPTDATA.ARIFILENAME{end+1} = ts.filename; |
368 | 372 | save(fullFilename,'ts','-v6')
|
369 | 373 | end
|
370 | 374 | tsClear(mapindices);
|
|
396 | 400 | qstart_indeces=find([TS{newBeatIdx}.fids.type]==2);
|
397 | 401 | qend_indeces=find([TS{newBeatIdx}.fids.type]==4);
|
398 | 402 | if isempty(qstart_indeces) || isempty(qend_indeces)
|
399 |
| - msg = sprintf('There is no qrs-wave for the file %s. Therefore, activation detection cannot be done for this file. Aborting...',TS{newBeatIdx}.filename); |
| 403 | + msg = sprintf(['There is no qrs-wave for the file %s. Therefore, activation '... |
| 404 | + 'detection cannot be done for this file. Aborting...'],TS{newBeatIdx}.filename); |
400 | 405 | errordlg(msg)
|
401 | 406 | success = 0;
|
402 | 407 | return
|
|
433 | 438 | if ~success, return, end
|
434 | 439 |
|
435 | 440 | if any((qe-qs) < 15)
|
436 |
| - msg = sprintf('The QRS-wave in beat %d is to small! This often causes the activation detetection to fail',newBeatIdx); |
| 441 | + msg = sprintf(['The QRS-wave in beat %d is to small! This often causes the '... |
| 442 | + 'activation detetection to fail'],newBeatIdx); |
437 | 443 | errordlg(msg)
|
438 | 444 | success = 0 ;
|
439 | 445 | return
|
|
442 | 448 | try
|
443 | 449 | for leadNumber=1:numchannels
|
444 | 450 | %for each lead in each group = for all leads..
|
445 |
| - %[act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,qs(leadNumber):qe(leadNumber)),win,deg)-1)/SCRIPTDATA.SAMPLEFREQ + qs(leadNumber); |
446 |
| - [act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,qs(leadNumber):qe(leadNumber)),win,deg)-1) + qs(leadNumber); |
| 451 | + %[act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,... |
| 452 | + %qs(leadNumber):qe(leadNumber)),win,deg)-1)/SCRIPTDATA.SAMPLEFREQ + qs(leadNumber); |
| 453 | + [act(leadNumber)] = (actFktHandle(TS{newBeatIdx}.potvals(leadNumber,... |
| 454 | + qs(leadNumber):qe(leadNumber)),win,deg)-1) + qs(leadNumber); |
447 | 455 | end
|
448 | 456 | catch
|
449 | 457 | errordlg('The selected function used to find the activations caused an error. Aborting...')
|
|
477 | 485 | tStartIndeces=find([TS{newBeatIdx}.fids.type]==5);
|
478 | 486 | tEndIndeces=find([TS{newBeatIdx}.fids.type]==7);
|
479 | 487 | if isempty(tStartIndeces) || isempty(tEndIndeces)
|
480 |
| - msg = sprintf('There is no t-wave for the file %s. Therefore, recovery detection cannot be done for this file. Aborting...',TS{newBeatIdx}.filename); |
| 488 | + msg = sprintf(['There is no t-wave for the file %s. Therefore, recovery '... |
| 489 | + 'detection cannot be done for this file. Aborting...'],TS{newBeatIdx}.filename); |
481 | 490 | errordlg(msg)
|
482 | 491 | success = 0;
|
483 | 492 | return
|
|
512 | 521 | if ~success, return, end
|
513 | 522 | try
|
514 | 523 | for leadNumber=1:numchannels
|
515 |
| - %rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,ts(leadNumber):te(leadNumber)),win,deg)/SCRIPTDATA.SAMPLEFREQ + ts(leadNumber); |
516 |
| - rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,ts(leadNumber):te(leadNumber)),win,deg) + ts(leadNumber); |
| 524 | + %rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,... |
| 525 | + %ts(leadNumber):te(leadNumber)),win,deg)/SCRIPTDATA.SAMPLEFREQ + ts(leadNumber); |
| 526 | + rec(leadNumber) = recFktHandle(TS{newBeatIdx}.potvals(leadNumber,... |
| 527 | + ts(leadNumber):te(leadNumber)),win,deg) + ts(leadNumber); |
517 | 528 |
|
518 | 529 | end
|
519 | 530 | catch
|
|
0 commit comments