-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwavedet_3D_extra.m
1932 lines (1844 loc) · 93.9 KB
/
wavedet_3D_extra.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function [position,positionaux,messages] = wavedet_3D(sigdir,headir,matdir,ecgnr,ft,anot,lead,t,flags,anot_fmt,aname,dirann,messages,bufferedSignal,bufferedHeaSig)
%[position,positionaux,messages] =wavedet_3D(sigdir,headir,matdir,ecgnr,ft,anot,lead,t,qrs_flag,anot_fmt,aname,dirann)
%Significant ECG points detector based on wavelet approach
%
%Input Parameters:
% sigdir: directory of the original signal (.dat file)
% headir: directory of the header file
% matdir: output directory
% ecgnr: string with the name of the record to analyze
% ft: format file:
% - 0 for MIT header using any recorded leads from same datafile
% - 1 for LUND header (to be tested)
% - 2 for data in matlab file (.mat file with a varible fa with sampling frequency and variable sinal with ecg, one lead per column)
% - 4 for RawData.bin files (one hour) created with Mortara Software SuperECG
%
% obsolete formats
% - 3 for MIT header using the Dower xyz (ft=0, leadsynth_flag=1)
% - 10 for MIT format in PTBDB .dat extension file (ft=0)
% - 30 for MIT type format in PTBDB .dat extension file use the projected xyz (ft=0, leadsynth_flag=1)
% - 20 for MIT type format in PTBDB .xyz extension file (ft=0, leads=leads+12)
% - 40 for MIT header using 3 PC based all available leads and signal (ft=0, leadsynth_flag=4,flagaux=0)
% - 41 for MIT header using 3 PC based in 8 leads and sub interval on the beat (ft=40,leadsynth_flag=3,flagaux=1)
% - 42 for MIT type format in PTBDB .dat extension file use the PC based all signal and 8 leads (ft=0,leadsynth_flag=3,flagaux=0)
% - 44 for MIT header using for MIT type using lead aVF and 2 PC out of precordial leads and all signal (ft=0,leadsynth_flag=5,flagaux=0)
% - 123 for RawData.bin files (one hour) created with Mortara Software SuperECG (ft=4)
% - 124 for RawData.bin files (one hour) created with Mortara Software SuperECG use the projected xyz (ft=4, leadsynth_flag=1)
% - 50 for MIT type format like in ft=0 file using the PC based all available leads and signal (ft=0, leadsynth_flag=4)
% - 51 for MIT type format like in ft=0 file using the PC based in 8 leads and sub interval on the beat (ft=0,leadsynth_flag=3,flagaux=1)
% - 52 for MIT type format like in ft=0 file use the PC based all signal and 8 leads (ft=40,leadsynth_flag=3,flagaux=0)
%
% anot: name of the annotation output file
% lead: vector with the leads number to analyze (1,2 or 3 leads)
% if lead is a cell array the first element stands for leads number to analyze from the ones read and
% the second for the leads to be read from the original signal file
% t=[tbegin tend]: time vector with initial and sample to analyze
% flags: [qrs_flag leadsynth_flag flagaux]
% qrs_flag: QRS detection only (2), External (1), internal (0) QRS detector (0 by default)
% leadsynth_flag: None (0), (default)
% Dower matrix derived VCG (1)
% Levkov's matrix derived VCG (2)
% Principal components based in 8 uncorrelated leads out of 12-lead standard (3)
% Principal components based in all available leads (4)
% lead aVF and Principal components based on precordial leads (5)
% flagaux: use all signal (0) (default) or sub interval on the beat (1) for PC calculation, available only for leadsynth_flag>2
%
% anot_fmt: cell with format in case of external annotation file
% first field for QRS detector, format of annotation file: MIT (0) or mat file (1)
% second field for with excluded segments: xls (0), MIT annotations (1)
% aname: cell with annotation file name with QRS marks in the first field (by default ecgnr)
% with annotation file name with excluded segments in the second field (by default aname{1})
% dirann: cell with directory with external annotation files (QRS marks and/or excluded segments, by default sigdir)
% if diferent annotation files are used, first field refers to QRS marks and second field to excluded segments
%
%Output Parameters:
% position: struct vector with the detected points locations in samples
%
% positionaux: struct vector with the detected points using each specified lead
% - positionaux.position1: using lead(1)
% - positionaux.position2: using lead(2)
% - positionaux.position3: using lead(3)
%
% messages: struct vector with errors, warnings, setup and state
% - messages.status=0,1;
% - messages.errors
% - messages.errors_desc
% - messages.warnings
% - messages.setup.wavedet.nsamp=nsamp; number of samples to process in each excerpt, consider to calculate some parameters (default 2^16/250*sf)
% - messages.setup.wavedet.sig_quality: sig_quality test 1 or 0 (activated or inactivated)
%
% struct description:
% Pon: P wave onset
% P: P wave peak
% Poff: P wave end
% QRSon: QRS complex onset
% Q: Q wave peak (in multilead, according to QRSonset best fitted lead)
% R_inQRSon: R wave peak in QRSonset best fitted lead (multilead only)
% R: R wave peak (median mark in multilead approach)
% qrs: QRS complex fiducial mark
% R_inQRSoff: R wave peak in QRSend best fitted lead (multilead only)
% Rprima: R' wave peak (in multilead, according to QRSend best fitted lead)
% S: S wave peak (in multilead, according to QRSend best fitted lead)
% QRSoff: QRS complex end
% Ton: T wave onset
% T: first T wave peak (median mark in multilead approach)
% Tprima: second T wave peak (in multilead, according to Tend best fitted lead)
% Toff: T wave end
% Ttipo: T wave morphology (1:5 corresponding respectively to normal, inverted, upwards only, downwards only, biphasc pos-neg, biphasc neg-pos)
% Tscale: scale used for T wave detection
% Ttipoon: T wave morphology, according to Tonset best fitted lead (multilead only)
% Ttipooff: T wave morphology, according to Tend best fitted lead (multilead only)
%
% warnings description:
% 'warning: there are not 8 uncorrelated leads, all available leads considered instead'
% leadsynth_flag=3 was used over a file that does not have all precordial leads and at least 2 of the limb leads
% leadsynth_flag=4 was automatically set
%
% 'warning: lead aVF not available, lead xpto considered instead'
% leadsynth_flag=5 was used over a file that does not have a lead aVF nor 2 limb leads to calculate it
% aVF was replaced by lead xpto
%
% 'warning: mV are assumed as units'
% not units are provided, mV are assumed
%
% The analysis loop has an overlapping structure. The number of samples
% processed is large and there are an overlap at the beginning and another
% at the end. The first one is necessary because: a) the first l4-1 samples
% are always incorrectly filtered b) To align the signals, as the filters
% have different lengths, we must discard some samples. c) The algorithms
% must have some possibility of turning back.
% The second overlap is mainly because of the alignment, as the filters have
% different delays.
%
% based on wavedet.m by Juan Pablo Mart�nez Cort�s
% previous versions include wavedetplus.m and wavedet3D.m
% Last update: Rute Almeida 23OCT2013
%
% Designed for MATLAB Version R12; tested with MATLAB Version R13
str = '1';
positionaux=[];
position=[];
aname_sig_quality_cell{3} = [];
% t_initial=0; % Juan 28/03/2012
if (nargin<14) % JB 27/07/2011
% bufferedSignal = []; % Juan 28/03/2012 No se usan no tienen porque
% estar definidas
% bufferedHeaSig = []; % Juan 28/03/2012
else % 03AGO 2011
ft=NaN;
heasig = bufferedHeaSig;
if ~isfield(heasig,'freq')
messages.errors=[messages.errors {'Fatal error in wavedet_3D: no sampling frequency variable found.'}];
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc {'No sampling frequency variable found on the header information file.'}];
messages.status=0;
return
end
if ~isempty(t) && length(t)==2 %& t(2)>t(1)
if length(bufferedSignal) == t(2)-t(1)+1;
sig_all =bufferedSignal(:,~isnan(bufferedSignal(1,:)));
% t_initial=t(1); % Juan 28/03/2012
t=[1 length(sig_all)];
elseif length(bufferedSignal)>t(2)
sig_all = bufferedSignal(:,t(1):t(2));
else
sig_all = bufferedSignal;
t=[1 length(sig_all)];
end
else
sig_all = bufferedSignal;
t=[1 length(sig_all)];
end
if size(sig_all,2)>size(sig_all,1)
sig_all=sig_all';
end
if ~isfield(heasig,'nsamp') || isempty(heasig.nsamp)
heasig.nsamp=size(sig_all,1);
end
if ~isfield(heasig,'nsig')
heasig.nsig=size(sig_all,2);
end
if ~isfield(heasig,'gain')
heasig.gain=200.*ones(1,heasig.nsig); % When heasig.gain = 0 => default 200
end
if ~isfield(heasig,'spf')
% heasig.spf=ones(1,max(heasig.nsig,leadreading)); % Juan
% 28/03/2012 leadreading no esta definido
heasig.spf=ones(1,max(heasig.nsig, size(sig_all,1)));
end
if ~isfield(heasig,'adczero')
heasig.adczero=zeros(1,heasig.nsig);
end
end
%%%%%%%%%%%%%%%%%%%%%%%
if nargin<13
messages.warnings=[];
end
if ~isfield(messages,'setup'), messages.setup.wavedet=[]; end
if ~isfield(messages.setup,'wavedet'), messages.setup.wavedet=[]; end
if ~isfield(messages,'errors'), messages.errors=[]; end
if ~isfield(messages,'errors_desc'), messages.errors_desc=[]; end
if ~isfield(messages,'warnings'), messages.warnings=[]; end
if isfield(messages,'status')
if messages.status~=1
messages.warnings=[messages.warnings {['Initial status=' num2str(messages.status) '. status changed to 1']}];
end
end
messages.status=1;
if nargin<7 %21MAR2011
messages.errors=[messages.errors {'Fatal error in wavedet_3D: not enough inputs.'}];
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc 'Mandatory inputs not defined.'];
messages.status=0;
return
elseif nargin<9
flags=[];
end
if iscell(lead)
if size(lead,2)==2
leadreading=(lead{2});
else
leadreading=(lead{1});
end
lead=lead{1};
else
leadreading=(lead);
end
if nargin<=10 %&& anot_fmt==1 %JUL2011
aname=ecgnr;
dirann=sigdir;
end%JUL2011
if iscell(aname)
if length(aname)==2
aname_sig_quality=aname{2};
end
aname=aname{1};
else
aname_sig_quality=aname;
end
if iscell(dirann)
if length(dirann)==2
dirann_sig_quality=dirann{2};
end
dirann=dirann{1};
else
dirann_sig_quality=dirann;
end
if isempty(flags)
if isfield(messages.setup.wavedet,'qrs_flag')
flags(1)=messages.setup.wavedet.qrs_flag;
else
flags(1)=0;
end
elseif isfield(messages.setup.wavedet,'qrs_flag') && flags(1)~=messages.setup.wavedet.qrs_flag;
messages.warnings=[messages.warnings {'Obsolete use of flag with inconsistency: flag(1) value differs from messages.setup.wavedet.qrs_flag value. flag(1) ignored.'}];
else
messages.setup.wavedet.qrs_flag=flags(1);
messages.warnings=[messages.warnings {['Obsolete use of flag. Use messages.setup.wavedet.qrs_flag=' num2str(flags(1)) 'instead.' ]}];
end
if length(flags)<2
if isfield(messages.setup.wavedet,'leadsynth_flag')
flags(2)=messages.setup.wavedet.leadsynth_flag;
else
flags(2)=0;
end
elseif isfield(messages.setup.wavedet,'leadsynth_flag') && flags(2)~=messages.setup.wavedet.leadsynth_flag;
messages.warnings=[messages.warnings {'Obsolete use of flag with inconsistency: flag(2) value differs from messages.setup.wavedet.leadsynth_flag value. flag(2) ignored.'}];
else
messages.setup.wavedet.leadsynth_flag=flags(2);
messages.warnings=[messages.warnings {['Obsolete use of flag. Use messages.setup.wavedet.leadsynth_flag=' num2str(flags(2)) 'instead.' ]}];
end
if length(flags)<3
if isfield(messages.setup.wavedet,'flagaux')
flags(3)=messages.setup.wavedet.flagaux;
else
flags(3)=0;
end
elseif isfield(messages.setup.wavedet,'flagaux') && flags(3)~=messages.setup.wavedet.flagaux;
messages.warnings=[messages.warnings {'Obsolete use of flag with inconsistency: flag(3) value differs from messages.setup.wavedet.flagaux. flag(3) ignored.'}];
else
messages.setup.wavedet.flagaux=flags(3);
messages.warnings=[messages.warnings {['Obsolete use of flag. Use messages.setup.wavedet.flagaux=' num2str(flags(3)) 'instead.' ]}];
end
if length(flags)==4
if isfield(messages.setup.wavedet,'nsamp') && messages.setup.wavedet.nsamp~=flags(4)
messages.warnings=[messages.warnings {'Obsolete use of flag with inconsistency: flag(4) value differs from messages.setup.wavedet.nsamp value. flag(4) ignored.'}];
else
messages.setup.wavedet.nsamp=flags(4);
messages.warnings=[messages.warnings {['Obsolete use of flag. Use messages.setup.wavedet.nsamp=' num2str(flags(4)) 'instead.' ]}];
end
end
qrs_flag=flags(1);
leadsynth_flag=flags(2);
flagaux=flags(3);
messages.setup.wavedet.qrs_flag=qrs_flag;
messages.setup.wavedet.leadsynth_flag=leadsynth_flag;
messages.setup.wavedet.flagaux=flagaux;
if ~isfield(messages.setup.wavedet,'sig_quality') || messages.setup.wavedet.sig_quality==0
messages.setup.wavedet.sig_quality=0;
messages.warnings=[messages.warnings {'No signal quality test used: messages.setup.wavedet.sig_quality=0'}];
else
if isfield(messages.setup.wavedet,'dirann_sig_quality')
dirann_sig_quality=messages.setup.wavedet.dirann_sig_quality;
elseif ~exist('dirann_sig_quality','var') || isempty(dirann_sig_quality)
dirann_sig_quality=sigdir;
end
if isfield(messages.setup.wavedet,'aname_sig_quality')
aname_sig_quality=messages.setup.wavedet.aname_sig_quality;
elseif ~exist('aname_sig_quality','var') || isempty(aname_sig_quality)
aname_sig_quality=ecgnr;
end
messages.setup.wavedet.sig_quality=1;
messages.warnings=[messages.warnings {['Signal quality information used: messages.setup.wavedet.sig_quality=' num2str(messages.setup.wavedet.sig_quality)]}];
end
if length(flags)==3
if leadsynth_flag<3
flagaux=0;
messages.warnings=[messages.warnings {'flagaux>0 only available for leadsynth_flag>2. flagaux=0 used'}];
end
end
%obsolete formats
if ft==3;
ft=0; leadsynth_flag=1;
end %obsolete formats
if ft==10
ft=0;
end %obsolete formats
if ft==20
ft=0;
lead=lead+12;
leadreading=leadreading+12;
end %obsolete format
if ft==30
ft=0;
leadsynth_flag=1;
leadreading=1:12;
end%obsolete formats
if ft==41
ft=0;
leadsynth_flag=3;
flagaux=1;
end %obsolete format
if ft==42||ft==52
ft=0;
leadsynth_flag=3;
flagaux=0;
end%obsolete formats
if ft==50
ft=0;
leadsynth_flag=4;
flagaux=0;
end%obsolete formats
if ft==51
ft=0;
leadsynth_flag=4;
flagaux=1;
end%obsolete formats
if ft==123
ft=4;
end% change format notation
if ft==124
ft=4;
leadsynth_flag=1;
end% change format notation
if ft==44
ft=0;
leadsynth_flag=5;
flagaux=0;
end%obsolete formats
if ft==40
ft=0;
leadsynth_flag=4;
flagaux=0;
end%obsolete formats
%number of leads from 1 to 3
if length(lead)>3
lead(4:end)=[];
messages.warnings=[messages.warnings {['Too many leads to process, just first 3 leads are considered: lead=[' num2str(lead) ']']}];
elseif isempty(lead)
lead=1;
leadreading=lead;
messages.warnings=[messages.warnings {'No leads indicated to process: first lead in file is considered'}];
end
if leadsynth_flag==1
leadstring='synt';
end
if leadsynth_flag==2
leadstring='levk';
end
if leadsynth_flag==1 || leadsynth_flag==2
%%%%%%%%%%%%%%%%%%%%%%%
%verify leads to process
invalid_lead= find(lead>3); %#ok<EFIND>
if ~isempty(invalid_lead)
[C,IA,IB]=intersect(leadreading,lead); %#ok<NASGU> % Juan 28/03/2012
if length(C)==length(lead)
lead=IA;
invalid_lead= find(lead>3); % Juan 28/03/2012
if isempty(invalid_lead)
messages.warnings=[messages.warnings {['the lead(s) chosen to be processed are the lead(s) ' num2str(leadreading(lead))]}];
else
alead=lead;
lead(invalid_lead)=[];
if isempty(lead)
lead=1:min(length(lead),3);
end
messages.warnings=[messages.warnings {[ 'Invalid lead for VCG analysis (' num2str(alead) '): transformed lead(s) ' num2str(1:min(length(lead),3)) ' considered instead.' ]}];
end
elseif ~isempty(C)
messages.warnings=[messages.warnings {[ 'Invalid lead for VCG analysis (' num2str(lead) '): transformed lead(s) ' num2str(leadreading(IA)) ' considered instead.' ]}];
lead=IA;
else
messages.warnings=[messages.warnings {[ 'Invalid lead for VCG analysis (' num2str(lead) '): transformed lead(s) ' num2str(1:min(length(lead),3)) ' considered instead.' ]}];
lead=1:min(length(lead),3);
end
end
%%%%%%%%%%%%%%%%
elseif leadsynth_flag==3
invalid_lead=find(lead>8);
lead(invalid_lead)=[];
if ~isempty(invalid_lead)
messages.warnings=[messages.warnings {'Invalid lead after the chosen PC transformation: 8 PC are produced.'}];
end
elseif leadsynth_flag==4
invalid_lead= find(lead>max(leadreading)); % Juan 28/03/2012
lead(invalid_lead)=[];
if ~isempty(invalid_lead)
messages.warnings=[messages.warnings {['Invalid lead after the chosen PC transformation: ' num2str(leadreading) ' PC are produced. Lead(s) ' num2str(lead) ' considered instead']}];
end
if isempty(lead)
lead=1;
messages.warnings=[messages.warnings {['Invalid lead after the chosen PC transformation: lead=[' num2str(lead) '] considered instead.']}];
end
elseif leadsynth_flag==5
if isempty(find(lead==1,1))
messages.warnings=[messages.warnings { 'Processing lead 1, standing for aVF, is mandatory in the chosen PC transformation.'}];
lead=[1 lead];
end
invalid_lead=find(lead>7);
lead(invalid_lead)=[];
if ~isempty(invalid_lead)
messages.warnings=[messages.warnings {'Invalid lead after the chosen PC transformation: aVF plus 6 PC are available.'}];
end
if isempty(lead)
lead=1:3;
messages.warnings=[messages.warnings {['Invalid lead after the chosen PC transformation: lead=[' num2str(lead) '] considered instead.']}];
elseif length(lead)>3
lead(4:end)=[];
messages.warnings=[messages.warnings {['Too many leads to process, just first 3 leads are considered: lead=[' num2str(lead) ']']}];
elseif length(lead)==1
messages.warnings=[messages.warnings { 'Single lead over lead aVF selected.' }];
end
end
global OPT
allfig=0;figuresoff=1; %#ok<NASGU>
OPT=optimset(@fminbnd);
OPT.MaxFunEvals=1000;
OPT.Display='off';
warning off %#ok<WNOFF>
ultimo_anot=1;
ultimo_anottyp=0;
% timeoffset=0; % Juan 28/03/2012 Solo se define para el formato lund si
% es necesario dentro
count=0;
%errores=struct('errores',[]);
if isunix, %%%%%%% Rute 13/03/02
sep = '/';
else sep = '\'; %%%%%%% Rute 13/03/02
end %%%%%%% Rute 13/03/02
PC_aux_ind=[];
aux=find(ecgnr==sep);
headir=[headir ecgnr(1:aux)];
sigdir=[sigdir ecgnr(1:aux)];
matdir=[matdir ecgnr(1:aux)];
if ~isempty(aux)
ecgnr=ecgnr(aux+1:end);
end
%%%%%%%%%%%%%%%%%%%%%%% file format %%%%%%%%%%%%%%%%%%%%%%%%%%%%
if ft==0 % MIT format files
name=[headir sep ecgnr '.hea'];
heasig = readheader(name);
[auxleads] = ecgleads(heasig.desc); %V1 V2 V3 V4 V5 V6 I II III aVR aVL aVF X Y Z VX VY VZ
%verify leads to read
if sum(leadreading>heasig.nsig)>0
messages.warnings=[messages.warnings {[ 'The selected file contains only ' num2str(heasig.nsig) ' signals: unable to read leads [' num2str(leadreading) '], leads out of the range will be ignored' ]}];
leadreading(leadreading>heasig.nsig)=[];
end
if leadsynth_flag==0 % should be leadreading=lead
if length(leadreading)~=length(lead) | (length(leadreading)==length(lead) & sort(leadreading)~=sort(lead)) %#ok<AND2,OR2>
[C,IA,IB]=intersect(leadreading,lead); %#ok<NASGU>
if length(C)==length(lead) % extra leads on leadreading will be deleted
leadreading=IA;
messages.warnings=[messages.warnings {['the lead(s) chosen to be processed are the lead(s) ' num2str(leadreading)]}];
else % extra leads on lead or different leads
if ~isempty(lead>heasig.nsig)
messages.warnings=[messages.warnings {[ 'The selected file contains only ' num2str(heasig.nsig) ' signals: unable to read leads [' num2str(lead) '], leads out of the range will be ignored' ]}];
lead=lead(lead<=heasig.nsig);
end
if length(leadreading)~=length(lead) | (length(leadreading)==length(lead) & sort(leadreading)~=sort(lead)) %#ok<AND2,OR2>
messages.warnings=[messages.warnings {[ 'unable to interpret the lead(s) number to process (' num2str(leadreading) '): lead(s) ' num2str(lead(lead<=heasig.nsig)) ' considered instead.' ]}];
leadreading=lead;
end
end
else
messages.warnings=[messages.warnings {['the lead(s) chosen to be processed are the lead(s) ' num2str(leadreading)]}];
end
elseif leadsynth_flag==1 || leadsynth_flag==2 || leadsynth_flag==3% Leads V1 to V6 and 2 limb leads required
if size(leadreading)<8 %wrong number of leads
if ~isnan(auxleads(1:8))
leadreading=(auxleads(1:8));
elseif ~isnan(auxleads([1:7 9]))
leadreading=(auxleads([1:7 9]));
elseif ~isnan(auxleads([1:6 8 9]))
leadreading=(auxleads([1:6 8 9]));
else
messages.errors=[messages.errors {'Fatal error in wavedet_3D: not enough leads in file to apply the chosen transformation.'}];
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc 'Leads V1 to V6 and 2 limb leads are required.'];
messages.status=0;
return
end
messages.warnings=[messages.warnings {['Not enough leads to apply the chosen transformation in given leadreading: leadreading=[' num2str(leadreading) '] considered instead' ]}];
else
if sum(isnan(auxleads(1:6)))>0 || sum(isnan(auxleads(7:9)))>1 % heasig.desc does not include Leads V1 to V6 and 2 limb leads
if heasig.nsig>=8
messages.warnings=[messages.warnings {'Leads V1 to V6 and 2 limb leads required to apply the chosen transformation but cannot be recognized. It is assumed that the first 8 leads of leadreading are V1 V2 V3 V4 V5 V6 I II'}];
leadreading=leadreading(1:8);
auxleads=NaN*ones(size(auxleads));
auxleads(1:8)=1:8;
else
messages.errors=[messages.errors {'Fatal error in wavedet_3D: not enough leads in file to apply the chosen transformation.'}];
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc 'Leads V1 to V6 and 2 limb leads are required.'];
messages.status=0;
return
end
else % heasig.desc includes Leads V1 to V6 and 2 limb leads
leadreading=leadreading(auxleads(auxleads<=length(leadreading)));% sort leadreding as V1 V2 V3 V4 V5 V6 I II III aVR aVL aVF X Y Z VX VY VZ
end
end
elseif leadsynth_flag==4 && size(leadreading)==1
leadsynth_flag=0;
messages.warnings=[messages.warnings {'To aply PC transformation more than one lead is requires in leadreading: no trasnformation applied (leadsynth_flag=0)'}];
elseif leadsynth_flag==5 && length(lead)~=1 % aVL and leads V1 to V6 required
if size(leadreading)<7 %wrong number of leads
if ~isnan(auxleads([12 1:6])) %lead aVF and V1 to V6 available
leadreading=auxleads([1:6 12]);
elseif ~isnan(auxleads(1:8))
leadreading=auxleads(1:8);
elseif ~isnan(auxleads([1:7 9]))
leadreading=auxleads([1:7 9]);
elseif ~isnan(auxleads([1:6 8 9]))
leadreading=auxleads([1:6 8 9]);
else
messages.errors=[messages.errors {'Fatal error in wavedet_3D: not enough leads in file to apply the chosen transformation.'}];
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc 'Leads aVF and V1 to V6 are required. Sugestion: use leadsynth_flag=4 instead'];
messages.status=0;
return
end
else
if sum(isnan(auxleads(1:6)))>0 || (isnan(auxleads(12)) && sum(isnan(auxleads(7:9)))>1) % heasig.desc does not include Leads V1 to V6 and aVF cannot be calculated
if size(leadreading)==7 && heasig.nsig>=7
messages.warnings=[messages.warnings {'Leads V1 to V6 and aVF limb leads required to apply the chosen transformation but cannot be recognized. It is assumed that the 7 leads of leadreading are V1 V2 V3 V4 V5 V6 aVF' }];
leadreading=leadreading(1:7);
auxleads=NaN*ones(size(auxleads));
auxleads([1:6 12])=1:7;
elseif heasig.nsig>=8
messages.warnings=[messages.warnings {'Leads V1 to V6 and aVF limb leads required to apply the chosen transformation but cannot be recognized. It is assumed that the first 8 leads of leadreading are V1 V2 V3 V4 V5 V6 aVF' }];
leadreading=leadreading(1:8);
auxleads=NaN*ones(size(auxleads));
auxleads(1:8)=1:8;
else
messages.errors=[messages.errors {'Fatal error in wavedet_3D: not enough leads in file to apply the chosen transformation.'}];
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc 'Leads aVF and V1 to V6 are required. Sugestion: use leadsynth_flag=4 instead'];
messages.status=0;
return
end
else % heasig.desc includes Leads V1 to V6 and 2 limb leads
leadreading=leadreading(auxleads(auxleads<=length(leadreading)));% sort leadreding as %V1 V2 V3 V4 V5 V6 I II III aVR aVL aVF X Y Z VX VY VZ
end
end
elseif leadsynth_flag==5 && length(lead)==1
if ~isnan(auxleads(12))
leadreading=auxleads(12);
elseif sum(~isnan(auxleads(7:9)))>1
leadreading=auxleads(~isnan(auxleads(7:9)));
elseif length(leadreading)==1
messages.warnings=[messages.warnings {'Lead aVF lead is required but cannot be recognized. It is assumed that the first lead of leadreading is aVF'}];
leadreading=1;
auxleads=NaN*ones(size(auxleads));
auxleads(12)=1;
else
messages.warnings=[messages.warnings {'Lead aVF lead is required but cannot be recognized. It is assumed that the first 2 lead of leadreading are I and II'}];
auxleads=NaN*ones(size(auxleads));
auxleads(7:8)=1:2;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% this is necessary when there are leads in different files. e.g. ptbdb database JP 2006
leadsfile=NaN*ones(heasig.nsig,1);
leadinfile=NaN*ones(heasig.nsig,1);
nsiginfile=NaN*ones(heasig.nsig,1);
for jj=1:heasig.nsig
for kk=1:heasig.nsig
leadsfile(kk)=strcmp(heasig.fname(jj,:),heasig.fname(kk,:));
end
leadsfile = cumsum(leadsfile);
leadinfile(jj) = leadsfile(jj); % lead indexes in the file
nsiginfile(jj) = leadsfile(end); % number of the leads in th file nsiginfile<=heasig.nsig
end
if(min(lead)>nsiginfile(1))
auxleads(auxleads<=nsiginfile(1))=NaN;
else
auxleads(auxleads>nsiginfile(1))=NaN;
end
n_auxleads=find(auxleads>0);
auxleads(n_auxleads)=leadinfile(auxleads(n_auxleads));
% nsiginfile=nsiginfile(lead(1)); % Juan 28/03/2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%
if (heasig.fmt(lead)==16) | (heasig.fmt(lead)==212) | (heasig.fmt(lead)==61), %#ok<OR2>
%%%%%%% multilead%%% Rute 02.Dec.04
if size(lead,2)==1
formato = num2str(heasig.fmt(lead));
elseif diff(heasig.fmt(lead))==0
formato = num2str(heasig.fmt(lead(1)));
end
%%%%%%%%%%%%%
else
messages.errors=[messages.errors {'This format is not supported by the program.'}];
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc ['Format ' num2str(heasig.fmt(lead)) ' data. For MIT data, formats 16, 212 and 61 are supported.'] ];
messages.status=0;
return
end
if strcmp(formato,'16')||strcmp(formato,'61'),
fid = fopen([sigdir heasig.fname(lead(1),:)],'rb');
fseek(fid,0,-1); % Rewind the file
if strcmp(heasig.fname(1,1),'_'), % Siemens card recordings with MIT-type header
timeoffset=512;
fseek (fid, timeoffset,-1); % offset
end
end
elseif ft==1 % LUND format files
try
hdsig=gethdsig(sigdir,ecgnr); % Reading header information
heasig = hdsig2heasig(hdsig);
leadinfile=lead;
[auxleads] = ecgleads(heasig.desc);
catch me
messages.errors=[messages.errors {'Fatal error in wavedet_3D: unable to read header signal on Lund format.'}];
warning(char(messages.errors{end}))
messages.errors_desc=[messages.errors_desc {me.message}]; % Juan 28/03/2012
messages.status=0;
return
end
elseif ft==2 % data in a Matlab file
try
[sig_all,messages1,heasig] = readsignal(sigdir,ecgnr,t,ft,[],leadreading,messages); % Juan 28/03/2012
if messages1.status==0
error('Fatal error in wavedet_3D: unable to read signal on mat format.'); % Juan 28/03/2012
end
catch me
messages.errors=[messages.errors {messages1.errors}]; % Juan 28/03/2012
warning(char(messages.errors{end}))
messages.errors_desc=[messages.errors_desc {me.message}]; % Juan 28/03/2012
messages.status=0;
return
end
if size(sig_all,2)>size(sig_all,1)
sig_all=sig_all';
end
%should not be needed; I will remove that part, all of that is done in
%readsignal Juan 28/03/2012
if ~exist('heasig','var')
heasig.nsamp=size(sig_all,1);
try
if exist('fa','var')
heasig.freq=fa; %#ok<NODEF>
else
heasig.freq=messages.setup.wavedet.freq;
end
catch me
messages.errors=[messages.errors {'Fatal error in wavedet_3D: no sampling frequency variable found.'}];
warning(char(messages.errors{end}))
me1.message = 'No sampling frequency variable found on the mat file.'; % Juan 28/03/2012
messages.errors_desc=[messages.errors_desc {me1.message}]; % Juan 28/03/2012
messages.status=0;
return
end
heasig.nsig=size(sig_all,2);
heasig.gain=200.*ones(1,heasig.nsig); % When heasig.gain = 0 => default 200
heasig.adczero=zeros(1,heasig.nsig);
end
%%%%%%%%%%%%%%%%%%%%%%%
leadinfile=lead;
% nsiginfile=heasig.nsig; %Juan 28/03/2012
heasig.spf_ecg=1;
if isfield(heasig,'desc')
[auxleads] = ecgleads(heasig.desc);
else
auxleads = 1:heasig.nsig; % assuming that all are ECG
end
elseif ft==4 % Ana e Tiago 11-04-2006 (copy from wavedetplus)
fa=1000;
% aux=[sigdir ecgnr '.bin']; Juan 28/03/2012
if nargin >=8,
if isempty(t)
t=[1 fa*60*60];
% else
% t=[t(1) min(t(1)+fa*60*60,t(2))];
end
else
t=[1 fa*60*60];
end
% first_sample=t(1); %ver com Sonia se '1 -1 pq first_sample=0 por
% defeito!!!! Juan 28/03/2012
% n_sample_per_lead=t(end);Juan 28/03/2012
% lead_number=lead;Juan 28/03/2012
heasig.nsamp=t(2)-t(1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%
heasig.freq=fa;
heasig.gain=200;
heasig.nsig=12;
heasig.units=char(ones(heasig.nsig,1)*'microV');
heasig.desc=['I ';'II ';'V1 ';'V2 ';'V3 ';'V4 ';'V5 ';'V6 ';'III';'aVR';'aVL';'aVF'];
[auxleads] = ecgleads(heasig.desc);
leadinfile=lead;
% nsiginfile=heasig.nsig;
elseif isnan(ft) % data in buffer % 03AGO 2011
leadinfile=lead;
% nsiginfile=heasig.nsig; Juan 28/03/2012
heasig.spf_ecg=1;
if ~isfield(heasig,'nsamp') || heasig.nsamp<=0
heasig.nsamp=size(sig_all,1);
end
if isfield(heasig,'desc')
[auxleads] = ecgleads(heasig.desc);
else
auxleads = 1:heasig.nsig; % assuming that all are ECG
end
else
try
[sig_all,messages1,heasig] = readsignal(sigdir,ecgnr,t,ft,[],leadreading,messages);
if messages1.status==0
error('Fatal error in wavedet_3D: no admissible format.'); % Juan 28/03/2012
end
catch me
messages.errors=[messages.errors {messages1.errors}];
me1.message = 'Format ft should be one of {0,1,2,4}. See help wavedet3D for details.'; % Juan 28/03/2012
warning(char(messages.errors(end)))
messages.errors_desc=[messages.errors_desc {me1.message}]; % Juan 28/03/2012
messages.status=0;
return
end
if size(sig_all,2)>size(sig_all,1)
sig_all=sig_all';
end
if isfield(heasig,'desc')
[auxleads] = ecgleads(heasig.desc);
else
auxleads = 1:heasig.nsig; % assuming that all are ECG
end
end
% leadinfile=lead; % Juan 28/03/2012 definido dentro de cada formato
% nsiginfile=heasig.nsig; % Juan 28/03/2012 parece que no se usa m�s no es
% necesario definir
if ~isfield(heasig,'spf')
heasig.spf=ones(1,heasig.nsig);
end
try
heasig.spf_ecg=heasig.spf(leadinfile(1));
catch me
me1.message = 'It is taken the first lead in file.';
messages.warnings = [messages.warnings {me1.message}];
heasig.spf_ecg=heasig.spf(1);
end
% messages.setup.wavedet.freq=heasig.spf_ecg*heasig.freq; %13ENE2010
messages.setup.wavedet.freq=heasig.spf_ecg*heasig.freq; %13ENE2010
% if isfield(heasig,'desc')
% [auxleads] = ecgleads(heasig.desc);
% else
% auxleads = 1:heasig.nsig; % assuming that all are ECG
% end
% at this point heasig must exist
if isfield(messages.setup.wavedet,'nsamp')
nsamp = messages.setup.wavedet.nsamp; % Number of samples per excerpt for the WT as input
else
nsamp=0;
end
if nsamp==0
% nsamp = 2^16/250*messages.setup.wavedet.freq; % Number of samples per excerpt for the WT corresponding to 2^16 samples at sf=250
nsamp = 2^16/250*heasig.freq*max(heasig.spf(leadreading)); % Number of samples per excerpt for the WT corresponding to 2^16 samples at sf=250
end
messages.setup.wavedet.nsamp=nsamp;
if nargin >=8,
if isempty(t)
t=[1 heasig.nsamp]; % pode falhar em formato lund...
else
t(1)=max(t(1),1);
if ~isempty(heasig.nsamp)
% if ft == 2
t(2)=min(t(1)+heasig.nsamp*heasig.spf_ecg-1,t(2));
% else
% t(2)=min(t(1)+heasig.nsamp-1,t(2));
% end
end
end
else
t=[1 heasig.nsamp];
end
if flagaux==1
if isfield(messages.setup.wavedet,'leadsynth')
leadref= messages.setup.wavedet.leadsynth;
messages.warnings=[messages.warnings {'Lead' num2str(leadref) ' will be considered for PCA time interval.'}];
else
if ~isnan(auxleads(8)); %lead II
leadref=auxleads(8);
else
messages.warnings=[messages.warnings {'Lead II not available. First selected lead would be considered instead.'}];
warning(char(messages.warnings(end)));
leadref=lead(1);
end
end
if ~exist([matdir ecgnr '.s' num2str(leadref)],'file')
wavedet_3D(sigdir,headir,matdir,ecgnr,ft,['s' num2str(leadref)],leadref);
end
marks=readannot([matdir ecgnr '.s' num2str(leadref)]);
if exist('marks','var')
marks=posmat2(marks);
marks(marks==0)=NaN;
end
PC_aux_ind= [];
tol1=0;tol2=0; tol3=200;
mark_on=4;mark_off=10;mark_on2=5; mark_off2=6; % QRSonset-tend
% mark_on=7;mark_off=10;mark_on2=6;mark_off2=10; % ton-tend
% mark_on=8;mark_off=10;mark_on2=6;mark_off2=10;% tpeak-tend
% mark_on=4;mark_off=6;mark_on2=4;mark_off2=6;% QRS based
for tt=1:size(marks,1)
if ~isnan(marks(tt,mark_off)) & ~isnan(marks(tt,mark_on))%#ok<AND2> %
PC_aux_ind=[PC_aux_ind round((marks(tt,mark_on)-tol1)):round((marks(tt,mark_off)+tol2))]; %#ok<AGROW>
elseif ~isnan(marks(tt,mark_on))& ~isnan(marks(tt,mark_off2))%#ok<AND2> %
PC_aux_ind=[PC_aux_ind round((marks(tt,mark_on)-tol1)):(marks(tt,mark_off2)+tol3)]; %#ok<AGROW>
elseif ~isnan(marks(tt,mark_on2))& ~isnan(marks(tt,mark_off))%#ok<AND2> %
PC_aux_ind=[PC_aux_ind round((marks(tt,mark_on2)-tol3)):(marks(tt,mark_off)+tol2)]; %#ok<AGROW>
else
PC_aux_ind=[PC_aux_ind round((marks(tt,5)-tol3)):(marks(tt,5)+tol3)]; %#ok<AGROW>
end
end
else
PC_aux_indaux= 1:(t(2)-t(1)+1); %EXARLE OJO %PC_aux_indaux=[];%alternativa
end
try
heasig.gain(heasig.gain==0)=200; % When heasig.gain = 0 => default 200
catch me
me1.message = 'Signal gain is set to 200'; % Juan 28/03/2012
messages.warnings = [messages.warnings {me1.message}]; % Juan 28/03/2012
end
% Reading of external QRS annotation file if qrs_flag
if qrs_flag==1 % The QRS fiducial point is read from external annotator
switch (anot_fmt);
case 0 % MIT annotation file
if exist([dirann filesep aname],'file')%Jul2011 % Jbolea 01/12/11
s=readannot([dirann aname],t);
s=isqrs(s,heasig,t);
ext_anot=s.time';
else error('QRS annotation file not found');
end
case 1
aname1 = aname; % Julia 27/11/2013
% if ~isempty(strfind(aname1,'_hea.mat'))% mat file
% aname1(strfind(aname1,'_hea.mat'):end) = [];
% end
if exist([dirann aname1],'file')%Jul2011
% if exist([dirann aname '.mat'],'file')%Jul2011
try
s= readannot_mat(dirann, aname1,'tm_qrs');%OCT2012
s.tm_qrs.pos = round(s.tm_qrs.pos*heasig.freq/1000);
ext_anot=s.tm_qrs.pos(s.tm_qrs.pos >= t(1)&s.tm_qrs.pos <= t(2));%OCT2012
catch me
messages.warnings=[messages.warnings {me.message}];
try
s= readannot_mat(dirann, aname1,'qrs');%DEC2011
s.qrs.pos = round(s.qrs.pos*heasig.freq/1000);
catch
s= readannot_mat(dirann, aname1,'qrs_hrv');%DEC2011
s.qrs.pos = round(s.qrs_hrv.pos*heasig.freq/1000);
end
ext_anot=s.qrs.pos(s.qrs.pos >= t(1)&s.qrs.pos <= t(2));%Jul2011 % Jbolea 01/12/11
end
% aux_t=t/heasig.freq/60/60; %%%???? ver heasig.freq % Juan
% 28/03/2012
%s=load ([dirann aname]);
%kk=getfield(s);%JUL2011
% eval(['ext_anot=s.qrs;']);
else error('QRS annotation file not found');
end
otherwise
messages.warnings=[messages.warnings {'Bad annotation format for external QRS annotation file; internal annotator would be considered instead.'}];
warning(char(messages.warnings(end)));
qrs_flag=0;
end
end
messages.setup.wavedet.qrs_flag=qrs_flag;
messages.setup.wavedet.leadsynth_flag=leadsynth_flag;
messages.setup.wavedet.flagaux=flagaux;
%%%%%%%%%%%%%%%%%%%%%%% Initiliazation %%%%%%%%%%%%%%%%%%%%%%%%%%%%
inisamp = t(1);
endsamp = t(1)-1; %15MAR09
timeqrs1 = [];timeqrs2 = [];timeqrs3 = [];
lastqrs1 = 1;lastqrs2 = 1;lastqrs3 = 1;
if qrs_flag==0 || qrs_flag==2 % estimated maximum number of beats
maxlength = round((t(2)-t(1))/messages.setup.wavedet.freq*2);
else maxlength=length(ext_anot);
end
if qrs_flag==1,
sel=find(ext_anot<messages.setup.wavedet.freq);
if ~isempty(sel)
ext_anot(sel)=[];
maxlength= length(ext_anot);
end
end
nanvec = nan*ones(1,maxlength);
position=struct('Pon',nanvec,'P',nanvec,'Poff',nanvec,...
'Pprima',nanvec,'Pscale',nanvec,'Ptipo',nanvec,...
'QRSon',nanvec,'Q',nanvec,'R',nanvec,'Rprima',nanvec,'S',nanvec,'QRSoff',nanvec,...
'qrs',zeros(1,maxlength),...
'R_inQRSoff',nanvec,'R_inQRSon',nanvec,...
'Ton',nanvec,'T',nanvec,'Tprima', nanvec,'Toff',nanvec,'Ttipo',nanvec,...
'Tscale',nanvec,'Ttipoon',nanvec,'Ttipooff',nanvec,'contadorToff',nanvec,...
'QRSonsetcriteria',nanvec,'QRSoffcriteria',nanvec,...
'QRSpa',nanvec,'QRSpp',nanvec,...
'QRSmainpos',nanvec,'QRSmaininv',nanvec);
position1=position;
position2=position;
position3=position;
position0=position;
%messages.errors=[messages.errors errores.errores];
if qrs_flag==1, position.qrs=ext_anot; end
% numlatdet = 0; % Number of detected beats until now % Juan
% 28/03/2012 no se usa despues
numlatdet1 = 0;
numlatdet2 = 0;
numlatdet3 = 0;
if ~isfield(messages.setup.wavedet,'filter_bank_design') || messages.setup.wavedet.filter_bank_design~=1 % Rute 24/11/11
messages.setup.wavedet.filter_bank_design=0; % Rute 24/11/11
[q1,q2,q3,q4,q5,messages] = qspfilt5(messages.setup.wavedet.freq,messages); % WT equivalent filters % Rute 22/05/02
if messages.status==1
l1=length(q1);l2=length(q2);l3=length(q3);l4=length(q4);
d1=floor((l1-1)/2);d2=floor((l2-1)/2);
d3=floor((l3-1)/2);d4=floor((l4-1)/2);
l5=length(q5);d5=floor((l5-1)/2); % Rute 22/05/02
begoverlap = l5+2* messages.setup.wavedet.freq; % l5 + 2 sec.
endoverlap = d5;
messages.warnings=[messages.warnings {'Default filter banks are used.'}];
warning(char(messages.warnings(end)));
else
messages.setup.wavedet.filter_bank_design=1; % Rute 24/11/11
messages.status=1;
end
end
%%%% % Rute 24/11/11
if messages.setup.wavedet.filter_bank_design==1;
MaxScales=5;
filters_cache_filename = ['wt_filters_' num2str(MaxScales) ' scales_' num2str(messages.setup.wavedet.freq) ' Hz.mat' ];
% check it form setup
if( exist(filters_cache_filename, 'file') )
load( filters_cache_filename );
else
q_filters = qs_filter_design(MaxScales, messages.setup.wavedet.freq); %ver spf
try
save([fileparts(which('wavedet_3D')) sep filters_cache_filename],'q_filters')
catch me
me.messages = ['Fatal error saving ' filters_cache_filename ' on ' fileparts(which('wavedet_3D')) '; please check folder permissions'];
messages.warnings = [messages.warnings {me.messages}];
end
end