/
BlockEdfSignalRasterView.m
1263 lines (1129 loc) · 56.6 KB
/
BlockEdfSignalRasterView.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
classdef BlockEdfSignalRasterView
%BlockEdfSignalRasterView Create a signal raster plot from EDF
% Function creates a raster plot from signals stored in an EDF file.
% The x axis of the raster plot represents time and the y axis
% presents seqential time segment. The X axis duration and number of
% segments to display on the y axis options are predefined to values most
% likely to be used in sleep and circadian research. Gridlines corresponding
% to 30 second sleep epochs are automatically displayed. The function can
% be used to create MATALB figures and can be used to create power
% point summaries.
%
% Function prototypes:
%
% obj = BlockEdfSignalRasterView % Generate Class
% opt = obj.opt\n') % Get option structure
% obj = BlockEdfSignalRasterView(fn|edfStruct, signalLabelCell)
% obj = BlockEdfSignalRasterView(fn|edfStruct, signalLabelCell, opt)
% obj = BlockEdfSignalRasterView(fn|edfStruct, signalLabelCell, opt, anote)
%
% fn : file name with path included
% edfStruct : Struct(header, signalHeader, signalCell) created
% from BlockEdfLoad or BlockEdfLoadClass
% signalLabelCell : A cell array of an EDF signal labels, {'edf signal lablel'}
% opt : A list of options which provide fine control of
% raster generation
% anotations : An array of times to mark on the raster plot
%
% Public Properties:
%
% Optional Properties:
% subjectID : For figure and PPT titles
% annotateSignalTimes : Array of times to annotate time series
%
% Figure Properties:
% percentile_range : [10 90]: Select data percentiles to include
% when scaling data, [10 90]
% signalToView : Need to select signals to display {'Pleth', 'EKG'};
% Recommended to only use one signal.
% Feature may be removed in future release
% signalDisplayGain : Set display gain indivudal gain (non zero factor);
% signalDefaultGain : if signalDisplayGain not set: 0.25;
% imageResolution : Image resolution defined as a string ('100')
% setFigurePosition : Set figure position flag (0);
% figurePosition : Figure position [x,y,w,h];
% xAxisScale : Index of private property (see xTickValues below);
% numSignalsPerPageIndex : Index of private property (see w below);
% AnnoteMarkerSize : 10;
%
% Setting Raster Properties:
% The three most common adjustments required for generating signal
% raster plots are descibed below:
%
% (1) Set x axis duration.The x axis duration is set by selecting an
% index to the w array. The w array durations are:
%
% 1, 2, 5, 10, 15, 20, 30 seconds
% 1, 2, 2.5, 3, 5, 10, 15, 20 30 40 45 minutes
% 1, 2, 3, 4, 6, 8, 12, 14 hours
%
% example:
% Setting obj.xAxisScale = 14; prior to creating figures or a
% powerpoint will set the raster x axis to 15 minute
%
% (2) Set number of segments to display. The number of segments is
% set by indexing numSignalsPerPage. The numSignalsPerPage
% values are:[1 2 3 4 5 6 10 12 20 24 30 60]
%
% example:
% Setting obj.numSignalsPerPageIndex = 8; prior to creating figures or a
% powerpoint will set the number of segments displayed to 12.
%
% (3) Change signal scale. Set signalDisplayGain to adjust signal
% scaling. Values between .2 and 8 generally work best.
%
% Reccomendations
% New users may want to model function calls around test cases which
% are distributed with this file. More advance user may want to review
% the private properties. If you are very new to programming you may want to
% use the gui SignalRasterView.
%
% Warning:
% The program can generate a large number of figures. Care must be
% taken to not exceed memory/system limitations.
%
%
% Version: 0.1.28
%
% ---------------------------------------------
% Dennis A. Dean, II, Ph.D
%
% Program for Sleep and Cardiovascular Medicine
% Brigam and Women's Hospital
% Harvard Medical School
% 221 Longwood Ave
% Boston, MA 02149
%
% File created: October 23, 2012
% Last update: April 25, 2014
%
% Copyright © [2012] The Brigham and Women's Hospital, Inc. THE BRIGHAM AND
% WOMEN'S HOSPITAL, INC. AND ITS AGENTS RETAIN ALL RIGHTS TO THIS SOFTWARE
% AND ARE MAKING THE SOFTWARE AVAILABLE ONLY FOR SCIENTIFIC RESEARCH
% PURPOSES. THE SOFTWARE SHALL NOT BE USED FOR ANY OTHER PURPOSES, AND IS
% BEING MADE AVAILABLE WITHOUT WARRANTY OF ANY KIND, EXPRESSED OR IMPLIED,
% INCLUDING BUT NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY AND
% FITNESS FOR A PARTICULAR PURPOSE. THE BRIGHAM AND WOMEN'S HOSPITAL, INC.
% AND ITS AGENTS SHALL NOT BE LIABLE FOR ANY CLAIMS, LIABILITIES, OR LOSSES
% RELATING TO OR ARISING FROM ANY USE OF THIS SOFTWARE.
%
%---------------------------------------------------- Public Properties
properties
% Input Properties
edf_fn = '';
% Optional parameters
subjectID = '' % For figure and PPT titles
annotateSignalTimes % Array of times to annotate time series
% Figure parameters
percentile_range = [10 90]; % Select data to include in scale
signalToView % Need to select signal to display {'Pleth'};
signalDisplayGain % Need to select indivudal gain:[.5, 0.25];
signalDefaultGain % Default if signalDisplayGain not set: 0.25;
% figure Parameters
imageResolution = 100;
setFigurePosition = 0;
figurePosition = [];
xAxisScale = 12;
numSignalsPerPageIndex = 8;
xGridInc = 1;
yGridInc = 0.05;
% Annotation Parameters
AnnoteMarkerSize = 10;
AnnoteMarker = 'x';
AnnoteColor = [1 0 0];
AnnoteLabel = '';
AddEpochNumbers = 1;
% PPT Parameters
PptBySignal = 0; % 0: Generate rasterplot figure
% 1: Generate rasterplot figures and create
% MS PowerPoint file
end
%------------------------------------------------- Dependent Properties
properties (Dependent)
% Input Propertied
num_signals % Number of signals in EDF
edf_signals_labels % signal lables for EDF
opt % Option structure
numSignalsToView % Size of signal sto view
% Derrived properties
totalNumPages % Total number of print pages under current
% x and y axis settings
% Display properties
signalDisplayGainDefault % Default to (0.4) gain)
% Output Properties
fig_ids % Figure IDs for generated figures
figCell % Support for multiple signals
window_epochs % Array of allowable window epochs
end
%--------------------------------------------------- Private Properties
properties (GetAccess = private)
% Input Properteis
arg1 % First argument
num_args % Number of arguments for
signal_list % Signals available for display
signalIndexes % Indexes of signals to display
userOpt = []; % User defined options
% EDF Properties
edf_header % EDF header structure from blockEdfLoad
edf_signal_header % EDF signal header structure
edf_signal_cell_arrray % EDF signal cell array
% plot constants
plotProportion = 8.5/11;
w = [1, 2, 5, 10, 15, 20, 30, 60, ...
2*60, 2.5*60, 3*60, 5*60, 10*60, 15*60, ...
20*60, 30*60, 40*60, 45*60, 60*60, ...
2*60*60, 3*60*60, 4*60*60, 6*60*60, ...
8*60*60, 12*60*60, 24*60*60]';
xTickValues = ...
{[0:.2:1]; [0:0.5:2]; [0:1:5]; ...
[0:2:10]; [0:5:15]; [0:5:20]; ...
[0:5:30]; [0:15:60]; [0:30:2*60]; ...
[0:30:2.5*60]; ...
[0:30:3*60]; [0:30:5*60]; [0:300:10*60]; ...
[0:5*60:15*60]; [0:5*60:20*60]; [0:10*60:30*60]; ...
[0:10*60:40*60]; [0:15*60:45*60]; [0:15*60:60*60]; ...
[0:30*60:2*60*60]; [0:60*60:3*60*60]; [0:60*60:4*60*60];...
[0:2*60*60:6*60*60]; [0:2*60*60:8*60*60]; ...
[0:3*60*60:12*60*60]; [0:6*60*60:24*60*60]};
% xTickValues = {[0:5:30], [0:10:60]};
xTickLabels = ...
{{' 0 ', '0.2', '0.4', '0.6', '0.8', ' 1 '}; ...
{' 0 ', '0.5', '1.0', '1.5', ' 2 '};...
{'0', '1', '2', '3', '4', '5'}; ...
{'0 ', '2 ', '4 ', '5 ', '8 ', '10'}; ...
{'0 ', '3 ', '6 ', '9 ', '12', '15'};...
{'0 ', '5 ', '10', '15', '20'}; ...
{'0 ', '5 ', '10', '15', '20', '25', '30'}; ...
{'0 ', '15', '30', '45', '60'};...
{' 0 ', '0.5', ' 1 ', '1.5', '2.0'};...
{' 0 ', '0.5', ' 1 ', '1.5', '2.0', '2.5'};...
{'0', '1', '2', '3'}; ...
{'0', '0.5', '1', '1.5', '2', '2.5', '3', '3.5', '4', '4.5', '5'}; ...
{'0 ', '5 ', '10'};...
{'0 ', '5 ', '10', '15'};...
{'0 ', '5 ', '10', '15', '20'};...
{'0 ', '10', '20', '30'};...
{'0 ', '10', '20', '30', '40'};...
{'0 ', '15', '30', '45'};...
{'0 ', '15', '30', '45', '60'};...
{' 0 ', '0.5', ' 1 ', '1.5', ' 2 '};...
{'0', '1', '2', '3'};...
{'0', '2', '3', '4'};...
{'0', '2', '4', '6'};...
{'0', '2', '4', '6', '8'};...
{'0 ', '3 ', '6 ', '9 ', '12'};...
{'0 ', '6 ', '12', '18', '24'} };
xTickUnits = ...
{'Time (sec.)'; ...
'Time (sec.)'; ...
'Time (sec.)'; ...
'Time (sec.)'; ...
'Time (sec.)'; ...
'Time (sec.)'; ...
'Time (sec.)'; ...
'Time (sec.)'; ...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (min.)';...
'Time (hr.)';...
'Time (hr.)';...
'Time (hr.)';...
'Time (hr.)';...
'Time (hr.)';...
'Time (hr.)';...
'Time (hr.)'};
% Define Page information
numSignalsPerPage = [1 2 3 4 5 6 10 12 20 24 30 60];
numSignalsPerPageTicks = ...
{ ...
[1], [1 2], [1 2 3], [1 2 3 4], [1 2 3 4 5], ...
[1 2 3 4 5 6], ...
[1 3 5 7 9], ...
[1 4 7 10 12], ...
[1 5 10 15 20], ...
[1 6 12 18 24], ...
[1,5:5:30], ...
[1,10:10:60] ...
};
numSignalsPerPageTicksLabels = { ...
{'1'}; ...
{'2', '1'};...
{'3', '2', '1'};...
{'4', '3', '2', '1'};...
{'5', '4', '3', '2', '1'}; ...
{'6', '5', '4', '3', '2', '1'};...
{'10' ' 8' ' 6' ' 4' ' 2'};...
{'12', ' 9', '6', '3', '1'};...
{'20' '15' '10' ' 5' ' 1'};...
{'24', '18', '12', '6 ', '1 '};...
{'30', '25', '20', '15', '10', '5', '1'}; ...
{'60', '50', '40', '30', '20', '10', '1'} ...
};
% Raster plot properteis
xAxisLineWidth = 2.5
yAxisEpochWidth = 2.5;
% Output Properties
multiFigPosition = [ -1679 -149 1680 974]; % Preset size
fig_idsP % Organized Figures
defaultPptName ='signalRaster.ppt';
figCellP % Generated figures by signal
end
%------------------------------------------------------- Public Methods
methods
%------------------------------------------------------ Constructor
function obj = BlockEdfSignalRasterView(varargin)
% Constructor
% Store number of input arguments
obj.num_args = nargin;
% Process input arguments
if nargin == 0
% used to get option structure
return
elseif nargin == 1
% Get argument
obj.arg1 = varargin{1};
elseif nargin == 2
obj.arg1 = varargin{1};
obj.signalToView = varargin{2};
elseif nargin == 3
obj.arg1 = varargin{1};
obj.signalToView = varargin{2};
obj.userOpt = varargin{3};
elseif nargin == 4
obj.arg1 = varargin{1};
obj.signalToView = varargin{2};
obj.userOpt = varargin{3};
obj.annotateSignalTimes = varargin{4};
else
% function prototype not supported
fprintf('obj = signalViewEdfSignals\nopt = obj.opt\n');
fprintf('obj = signalViewEdfSignals(fn|edfStruct, signalLabelCell)\n');
fprintf('obj = signalViewEdfSignals(fn|edfStruct, signalLabelCell, opt)\n');
fprintf('obj = signalViewEdfSignals(fn|edfStruct, signalLabelCell, opt, anotations)\n');
return
end
% Process first argument
if ischar(obj.arg1)
% First argument is a file name
obj.edf_fn = obj.arg1;
% Load Data
[header signalHeader signalCell] = blockEdfLoad(obj.edf_fn);
% Record EDF components
obj.edf_header = header;
obj.edf_signal_header = signalHeader;
obj.edf_signal_cell_arrray = signalCell;
else
% Record EDF components
obj.edf_header = obj.arg1.header;
obj.edf_signal_header = obj.arg1.signalHeader;
obj.edf_signal_cell_arrray = obj.arg1.signalCell;
end
% Specify signals to display
if nargin == 1
obj.signal_list = obj.edf_signals_labels;
elseif nargin == 2 | nargin == 3
if isempty(obj.signal_list)
% Signal list is empty, set default
obj.signal_list = obj.edf_signals_labels;
end
end
% Need to double check what to do
% Get signal indexes
obj.signalIndexes = obj.GetSignalIndexes...
(obj.edf_signals_labels, obj.signal_list);
% Set user provided options
if nargin == 3 | nargin == 4
% Signal Parameters
obj.percentile_range = obj.userOpt.percentile_range;
obj.signalDisplayGain = obj.userOpt.signalDisplayGain;
obj.signalDefaultGain = obj.userOpt.signalDefaultGain;
% figure Parameters
obj.imageResolution = obj.userOpt.imageResolution;
obj.setFigurePosition = obj.userOpt.setFigurePosition;
obj.figurePosition = obj.userOpt.figurePosition;
obj.xAxisScale = obj.userOpt.xAxisScale;
obj.numSignalsPerPageIndex = obj.userOpt.numSignalsPerPageIndex;
obj.PptBySignal = obj.userOpt.PptBySignal;
end
end
%------------------------------------------------- CreateSignalView
function obj = GenerateSignalRasterViewFigures(obj, varargin)
% Create a signal raster plot
% Set default values
pptFn = '';
pptTitle = '';
pagesToPrint = [];
% Process input argument
if nargin == 2
pptFn = varargin{1};
elseif nargin ==3
pptFn = varargin{1};
pptTitle = varargin{2};
elseif nargin == 4
pptFn = varargin{1};
pptTitle = varargin{2};
pagesToPrint = varargin{3};
end
% Get information to display figure
numSignals = obj.edf_header.num_signals;
num_data_records = obj.edf_header.num_data_records;
data_record_duration = obj.edf_header.data_record_duration;
getSignalSamplesF = @(x)obj.edf_signal_header(x).samples_in_record;
signalSamplesPerRecord = arrayfun(getSignalSamplesF,[1:numSignals]);
% Define signals to view
getSignalLablesF = @(x)obj.edf_signal_header(x).signal_labels;
signalLabels = cellfun...
(getSignalLablesF, num2cell([1:numSignals]), 'UniformOutput', false);
signalToView = obj.signalToView;
signalDisplayGain = obj.signalDisplayGain;
signalsToViewIndexes = ...
obj.GetSignalIndexes(signalLabels, signalToView);
numSignalsToView = obj.numSignalsToView;
% plot constants
plotProportion = obj.plotProportion;
w = obj.w;
xTickValues = obj.xTickValues;
xTickLables = obj.xTickLabels;
% Define Page information
numSignalsPerPage = obj.numSignalsPerPage;
numSignalsPerPageTicks = obj.numSignalsPerPageTicks;
numSignalsPerPageTicksLabels = obj.numSignalsPerPageTicksLabels;
% Get annotation information if present
annotateT =[];
if ~isempty(obj.annotateSignalTimes);
annotateT = obj.annotateSignalTimes;
end
% figure Parameters
figCell = cell(numSignalsToView,1);
for v = 1:numSignalsToView;
% assign old counter to current index (hack)
s = signalsToViewIndexes(v);
% Create a plot for each signal
signalSize = double(signalSamplesPerRecord(s)*num_data_records);
% Define preset widths in second
widthIndex = obj.xAxisScale;
widthDuration = obj.w(widthIndex);
% Compute Image size
ptWidth = widthDuration*signalSamplesPerRecord(s)/data_record_duration;
ptHeight = numSignalsPerPage(obj.numSignalsPerPageIndex);
signalImage = zeros(ptHeight, ptWidth);
% Move point into image
signal = obj.edf_signal_cell_arrray{s};
goodRange = ...
prctile(signal, obj.percentile_range);
goodRangeIndexes = find(and(signal>=goodRange(1), signal<=goodRange(2)));
% Create scale with the goal of showing 80% of the data
goodRangeMin = min(signal(goodRangeIndexes));
goodRangeMax = max(signal(goodRangeIndexes));
goodRangeScaleF = ...
@(x)(x-goodRangeMin)*signalDisplayGain(v)/(goodRangeMax-goodRangeMin);
if (goodRangeMax-goodRangeMin)~= 0
signal = goodRangeScaleF(signal);
else
signal = (signal-goodRangeMin);
end
% Compute Page Information
pageLengthSec = ...
widthDuration*numSignalsPerPage(obj.numSignalsPerPageIndex);
pageLengthPts = pageLengthSec*signalSamplesPerRecord(s)/data_record_duration;
signalLengthHr = length(signal)*data_record_duration/signalSamplesPerRecord(s);
numberPages = ceil(signalLengthHr/pageLengthSec);
% Reset figure for current signal
figs = [];
if isempty(pagesToPrint)
generatePages = [1:1:numberPages-1];
pagesToPrint = numberPages;
else
generatePages = pagesToPrint;
if generatePages(end) == numberPages
generatePages(end) = [];
end
end
for p = generatePages
% Move data into array
signalStart = 1+ptHeight*ptWidth*(p-1);
signalEnd = ptHeight*ptWidth*p;
signalImage(1:ptHeight,1:ptWidth) = ...
reshape(signal(signalStart:signalEnd), ptWidth, ptHeight)';
% Create figure
% ax1 is used to create epoch level grid lines
% ax2 is used to generate minor grid lines defined by
% user.
% Axis control is sensitive to command order. Care
% must be taken when revising. Note that each axis
% is created prior to plotting.
fid = figure('InvertHardcopy','off','Color',[1 1 1]);
ax1 = gca;
set(ax1,'Box','On');
set(ax1,'Color','None');
set(ax1,'Box','On');
set(ax1, 'xLim',[0,widthDuration]);
set(ax1, 'yLim',[ 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
%create new axis
ax2=axes('position',get(gca,'position'),'Visible', 'on', ...
'Color', 'None');
set(ax2,'Box','On');
set(ax2, 'xLim',[0,widthDuration]);
set(ax2, 'yLim',[ 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
% Set x axis labels
set(ax1,'YTick',[],'Xcolor',[.75 .75 .75],'Xtick',...
[1:obj.xGridInc:widthDuration],...
'xgrid','on','color','none','GridLineStyle','-'); ...
%color none to make the axis transparent
%set(ax2,'xlim',get(ax2,'xlim')) %resize 2nd axis to match 1st
set(ax1,'XTickLabel',{});
% Set y axis labels
set(ax1,'Ycolor',[.75 .75 .75],...
'Ytick',[0:obj.yGridInc:numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1],...
'ygrid','on','color','none','GridLineStyle','-');
%set(ax2,'xlim',get(ax1,'xlim')) %resize 2nd axis to match 1st
set(ax1,'YTickLabel',{});
axis(ax1, [0,widthDuration, 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
hold on
% Create first page view
x = (([1:ptWidth]*data_record_duration/signalSamplesPerRecord(s))')...
*ones(1,numSignalsPerPage...
(obj.numSignalsPerPageIndex));
y = signalImage'; % Get data by page
% determin upper and lower envelope
y = y - ones(ptWidth, 1)*mean(y,1); % zero offset
y = y + ones(ptWidth, 1)*[numSignalsPerPage(obj.numSignalsPerPageIndex):-1:1]; % Page
% Plot on second axis
hold on
plot (ax2, x, y,'LineWidth',2,'Color',[0 0 1]);
hold on
% Add Annotation
if ~isempty(annotateT)
% Identify annotations to plot
pgEndSec = p*pageLengthSec;
pgStartSec = pgEndSec-pageLengthSec;
annotateMask = and(annotateT>=pgStartSec,...
annotateT <= pgEndSec);
pageAnnotationT = annotateT(find(annotateMask));
numPageAnote = length(pageAnnotationT);
% Convert annotation times to index
pageTime = pageAnnotationT - pgStartSec;
signalSamplingRate = signalSamplesPerRecord(v)/...
data_record_duration;
pageIndex = int64(pageTime*signalSamplingRate);
yIndex = (ceil(double(pageIndex)/ptWidth));
xIndex = double(pageIndex)-...
(yIndex-1.0)*double(ptWidth);
xIndex = int32(xIndex);
yIndex = int32(yIndex);
% Get Annotation points and plot
xAnote = arrayfun(@(z)x(xIndex(z), yIndex(z)),...
[1:numPageAnote]);
yAnote = arrayfun(@(z)y(xIndex(z), yIndex(z)),...
[1:numPageAnote]);
plot(xAnote, yAnote, obj.AnnoteMarker,...
'Color', obj.AnnoteColor,...
'MarkerFaceColor', obj.AnnoteColor,...
'MarkerSize', obj.AnnoteMarkerSize,...
'LineStyle', 'None',...
'LineWidth', 1);
end
% Annotate figure
timeStartStr = obj.getTimeStr...
(signalStart*data_record_duration/signalSamplesPerRecord(s));
timeEndStr = obj.getTimeStr...
(signalEnd*data_record_duration/signalSamplesPerRecord(s));
if isempty(obj.subjectID)
titleStr = sprintf('%s\nPage %.0f of %.0f: %s - %s', ...
obj.edf_signal_header(s).signal_labels,p, ...
numberPages, timeStartStr, timeEndStr);
else
titleStr = sprintf('%s - %s\nPage %.0f of %.0f: %s - %s', ...
obj.subjectID, ...
obj.edf_signal_header(s).signal_labels,p, ...
numberPages, timeStartStr, timeEndStr);
end
if and(~isempty(annotateT), ~isempty(obj.AnnoteLabel))
titleStr = sprintf('%s - %s', titleStr,...
obj.AnnoteLabel);
end
title(titleStr,'FontWeight','bold','FontSize',14,...
'Interpreter', 'None');
% % Set figure limits
% axis([0,widthDuration, 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
%
% ax2=axes('position',get(gca,'position'),'Visible', 'on');
% Set X Axis
xticks = obj.xTickValues{obj.xAxisScale};
set(ax2,'XTick',xticks);
set(ax2,'XTickLabel',obj.xTickLabels{obj.xAxisScale});
set(ax2, 'Xcolor','black');
set(ax2, 'xgrid','on');
set(ax2, 'xMinorGrid','On');
set(ax2, 'GridLineStyle','-');
set(ax2, 'LineWidth', 3.0);
xlabel(ax2, obj.xTickUnits{obj.xAxisScale},...
'FontWeight','bold','FontSize',14,'Color','black');
% Create yaxis labels
set(ax2,'YTick',numSignalsPerPageTicks{obj.numSignalsPerPageIndex})
set(ax2,'YTickLabel', numSignalsPerPageTicksLabels{obj.numSignalsPerPageIndex});
set(ax2, 'Ycolor','black');
set(ax2, 'ygrid','on');
set(ax2, 'GridLineStyle','-');
set(ax2, 'LineWidth', 1);
set(ax2, 'yMinorGrid','On');
set(ax2, 'MinorGridLineStyle','-');
ylabel(ax2, 'Page Line','FontWeight','bold','FontSize',14,...
'Color','black');
set(ax1, 'Color','None');
set(ax2, 'Color','None');
% Manually add epoch boundary
eBound = [0:30:widthDuration];
u = axis;
for l = 1:length(eBound)
% Add Epoch line
line([eBound(l) eBound(l)], [u(3) u(4)], ...
'Color', [0 0 0], ...
'LineWidth', obj.yAxisEpochWidth);
end
% Add epoch numbers
if obj.AddEpochNumbers == 1
xTextOFF = 1;
yTextOFF = 0.0; %1/20;
epochLabelFontSize = 12;
numLines = numSignalsPerPage(obj.numSignalsPerPageIndex);
numEpochsPerLine = length(eBound)-1;
pageEpoch = (p-1)*numLines*numEpochsPerLine;
for f = 1:1:numLines
for l = 1:numEpochsPerLine
% Determine epoch number
lineNum = numLines + 1 - f;
epochNum = pageEpoch+(f-1)*numEpochsPerLine+l;
% Add text for each epoch
hT = text(eBound(l)+xTextOFF, lineNum+yTextOFF, ...
num2str(epochNum), 'Color', [0 0 0], ...
'FontSize', epochLabelFontSize, ...
'BackgroundColor', [0.9 0.9 0.9], ...
'EdgeColor', [0 0 0 ],...
'VerticalAlignment', 'Bottom',...
'HorizontalAlignment', 'Left');
end
end
end
% Add X axis
a = axis();
for f = 1:numSignalsPerPage(obj.numSignalsPerPageIndex)
line(a(1:2), [f f], 'Color', 'Black',...
'LineWidth', obj.xAxisLineWidth);
end
axis(a)
% Set figure position
if obj.setFigurePosition == 1
if ~isempty (obj.figurePosition)
set(fid, 'Position', obj.figurePosition);
else
set(fid, 'Position', obj.multiFigPosition);
end
end
% Save figure ID
figs = [figs; fid];
end
if or(pagesToPrint(end) == numberPages, ...
isempty(numberPages));
% Generate last page
% Move data into array
p = numberPages;
signalStart = 1+ptHeight*ptWidth*(p-1);
signalEnd = signalSize;
lastPtHeight = floor((signalEnd-signalStart)/ptWidth);
lastLinePtWidth = ...
(signalEnd-signalStart)-lastPtHeight*ptWidth;
lastLinePtStart = signalStart+lastPtHeight*ptWidth;
% Create Signal Matrix
signalImage(1:lastPtHeight,1:ptWidth) = ...
reshape(signal(signalStart:lastLinePtStart-1), ...
ptWidth, lastPtHeight)';
% Create first page view
x = (([1:ptWidth]*data_record_duration/signalSamplesPerRecord(s))')...
*ones(1,lastPtHeight);
y = signalImage(1:lastPtHeight,1:end)';
y = y - ones(ptWidth, 1)*mean(y,1); % zero offset
terminalEpoch = numSignalsPerPage(obj.numSignalsPerPageIndex)...
- lastPtHeight +1;
y = y + ones(ptWidth, 1)*...
[numSignalsPerPage(obj.numSignalsPerPageIndex):-1:terminalEpoch];
% Plot signal block
fid = figure('InvertHardcopy','off','Color',[1 1 1]);
% ax1 is used to create epoch level grid lines
% ax2 is used to generate minor grid lines defined by
% user.
% Axis control is sensitive to command order. Care
% must be taken when revising. Note that each axis
% is created prior to plotting.
ax1 = gca;
set(ax1,'Box','On');
set(ax1,'Color','None');
set(ax1,'Box','On');
set(ax1, 'xLim',[0,widthDuration]);
set(ax1, 'yLim',[ 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
%create new axis
ax2=axes('position',get(gca,'position'),'Visible', 'on', ...
'Color', 'None');
set(ax2,'Box','On');
set(ax2, 'xLim',[0,widthDuration]);
set(ax2, 'yLim',[ 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
plot (x, y,'LineWidth',2,'Color',[0 0 1]);
hold on
% Set x axis labels
set(ax1,'YTick',[],'Xcolor',[.75 .75 .75],'Xtick',...
[1:obj.xGridInc:widthDuration],...
'xgrid','on','color','none','GridLineStyle','-'); ...
%color none to make the axis transparent
%set(ax2,'xlim',get(ax2,'xlim')) %resize 2nd axis to match 1st
set(ax1,'XTickLabel',{});
% Set y axis labels
set(ax1,'Ycolor',[.75 .75 .75],...
'Ytick',[0:obj.yGridInc:numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1],...
'ygrid','on','color','none','GridLineStyle','-');
%set(ax2,'xlim',get(ax1,'xlim')) %resize 2nd axis to match 1st
set(ax1,'YTickLabel',{});
axis(ax1, [0,widthDuration, 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
hold on
% Add Annotations to partial page
if ~isempty(annotateT)
% Identify annotations to plot
pgEndSec = p*pageLengthSec;
pgStartSec = pgEndSec-pageLengthSec;
pgEndSec = pgEndSec - (ptHeight-lastPtHeight)*...
pageLengthSec/ptHeight;
annotateMask = and(annotateT>=pgStartSec,...
annotateT <= pgEndSec);
pageAnnotationT = annotateT(find(annotateMask));
numPageAnote = length(pageAnnotationT);
% Convert annotation times to index
pageTime = pageAnnotationT - pgStartSec;
signalSamplingRate = signalSamplesPerRecord(v)/...
data_record_duration;
pageIndex = int64(pageTime*signalSamplingRate);
yIndex = (ceil(double(pageIndex)/ptWidth));
xIndex = double(pageIndex)-...
(yIndex-1.0)*double(ptWidth);
xIndex = int32(xIndex);
yIndex = int32(yIndex);
% Get Annotation points and plot
xAnote = arrayfun(@(z)x(xIndex(z), yIndex(z)),...
[1:numPageAnote]);
yAnote = arrayfun(@(z)y(xIndex(z), yIndex(z)),...
[1:numPageAnote]);
plot(xAnote, yAnote, obj.AnnoteMarker,...
'Color', obj.AnnoteColor,...
'MarkerFaceColor', obj.AnnoteColor,...
'MarkerSize', obj.AnnoteMarkerSize,...
'LineStyle', 'None',...
'LineWidth', 1);
end
% Plot last incomplete line, if available
if lastPtHeight ~= numSignalsPerPage(obj.numSignalsPerPageIndex)
% Plot remaining points
y = signal(lastLinePtStart:end);
x = (([1:length(y)]*data_record_duration/signalSamplesPerRecord(s))')...
*ones(1,1);
% Scale signal for page
y = y - ones(length(y), 1)*mean(y,1); % zero offset
terminalEpoch = numSignalsPerPage(obj.numSignalsPerPageIndex)...
- lastPtHeight;
y = y + ones(length(y), 1)*terminalEpoch;
plot (x, y,'LineWidth',2,'Color',[0 0 1]);
hold on
% Add Annotations to partial line
if ~isempty(annotateT)
% lastPtHeight
% Identify annotations to plot
pgEndSec = p*pageLengthSec;
pgStartSec = pgEndSec-(ptHeight - lastPtHeight)*...
pageLengthSec/ptHeight;
annotateMask = and(annotateT>=pgStartSec,...
annotateT <= pgEndSec);
pageAnnotationT = annotateT(find(annotateMask));
numPageAnote = length(pageAnnotationT);
% Convert annotation times to index
pageTime = pageAnnotationT - pgStartSec;
signalSamplingRate = signalSamplesPerRecord(v)/...
data_record_duration;
pageIndex = int64(pageTime*signalSamplingRate);
yIndex = (ceil(double(pageIndex)/ptWidth));
xIndex = double(pageIndex)-...
(yIndex-1.0)*double(ptWidth);
xIndex = int32(xIndex);
yIndex = int32(yIndex);
% Get Annotation points and plot
xAnote = arrayfun(@(z)x(xIndex(z), yIndex(z)),...
[1:numPageAnote]);
yAnote = arrayfun(@(z)y(xIndex(z), yIndex(z)),...
[1:numPageAnote]);
plot(xAnote, yAnote, obj.AnnoteMarker,...
'Color', obj.AnnoteColor,...
'MarkerFaceColor', obj.AnnoteColor,...
'MarkerSize', obj.AnnoteMarkerSize,...
'LineStyle', 'None',...
'LineWidth', 1);
end
end
% Annotate figure
timeStartStr = obj.getTimeStr...
(signalStart*data_record_duration/signalSamplesPerRecord(s));
timeEndStr = obj.getTimeStr...
(signalEnd*data_record_duration/signalSamplesPerRecord(s));
if isempty(obj.subjectID)
titleStr = sprintf('%s\nPage %.0f of %.0f: %s - %s', ...
obj.edf_signal_header(s).signal_labels,p, ...
numberPages, timeStartStr, timeEndStr);
else
titleStr = sprintf('%s - %s\nPage %.0f of %.0f: %s - %s', ...
obj.subjectID, ...
obj.edf_signal_header(s).signal_labels,p, ...
numberPages, timeStartStr, timeEndStr);
end
if and(~isempty(annotateT), ~isempty(obj.AnnoteLabel))
titleStr = sprintf('%s - %s', titleStr,...
obj.AnnoteLabel);
end
title(titleStr,'FontWeight','bold','FontSize',14, ...
'Interpreter', 'None');
% Set figure limits
axis([0,widthDuration, 0.0, numSignalsPerPage(obj.numSignalsPerPageIndex)+ 1]);
% Set X Axis
xticks = obj.xTickValues{obj.xAxisScale};
set(ax2,'XTick',xticks);
set(ax2,'XTickLabel',obj.xTickLabels{obj.xAxisScale});
set(ax2, 'Xcolor','black');
set(ax2, 'xgrid','on');
set(ax2, 'xMinorGrid','On');
set(ax2, 'GridLineStyle','-');
set(ax2, 'LineWidth', 3.0);
xlabel(ax2, obj.xTickUnits{obj.xAxisScale},...
'FontWeight','bold','FontSize',14,'Color','black');
% Create yaxis labels
set(ax2,'YTick',numSignalsPerPageTicks{obj.numSignalsPerPageIndex})
set(ax2,'YTickLabel', numSignalsPerPageTicksLabels{obj.numSignalsPerPageIndex});
set(ax2, 'Ycolor','black');
set(ax2, 'ygrid','on');
set(ax2, 'GridLineStyle','-');
set(ax2, 'LineWidth', 1);
set(ax2, 'yMinorGrid','On');
set(ax2, 'MinorGridLineStyle','-');
ylabel(ax2, 'Page Line','FontWeight','bold','FontSize',14,...
'Color','black');
set(ax1, 'Color','None');
set(ax2, 'Color','None');
% Add epoch numbers
if obj.AddEpochNumbers == 1
eBound = [0:30:widthDuration];
xTextOFF = 0.2;
yTextOFF = 1/20;
epochLabelFontSize = 12;
numLines = numSignalsPerPage(obj.numSignalsPerPageIndex);
numEpochsPerLine = length(eBound)-1;
pageEpoch = (p-1)*numLines*numEpochsPerLine;
for f = 1:1:numLines
for l = 1:numEpochsPerLine
% Determine epoch number
lineNum = numLines + 1 - f;
epochNum = pageEpoch+(f-1)*numEpochsPerLine+l;
% Add text for each epoch
text(eBound(l)+xTextOFF, lineNum, ...
num2str(epochNum), 'Color', [0 0 0], ...
'FontSize', epochLabelFontSize, ...
'BackgroundColor', [0.9 0.9 0.9], ...
'EdgeColor', [0 0 0 ],...
'VerticalAlignment', 'Bottom');
end
end
end
% Manually add epoch boundary
eBound = [0:30:widthDuration];
u = axis;
for l = 1:length(eBound)
line([eBound(l) eBound(l)], [u(3) u(4)], ...
'Color', [0 0 0], 'LineWidth', 3);
end
% Replot data to place on top of gridlines
plot (ax2, x, y,'LineWidth',2,'Color',[0 0 1]);
% Add epoch numbers
eBound = [0:30:widthDuration];
xTextOFF = 0.2;
yTextOFF = 1/20;
epochLabelFontSize = 12;
numLines = numSignalsPerPage(obj.numSignalsPerPageIndex);
numEpochsPerLine = length(eBound)-1;
pageEpoch = (p-1)*numLines*numEpochsPerLine;
for f = 1:1:numLines
for l = 1:numEpochsPerLine
% Determine epoch number
lineNum = numLines + 1 - f;
epochNum = pageEpoch+(f-1)*numEpochsPerLine+l;
% Add text for each epoch
text(eBound(l)+xTextOFF, lineNum, ...
num2str(epochNum), 'Color', [0 0 0], ...
'FontSize', epochLabelFontSize, ...
'BackgroundColor', [0.9 0.9 0.9], ...
'EdgeColor', [0 0 0 ],...
'VerticalAlignment', 'Bottom');
end
end
% Set figure position
if obj.setFigurePosition == 1
if ~isempty (obj.figurePosition)
set(fid, 'Position', obj.figurePosition);
else
set(fid, 'Position', obj.multiFigPosition);
end
end
% Add X axis
a = axis();
for f = 1:numSignalsPerPage(obj.numSignalsPerPageIndex)
line(a(1:2), [f f], 'Color', 'Black',...
'LineWidth', obj.xAxisLineWidth);
end
axis(a)
% Save last figure id
figs = [figs; fid];
end