Repository navigation
Expand file tree
/
Copy pathCLASS_channels_container.m
More file actions
1740 lines (1578 loc) · 90.2 KB
/
Copy pathCLASS_channels_container.m
File metadata and controls
1740 lines (1578 loc) · 90.2 KB
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
%> @file CLASS_channels_container.m
%> @brief CLASS_channels_container is a wrapper class for CLASS_channels.
%> This keeps a collection of CLASS_channels as cell contents which are
%> stored in an instance variable.
% ======================================================================
%> @brief CLASS_channels_container exists for the purpose of organizing,
%> updating, and adjusting instances of CLASS_channels.
%
%
% History
% Written by:
% Hyatt Moore, IV
% last modified: October 8, 2012
% ======================================================================
classdef CLASS_channels_container < handle
properties
%> The cell which holds CLASS_channel objects.
cell_of_channels;
%> size of cell_of_channels (and also channel_vector)
num_channels;
%>sample space of the data currently being viewed
current_samples;
%> index of the channel currently selected
current_channel_index;
%>index of psd channel to show/0 if off
current_spectrum_channel_index;
%> @brief array of filter structures for applying filters to the data here.
%> array struct of filter rules that are applied to the
%> channel data.
%> The filterStruct is obtained from prefilter_dlg and
%> has the following fields
%> outputStruct.src_channel_index = [];
%> - .src_channel_label = [];
%> - .m_file = [];
%> - .ref_channel_index = [];
%> - .ref_channel_label = {};
filterArrayStruct;
%> .MAT filename which holds or will hold adjustable channel settings
settingsFilename = [];
%> @brief Vector of structs (channelSettings) containing stored field values of children channel objects - useful for gui display preference tracking between sessions
%> channelSettings is a struct with settings to load.
storedChannelSettings = [];
%> axes handle to plot PSD results to when applicable
psd_axes = [];
%> figure handle for results to go to and contextmenus to attach
parent_fig = [];
%> where channels are drawn/rendered
main_axes = [];
%> context menu handles to be used for added children
mainline_contextmenu_h;
%>
referenceline_contextmenu_h;
%> Sample rate to use when none is provided by a new CLASS_channel
%> instance.
default_samplerate;
%> pointer to the current event_container instance
EVENT_CONTAINER;
%> struct with sev related information for finding detection paths, files, etc.
sevDefaults;
end
methods
% =================================================================
%> @brief CLASS_channels_container constructor.
%> @param obj instance of CLASS_channels_container class.
%> @param parent_fig Handle to SEV figure
%> @param main_axes Handle to SEV axes where channels are displayed
%> @param psd_axes Handle to SEV axes where PSD is displayed
%> @param sevDefaults Structure of SEV settings
%> @retval obj instance of CLASS_channels_container class.
% =================================================================
function obj = CLASS_channels_container(parent_fig,main_axes,psd_axes,sevDefaults)
if(nargin>3)
obj.default_samplerate = sevDefaults.samplerate; %set this to 0 or -1 if you do not want a common sample rate
else
sevDefaults = [];
obj.default_samplerate = [];
end
obj.sevDefaults = sevDefaults;
obj.EVENT_CONTAINER = [];
obj.cell_of_channels = {};
obj.num_channels = 0;
obj.current_samples = [];
obj.filterArrayStruct = [];
obj.current_channel_index = 0;
obj.current_spectrum_channel_index = 0;
obj.parent_fig = [];
obj.main_axes = [];
obj.psd_axes = [];
obj.referenceline_contextmenu_h = [];
if(nargin>1)
obj.parent_fig = parent_fig;
obj.main_axes = main_axes;
if(nargin>2)
obj.psd_axes = psd_axes;
end
obj.configure_contextmenu();
end
end
% =================================================================
%> @brief Sets the default sample rate of the object.
%> @param obj instance of CLASS_channels_container.
%> @param Sample rate to use as the default.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function setDefaultSamplerate(obj,samplerate)
obj.default_samplerate = samplerate;
end
% =================================================================
%> @brief Contextmenu callback for a channel's visibility.
%> @note This is not implemented and may be *REMOVED* in future
%> versions.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object.
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_visibility_Callback(obj,hObject,eventdata)
disp('listening');
end
% =================================================================
%> @brief Configure the channels contextmenus' callbacks.
%> @param obj instance of CLASS_channels_container.
% =================================================================
function configure_contextmenu(obj)
obj.configureReferenceLineContextmenu();
%%% main line contextmenu
obj.configureChannelLineContextmenu();
end
%% -- Contextmenu configuration section
% --------------------------------------------------------------------
% Reference Line callback section
% --------------------------------------------------------------------
% =================================================================
%> @brief Configure the channel's reference line contextmenu.
%> @param obj instance of CLASS_channels_container.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function configureReferenceLineContextmenu(obj)
%%% reference line contextmenu
contextmenu_ref_line_h = uicontextmenu('callback',@obj.contextmenu_ref_line_callback,'parent',obj.parent_fig);
uimenu(contextmenu_ref_line_h,'Label','Change Color','separator','off','callback',@obj.contextmenu_ref_line_color_callback);
uimenu(contextmenu_ref_line_h,'Label','Adjust Offset','separator','off','callback',@obj.contextmenu_line_referenceline_callback);
uimenu(contextmenu_ref_line_h,'Label','Remove','separator','on','callback',@obj.contextmenu_ref_line_remove_callback);
obj.referenceline_contextmenu_h = contextmenu_ref_line_h;
end
% =================================================================
%> @brief The channel's reference line parent contextmenu callback.
%> The parent context menu that pops up before any of the children contexts are
%> drawn.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_ref_line_callback(obj,hObject,eventdata)
linehandle = get(obj.parent_fig,'currentobject');
obj.current_channel_index = get(linehandle,'userdata');
% set(linehandle,'selected','on');
end
% =================================================================
%> @brief Reference lines' contextmenu color callback option for
%> changing the lines display color.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_ref_line_color_callback(obj,hObject,eventdata)
childobj = obj.getCurrentChild();
c = uisetcolor(childobj.reference_line_color);
if(numel(c)~=1)
obj.setReferenceLineColor(obj.current_channel_index,c)
end;
set(gco,'selected','off');
end
% =================================================================
%> @brief Remove reference line contextmenu callback.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_ref_line_remove_callback(obj,hObject,eventdata)
reference_offset = 0;
obj.adjust_reference_offset(obj.current_channel_index,reference_offset);
set(gco,'selected','off');
end
% --------------------------------------------------------------------
% Main Channel Line callback section
% --------------------------------------------------------------------
% =================================================================
%> @brief Configure contextmenu for channel instances.
%> @param obj instance of CLASS_channels_container.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function configureChannelLineContextmenu(obj)
uicontextmenu_handle = uicontextmenu('callback',@obj.contextmenu_line_callback,'parent',obj.parent_fig);%,get(parentAxes,'parent'));
uimenu(uicontextmenu_handle,'Label','Resize','separator','off','callback',@obj.contextmenu_line_resize_callback);
uimenu(uicontextmenu_handle,'Label','Use Default Scale','separator','off','callback',@obj.contextmenu_line_default_callback);
uimenu(uicontextmenu_handle,'Label','Move','separator','off','callback',@obj.contextmenu_line_move_callback);
uimenu(uicontextmenu_handle,'Label','Add Reference Line','separator','on','callback',@obj.contextmenu_line_referenceline_callback);
uimenu(uicontextmenu_handle,'Label','Change Color','separator','off','callback',@obj.contextmenu_line_color_callback);
uimenu(uicontextmenu_handle,'Label','Align Channel','separator','off','callback',@obj.align_channels_on_axes);
uimenu(uicontextmenu_handle,'Label','Hide','separator','on','callback',@obj.contextmenu_line_hide_callback);
uimenu(uicontextmenu_handle,'Label','Duplicate','separator','off','callback',@obj.contextmenu_line_duplicate_callback);
uimenu(uicontextmenu_handle,'Label','Copy epoch to clipboard','separator','off','callback',@obj.copy_epoch2clipboard,'tag','copy_epoch2clipboard');
uimenu(uicontextmenu_handle,'Label','Export channel to workspace','separator','off','callback',@obj.copy_channel2workspace,'tag','copy_channel2workspace');
uimenu(uicontextmenu_handle,'Label','Show PSD','separator','on','callback',@obj.contextmenu_line_show_psd_callback);
uimenu(uicontextmenu_handle,'Label','Show MUSIC','separator','off','callback',@obj.contextmenu_line_show_music_callback);
uimenu(uicontextmenu_handle,'Label','Epoch statistics','separator','on','callback',@obj.contextmenu_line_show_epoch_stats_callback);
% uimenu(uicontextmenu_handle,'Label','Open Event Toolbox','separator','off','callback',@obj.event_toolbox_callback,'tag','toolbox');
uimenu(uicontextmenu_handle,'Label','Show Filtered','separator','off','tag','show_filtered','callback',@obj.contextmenu_line_show_filtered_callback,'checked','off');
% uimenu(uicontextmenu_handle,'Label','Compare Events','separator','off','callback',@obj.compare_events_callback,'tag','compare_events');
max_num_sources = 1; %maximum number of sources that can be drawn...
if(~isfield(obj.sevDefaults,'detection_inf_file') && exist(obj.sevDefaults.detection_inf_file,'file'))
[mfile, evt_label, num_reqd_indices, unused_param_gui, unused_batch_mode_label] = textread(obj.sevDefaults.detection_inf_file,'%s%s%n%s%c','commentstyle','shell');
event_detector_uimenu = uimenu(uicontextmenu_handle,'Label','Apply Detector','separator','off','tag','event_detector');
for k=1:numel(num_reqd_indices)
if(num_reqd_indices(k)==max_num_sources)
uimenu(event_detector_uimenu,'Label',evt_label{k},'separator','off','callback',{@obj.contextmenu_event_detector_callback,mfile{k}});
end;
end
end;
obj.mainline_contextmenu_h = uicontextmenu_handle;
end
% =================================================================
%> @brief Contextmenu callback for channel objects.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_callback(obj,hObject,eventdata)
%parent context menu that pops up before any of the children contexts are
%drawn...
global MARKING;
handles = guidata(hObject);
obj_handle = get(obj.parent_fig,'currentobject');
channel_index = get(obj_handle,'userdata');
obj.current_channel_index = channel_index;
channelObj = obj.getCurrentChild();
set(channelObj.line_handle,'selected','on');
MARKING.setLinehandle(channelObj.line_handle);
child_menu_handles = get(hObject,'children'); %this is all of the handles of the children menu options
default_scale_handle = child_menu_handles(find(~cellfun('isempty',strfind(get(child_menu_handles,'Label'),'Use Default Scale')),1));
show_filtered_handle = findobj(child_menu_handles,'tag','show_filtered');
% show_filtered_handle = child_menu_handles(find(~cellfun('isempty',strfind(get(child_menu_handles,'Label'),'Show Filtered')),1));
if(channelObj.scale==1)
set(default_scale_handle,'checked','on');
else
set(default_scale_handle,'checked','off');
end;
%show/hide the show filter handle
if(isempty(channelObj.filter_data))
set(show_filtered_handle,'visible','off');
else
set(show_filtered_handle,'visible','on');
if(channelObj.show_filtered)
set(show_filtered_handle,'Label','Show Raw Data');
% set(show_filtered_handle,'checked','on');
else
set(show_filtered_handle,'Label','Show Filtered Data');
% set(show_filtered_handle,'checked','off');
end
end
guidata(hObject,handles);
end
% =================================================================
%> @brief Resize callback for channel object contextmenu.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_resize_callback(obj,hObject,eventdata)
handles = guidata(hObject);
set(obj.parent_fig,'pointer','crosshair','WindowScrollWheelFcn',...
{@obj.resize_WindowScrollWheelFcn,...
obj.getCurrentChild(),handles.text_marker});
end
% =================================================================
%> @brief Copy current epoch of the selected channel to MATLAB
%> clipboard.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function copy_epoch2clipboard(obj,hObject,eventdata)
obj.copy2clipboard(obj.current_channel_index);
set(gco,'selected','off');
end
% =================================================================
%> @brief Copy current epoch of the selected channel to MATLAB
%> workspace.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function copy_channel2workspace(obj,hObject,eventdata)
obj.copy2workspace(obj.current_channel_index);
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel contextmenu callback to duplicate selected
%> channel.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_duplicate_callback(obj,hObject,eventdata)
obj.duplicate(obj.current_channel_index);
obj.align_channels_on_axes();
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel contextmenu callback to hide the selected
%> channel.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_hide_callback(obj,hObject,eventdata)
obj.hide(obj.current_channel_index);
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel contextmenu callback to move the selected
%> channel's position in the SEV.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @param channel_object The CLASS_channel object being moved.
%> @param ylim Y-axes limits; cannot move the channel above or below
%> these bounds.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function move_line(obj,hObject,eventdata,channel_object,y_lim)
%windowbuttonmotionfcn set by contextmenu_line_move_callback
%axes_h is the axes that the current object (channel_object) is in
pos = get(obj.main_axes,'currentpoint');
channel_object.setLineOffset(max(min(pos(1,2),y_lim(2)),y_lim(1)));
end
% =================================================================
%> @brief Mouse wheel callback to resize the selected channel.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Mouse scroll event data.
%> @param channelObj The selected CLASS_channel object.
%> @param text_h Text handle for outputing the channel's size/scale.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function resize_WindowScrollWheelFcn(obj,hObject,eventdata,channelObj,text_h)
%the windowwheelscrollfcn set by contextmenu_line_resize_callback
%it is used to adjust the size of the selected channel object (channelObj)
scroll_step = 0.05;
lowerbound = 0.001;
channelObj.scale = max(lowerbound,channelObj.scale-eventdata.VerticalScrollCount*scroll_step);
channelObj.draw();
%update this text scale...
click_str = sprintf('Scale: %0.3f',channelObj.scale);
set(text_h,'string',click_str);
end
% --------------------------------------------------------------------
% =================================================================
%> @brief Contextmenu callback to smooth the selected channel's
%> display. Uses matlab's line handle 'linesmoothing' option.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @param handles Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function context_menu_line_smoothing_Callback(obj,hObject, eventdata, handles)
% hObject handle to context_menu_line_smoothing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
childObj = obj.getCurrentChild();
if(strcmp(get(hObject,'Checked'),'on'))
set(hObject,'Checked','off');
set(childObj.line_handle,'linesmoothing','off');
else
set(hObject,'Checked','on')
set(childObj.line_handle,'linesmoothing','on');
end;
set(gco,'selected','off');
end
% =================================================================
%> @brief This context menu will allow the user to place or remove line labels as
%> necessary.
%> @param obj instance of CLASS_channels_container.
%> @param hObject Handle of callback object (unused).
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_referenceline_callback(obj,hObject,eventdata)
%the function str2double is implicitly used as an error check in
%conjunction with the explecit if statement that follows it.
childobj = obj.getCurrentChild();
reference_line_offset_str = num2str(childobj.reference_line_offsets(1));
%tried to change this, but does not work without the strvcat as of this
%commenting.
reference_offset_str = inputdlg(char({'Input desired line offset (in uV)','(0 turns off reference lines)'}),'Line Reference Input Dialog',1,{reference_line_offset_str});
if(~isempty(reference_offset_str))
reference_offset = str2double(reference_offset_str{1});
if(~(isnan(reference_offset)))
obj.adjust_reference_offset(obj.current_channel_index,reference_offset);
end
end
set(gco,'selected','off');
end
% =================================================================
%> @brief configures a contextmenu selection to be hidden or to have
%> attached uimenus with labels of hidden channels displayed.
%> @param obj instance of CLASS_channels_container.
%> @param contextmenu_h Handle of parent contextmenu to unhide
%> channels.
%> @param eventdata Unused.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function configure_contextmenu_unhidechannels(obj,contextmenu_h,eventdata)
delete(get(contextmenu_h,'children'));
set(contextmenu_h,'enable','off');
for k=1:obj.num_channels
tmp = obj.cell_of_channels{k};
if(tmp.hidden)
set(contextmenu_h,'enable','on');
uimenu(contextmenu_h,'Label',tmp.title,'separator','off','callback',@tmp.show);
end;
end;
set(gco,'selected','off');
end
% =================================================================
%> @brief Show MUSIC spectrum of a channel's selected data points.
%> @param obj instance of CLASS_channels_container.
%> @param spectrum_settings MUSIC settings.
%> @param axes_h The axes handle to display the spectrum on.
%> Default is obj.psd_axes
%> @param channel_index Index of the CLASS_channel object to
%> calculate spectrum of.
%> @param sample_indices Channel's sample indices to calculate
%> spectrum over. Default is to use obj's
%> current_spectrum_channel_index instance variable.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function showMUSIC(obj,spectrum_settings,axes_h, channel_index, sample_indices)
if(nargin <5)
sample_indices = obj.current_samples;
if(nargin <4)
channel_index = obj.current_spectrum_channel_index;
if(nargin<3)
axes_h = obj.psd_axes;
end
end
end
if(channel_index>0 && channel_index<=obj.num_channels) %just show this for one channel then...
channelObj = obj.getChannel(channel_index);
[S F] = channelObj.calculate_PMUSIC(spectrum_settings,sample_indices);
%just look at a subset right now...
freq_range = F<=spectrum_settings.freq_max & F>=spectrum_settings.freq_min;
cla(axes_h);
line('parent',axes_h,'xdata',F(freq_range),'ydata',S(freq_range));
set(axes_h,'xlim',[spectrum_settings.freq_min,spectrum_settings.freq_max])
end;
end
% =================================================================
%> @brief Displays the PSD of the input channel index on the range
%> of samples identified by sample_indices using the PSD settings
%> listd in the input struct spectrum_settings.
%> @param obj instance of CLASS_channels_container.
%> @param spectrum_settings struct with PSD settings to use
%> @param axes_h Axes handle to plot power spectrum to.
%> @param channel_index Index of the channel object to calculate PSD
%> of.
%> @param sample_indices range of samples to calculate the PSD over.
% =================================================================
function showPSD(obj,spectrum_settings,axes_h,channel_index,sample_indices)
if(nargin <5)
sample_indices = obj.current_samples;
if(nargin <4)
channel_index = obj.current_spectrum_channel_index;
if(nargin<3)
axes_h = obj.psd_axes;
end
end
end
if(channel_index>0 && channel_index<=obj.num_channels) %just show this for one channel then...
channelObj = obj.getChannel(channel_index);
[S F] = channelObj.calculate_PSD(spectrum_settings,sample_indices);
%just look at a subset right now...
freq_range = F<=spectrum_settings.freq_max & F>=spectrum_settings.freq_min;
F = F(freq_range);
S = S(:,freq_range);
S(:,1) = 0; %don't show the mean here b/c it can hold negative values for us (-dc offset), which makes it less intelligible due to matlab's auto scaling.
cla(axes_h);
bar(axes_h,F,sum(S,1)/size(S,1));
set(axes_h,'xlim',[spectrum_settings.freq_min,spectrum_settings.freq_max])
end;
end
% =================================================================
%> @brief Set color of the selected channels' referece line(s).
%> @param obj instance of CLASS_channels_container.
%> @param channel_indices Indices of the channels whose reference
%> lines will be set.
%> @param new_colors Color to set reference line to. If
%> channel_indices is an Nx1 vector, then new_colors is an Nx3 matrix.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function setReferenceLineColor(obj,channel_indices,new_colors)
num_colors = size(new_colors,1); %how many rows
num_indices = numel(channel_indices);
for k=1:num_indices
if(num_colors<num_indices)
new_color = new_colors(1,:);
else
new_color = new_colors(k,:);
end
channel_index = channel_indices(k);
if(channel_index>0 && channel_index<=obj.num_channels)
obj.cell_of_channels{channel_index}.setReferenceLineColor(new_color);
end
end
end
% =================================================================
%> @brief Set color of the selected channel's referece line.
%> @param obj instance of CLASS_channels_container.
%> @param channel_index Index of the channel to set the reference line color of.
%> @param c Color to use.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function obj = setColor(obj,channel_index,c)
obj.cell_of_channels{channel_index}.setColor(c);
end
% =================================================================
%> @brief Gets the color of the selected channel.
%> @param obj instance of CLASS_channels_container.
%> @param channel_index Index of the channel to return the line color of.
%> @retval colorOut Color of the selected channel.
% =================================================================
function colorOut = getColor(obj,channel_index)
colorOut = obj.cell_of_channels{channel_index}.color;
end
% =================================================================
%> @brief Load settings from a file.
%> @param obj instance of CLASS_channels_container.
%> @param settingsFilename Name of file to load settings from.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function obj = loadSettings(obj, settingsFilename)
if(exist(settingsFilename,'file'))
x = load(settingsFilename);
obj.storedChannelSettings = x.storedChannelSettings;
end
end
% =================================================================
%> @brief Channel's contextmenu line move callback.
%> @param obj instance of CLASS_channels_container.
%> @param hObject gui handle object
%> @param eventdata unused
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_move_callback(obj,hObject,eventdata)
y_lim = get(obj.main_axes,'ylim');
set(obj.parent_fig,'pointer','hand',...
'windowbuttonmotionfcn',...
{@obj.move_line,obj.getCurrentChild(),y_lim}...
);
end;
% =================================================================
%> @brief Channel's contextmenu line default scale callback.
%> Returns the channel's scale/size to 1.
%> @param obj instance of CLASS_channels_container.
%> @param hObject gui handle object
%> @param eventdata unused
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_default_callback(obj,hObject,eventdata)
if(strcmp(get(hObject,'checked'),'off'))
set(hObject,'checked','on');
childobj = obj.getCurrentChild();
childobj.scale = 1;
childobj.draw();
end;
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel's contextmenu option to display results of the
%> applied filter(s).
%> @param obj instance of CLASS_channels_container.
%> @param hObject gui handle object
%> @param eventdata unused
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_show_filtered_callback(obj,hObject,eventdata)
if(strcmp(get(hObject,'label'),'Show Filtered Data'))
show_filtered = true;
else
show_filtered = false;
end
%if it is checked ('on') then we want to turn it off -> send false
%and if it is 'off' then we want to turn it on -> send true
obj.setShowFiltered(obj.current_channel_index,show_filtered);
% CHANNELS_CONTAINER.setShowFiltered(channel_index,strcmp(get(hObject,'checked'),'off'));
%set things back in order and update the plot...
set(gco,'selected','off');
% updatePlot(guidata(hObject));
end
% =================================================================
%> @brief Channel contextmenu option to display the channel's PSD.
%> @param obj instance of CLASS_channels_container.
%> @param hObject handle of the gui object
%> @param eventdata unused
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_show_psd_callback(obj,hObject,eventdata)
global MARKING;
obj.current_spectrum_channel_index = obj.current_channel_index;
obj.showPSD(MARKING.SETTINGS.PSD);
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel contextmenu option to display the channel's MUSIC
%> spectrum.
%> @param obj instance of CLASS_channels_container.
%> @param hObject handle of the gui object
%> @param eventdata unused
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_show_music_callback(obj,hObject,eventdata)
global MARKING;
obj.current_spectrum_channel_index = obj.current_channel_index;
obj.showMUSIC(MARKING.SETTINGS.MUSIC);
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel contextmenu option to set the channel's line
%> color.
%> @param obj instance of CLASS_channels_container.
%> @param hObject handle of the gui object
%> @param eventdata unused
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_color_callback(obj,hObject,eventdata)
channel_index = obj.current_channel_index;
% channel_index = get(WORKSPACE.current_linehandle,'userdata');
c = obj.getColor(channel_index);
c = uisetcolor(c);
if(numel(c)~=1)
obj.setColor(channel_index,c);
end;
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel contextmenu option to run an event detector on the channel.
%> @param obj instance of CLASS_channels_container.
%> @param hObject gui handle object
%> @param eventdata unused
%> @param detection_mfile File that contains SEV compatible
%> detection methods that can be selected from.
%> @note This option will be deprecated in future releases and is
%> flagged for removal (*REMOVE*).
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_event_detector_callback(obj,hObject,eventdata,detection_mfile)
global MARKING;
if(ishandle(MARKING.current_linehandle))
showBusy();
channelIndex = get(WORKSPACE.current_linehandle,'userdata');
function_call = [obj.sevDefaults.detection_path(2:end),'.',detection_mfile];
detectStruct = feval(function_call,channelIndex);
%detectStruct has the fields
% .new_data
% .new_events
% .paramStruct - parameters associated with detected events
event_label = get(hObject,'label');
sourceStruct.channel_indices = channelIndex;
sourceStruct.algorithm = [obj.sevDefaults.detection_path(2:end),'.',detection_mfile];
detection_struct = CLASS_settings.loadParametersInf(obj.sevDefaults.detection_path);
%detection_struct has the fields that are contained/gridded in the
%detection.inf file
%
sourceStruct.editor = detection_struct.param_gui{strcmp(detection_mfile,detection_struct.mfile)};
event_index = obj.EVENT_CONTAINER.updateEvent(detectStruct.new_events,event_label,channelIndex,sourceStruct,detectStruct.paramStruct);
if(~isempty(event_index))
obj.EVENT_CONTAINER.draw_events(event_index);
% handles = guidata(hObject);
% updateAxes2(handles);
% updatePlot(handles);
end;
else
warndlg('no valid line handle found');
end;
MARKING.restore_state();
set(gco,'selected','off');
end
% =================================================================
%> @brief Channel context menu to display statistics of the channel.
%> @param obj instance of CLASS_channels_container.
%> @param hObject gui handle object
%> @param eventdata unused
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function contextmenu_line_show_epoch_stats_callback(obj,hobject,eventdata)
global MARKING;
cur_epoch = MARKING.current_epoch;
childobj = obj.getCurrentChild();
summary_stats = obj.getStats(obj.current_channel_index);
summary_stats.description_str = sprintf('summary statistics for %s epoch (%u)',obj.getChannelName(obj.current_channel_index),cur_epoch);
if(~isfield(childobj,'summarystats_h') || ~ishandle(childobj.summarystats_h))
childobj.summary_stats_figure_h = figure('menubar','none','visible','off','name',summary_stats.description_str,'units','pixels','visible','on');
childobj.summary_stats_uitable_h = uitable('parent',childobj.summary_stats_figure_h,'columnname',summary_stats.table_column_names,'data',summary_stats.table_data,'rowname',summary_stats.table_row_names,'units','pixels','visible','on');
else
set(childobj.summary_stats_uitable_h,'columnname',summary_stats.table_column_names,'data',summary_stats.table_data,'rowname',summary_stats.table_row_names);
end
drawnow;
extent = get(childobj.summary_stats_uitable_h,'extent');
figure_pos = get(childobj.summary_stats_figure_h,'position');
set(childobj.summary_stats_uitable_h,'position',[0 0 extent(3:4)]);
set(childobj.summary_stats_figure_h,'position',[figure_pos(1:2), extent(3:4)]);
set(gco,'selected','off');
end
% =================================================================
%> @brief Return the selected channel object.
%> @param obj Instance of CLASS_channels_container.
%> @retval childobj The selected CLASS_channel object.
% =================================================================
function childobj = getCurrentChild(obj)
if(obj.current_channel_index>0 && obj.current_channel_index<=obj.num_channels)
childobj = obj.cell_of_channels{obj.current_channel_index};
else
childobj = [];
end
end
% =================================================================
%> @brief Sets channel settings indicated by indices.
%> @param obj instance of CLASS_channels_container.
%> @param Indices are the indices of the children channels requesting
%> setting adjustments if there is a match (if indices is empty
%> then all channels with matching titles will be used.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function obj = setChannelSettings(obj,indices)
%channelSettings is a struct with settings to load
channelSettings = obj.storedChannelSettings;
if(~isempty(channelSettings))
if(nargin<2 || isempty(indices))
indices = 1:obj.num_channels;
end
storedEDF_labels = cell(numel(obj.storedChannelSettings),1);
[storedEDF_labels{:}] = obj.storedChannelSettings.EDF_label;
for k=1:numel(indices)
index = indices(k);
%now I can check if the label is already in existence or
%not...
channelName = obj.getChannelName(index);
match = find(strcmpi(channelName,storedEDF_labels),1);
if(~isempty(match))
%update the data from channelsettings
obj.cell_of_channels{index}.loadSettings(channelSettings(match));
end
end
end
end
% =================================================================
%> @brief Save channel settings to file.
%> @param obj instance of CLASS_channels_container.
%> @param settingsFilename Name of the file to save settings to
%> (string).
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function obj = saveSettings(obj, settingsFilename)
%save the settings to the given filename as a .mat file
%find any matches and replace, otherwise add to it.
if(obj.num_channels>=1)
if(nargin<2 || isempty(settingsFilename))
settingsFilename = obj.settingsFilename;
end
if(~isempty(settingsFilename))
obj.settingsFilename = settingsFilename;
if(isempty(obj.storedChannelSettings) && exist(settingsFilename,'file'))
obj.loadSettings(settingsFilename); %make sure we don't accidentally delete otherwise stored settings
end
if(isempty(obj.storedChannelSettings))
obj.storedChannelSettings = repmat(obj.cell_of_channels{1}.getSettings(),obj.num_channels,1);
for k=2:obj.num_channels
obj.storedChannelSettings(k) = obj.cell_of_channels{k}.getSettings();
end
else
for k=1:obj.num_channels
settings = obj.cell_of_channels{k}.getSettings();
storedEDF_labels = cell(numel(obj.storedChannelSettings),1);
[storedEDF_labels{:}] = obj.storedChannelSettings.EDF_label;
match = find(strcmpi(settings.EDF_label,storedEDF_labels),1);
if(~isempty(match))
obj.storedChannelSettings(match) = settings;
else
obj.storedChannelSettings(end+1) = settings;
end
end
end
storedChannelSettings = obj.storedChannelSettings;
save(settingsFilename,'storedChannelSettings','-mat');
end
end
end
% =================================================================
%> @brief Adjust a channel's reference line offset.
%> @param obj instance of CLASS_channels_container.
%> @param channel_index Index of the channel to adjust.
%> @param reference_offset Offset to adjust reference line to.
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function adjust_reference_offset(obj,channel_index,reference_offset)
if(channel_index<=obj.num_channels && channel_index>0)
obj.cell_of_channels{channel_index}.setReferenceLineOffset(reference_offset);
end
end
% =================================================================
%> @brief Retrieves EDF indices that have been loaded and which are stored in the CLASS_channels_container instance.
%> @param obj instance of CLASS_channels_container.
%> @retval loadedEDFIndices Vector containing the indices of the PSG
%> channels that have been loaded from the current EDF file.
%> @note Synthetic channels are excluded (i.e. ones generated
%> internally using SEV and which are not found in the original EDF
%> file.
% =================================================================
function loadedEDFIndices = getLoadedEDFIndices(obj)
loadedEDFIndices = zeros(obj.num_channels,1);
for k=1:numel(loadedEDFIndices)
loadedEDFIndices(k) = obj.cell_of_channels{k}.EDF_index;
end;
%exclude synthetic channels
loadedEDFIndices = loadedEDFIndices(loadedEDFIndices>0);
end
%% sev menu callbacks
% =================================================================
%> @brief loadEDFchannels(obj,EDF_fullfilename,EDF_channel_indices,use_Default_Samplerate)
%> @param obj instance of CLASS_channels_container.
%> @param EDF_fullfilename Full path and filename of EDF to load
%> @param EDF_channel_indices Vector of channel indices - 1 correspdonds to the
%> first channel in the EDF
%> @param use_Default_Samplerate - boolean (default is true)
%> @retval obj instance of CLASS_channels_container.
%> @retval EDF_HDR EDF's header
% =================================================================
function EDF_HDR = loadEDFchannels(obj,EDF_fullfilename,EDF_channel_indices,use_Default_Samplerate)
try
%default to using the default sample rate
if(nargin<4)
use_Default_Samplerate= true;
end
HDR = loadEDF(EDF_fullfilename);
EDF_channel_indices = EDF_channel_indices(EDF_channel_indices>0 &...
EDF_channel_indices<=numel(HDR.label));
[HDR, signals] = ...
loadEDF(EDF_fullfilename,EDF_channel_indices);
EDF_HDR = HDR;
for k=1:numel(EDF_channel_indices)
EDF_index = EDF_channel_indices(k);
src_label = HDR.label{EDF_index}; %just stick with the EDF label as the title for now (default)
if(use_Default_Samplerate)
%use default samplerate (100Hz)
obj.addChannel(signals{k},...
src_label,EDF_index,HDR.samplerate(EDF_index));
else
%or use sample rate from Header
obj.addChannel(signals{k},...
src_label,EDF_index,HDR.samplerate(EDF_index),HDR.samplerate(EDF_index));
end
end
catch ME
showME(ME);
% ME.message
% ME.stack(1).line
% ME.stack(1).file
EDF_HDR = [];
end
end
% =================================================================
%> @brief Load a single channel as defined by the input arguments
%> @param obj instance of CLASS_channels_container.
%> @param channelData Row vector of channel's sample values
%> @param samplerate Sampling frequency used for the data.
%> @param channelLabel Label to describe the channel (string)
%> @retval obj instance of CLASS_channels_container.
% =================================================================
function HDR = loadGenericChannel(obj,channelData,samplerate,channelLabel)
try
EDF_index = -1;
obj.addChannel(channelData,channelLabel,EDF_index,samplerate);
HDR.duration_sec = numel(channelData)/samplerate;
HDR.T0 = [2020 7 31 00 00 00];
HDR.label = {channelLabel};
HDR.fs = samplerate;
HDR.samplerate = samplerate;
HDR.duration_samples = numel(channelData);
catch ME
showME(ME);
HDR = [];
end