-
Notifications
You must be signed in to change notification settings - Fork 6
/
SimMEEG_GUI.asv
7202 lines (6491 loc) · 523 KB
/
SimMEEG_GUI.asv
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 SimMEEG_GUI(varargin)
%% GUI for user-friendly selection of parameters needed to run SimSignals.m
% varagin = bst structure called directly from Brainstorm see "sm_bst2ft_anatomy_from_bst_files" for input structure
%
% This version is only for distribution with Alex Moiseev.
%
%
% To Do:
% - consider adding MVAR model simulation, called Seed-G by @author: alessandra anzolin ([email protected]).
% - add in EOG artefact simulation based on typical EOG blinks and saccades --> then need to include artefact remove/reduce functions (a lot of work to do this properly).
%
% Updates v24b: Too many to list in detail
% Major:
% - added signal-spread function (SPF) and cross-talk functions (CTF)
% - Important Note: Non-normalized inverse maps must be selected to get same peak locations for Brainstorm's and FieldTrip's inverse solutions: I tested Brainstorm's inverse
% solutions within SimMEEG and within Brainstorm and they replicate as long as "normalized maps" is not selected.
%
% Minor:
% - removed parfor loops for some of functions, but kept it for BRANELab beamformers because it really speeds up the processing.
% - general improvements, memory usage improvements, and processing speed ups
%
% Updates since v21d: Too many to list in detail
% Major:
% - added ability to simuluate sources using Auto-Regressive Model (ARM) - "arm_generate_signal.m" Copyright 2006-2018 Guido Nolte and Stefan Haufe.
% - added spatial (synthetic Cov), temporal (ARM), or spatiotemporal (Cov + ARM) shaping of synthetic noise
% - added ROC analyses of PLV/PLI to estimate performance of inverse solution's ability to estimate ground truth connectivity, i.e., FC for "true" source PLV/PLI.
% - added ability to load in multiple channel montages to be selected from "Anatomy" file; default anatomy contains MEG (sensors = 151) and EEG (channels = 16, 32, 64, 128, and 256).
%
% Minor:
% - general improvements in user interfaces and data selection options
%
% Updates since v19:
% - Major Bug Fixed - Source modeling was setting "Simulated" forward leadfields to the "inverse Head Model" selection --> this yields wrong location errors
% - added button "Plot SpatioTemporal" to plot spatiotemporal mapping of inverse solutions - can then click on source waveform axis to move time cursor
% - fixed monte-carlo bug that allows it to run even when location range dimenions were different across X, Y, Z edit boxes
% - Monte-Carlo Tab: a new look --> reconfigured Monte-Carlo panels
% - Mote-Carlo tab: added head model selection for forward and inverse modeling
% - fixed source waveform calculations in bs_calc_FC.m for MNE and eLORETA by changing (permute) leadfields to needed dimensions
% - fixed "Orientation Constraint" so that user can select "Random" for "Cortical Surface" HeadModels
% - added button "plot LeadField" to plot dipole locations for leadfields and transparency slider for them
% - added a radio button to plot raw or normalized source waveforms from inverse solutions
% - fixed "Noise Projection" menu sub-selection items in panel "Generator Sensor Noise" on the "Simulate M/EEG" Panel
% - added ability to plot evoked as butterfly plot by selecting multiple channels in the list box on the "Simulate M/EEG" Panel
% - added "Real Sensor" in "Noise Projection" on the "Simulate M/EEG" Panel - this allows users to "Load Real Noise" from a datafile.mat with variable data=[samples x channels x trials].
% - added button that with randomize the "Real Sensor" noise loaded by apply Alex Moiseev's PCA-FFT phase randomization procedure --> this removes sensor-to-sensor phase coherences and thus PLV/PLI interactions.
% - change "run_source_modeling.m" to only include sensors (h.anatomy.sens.good_sensors) in lead fields when calculating inverse solutions
% - added "Spatial Temporal" Source searching to find peaks voxels in space with lowest residual variance (best fit - after waveform normalization) to the true source waveforms
% - added text data points to error plots on "Source Modeling Tab"
% - source waveform error is now "% Residual Variance" = sum of squares of differences between peak source and true source waveforms
% - changed source plot colors to peak "Hits" = true source colors and all other false positives as transparent orange
% - when selecting from "Peaks Found" listbox, sources are highlighted in purple and waveforms become solid
% - main figure on startup --> adjusts screensize to fit within monitor's resolution
% - created "Aanlyses" panel on "Source Modeling" tab
% - added "Seeded Functional Connectivity" Analyses with plotting TFRs and 3D connectivity grap; includes Surrogate Statistics
% - added ability to inverse project sensor noise to Seed and comparison locations to use as baseline statistics similar to surrogate statistics for PLV, null distributions are
% based on reshaped matrix of within the active interval of the inverse solution
% - fixed "plot normalized waves" so that "true source waves" are also normalized just liked the "peak source waves" so that the "% Residual Variance" is more accurate measure.
%
%
% Bug or Need-to-Fix report
% - Need to fix "Nearest" for finding nearest source loc to true source based on search distance. Curently making errors of selecting too far away sources
% - Vector inverse solution --> need to add option for selecting maximal dipole orientation <-- currently set to rms of 3 dipole orientations to yield final maps and waveforms
% - allow use to define "dip_thresh" search distances for spatiotemporal searches --> line 44 in "sm_spatiotemp_mapping.m"
% - add in tooltips for all buttons, edit boxes, etc.
% - Time-Frequency Analysis --> change to or add in "ft_freqanalysis.m" because it has a lot more functionality and evidence for use with M/EEG
% - Fixed dB calculation for wavelet TFR in plot_SimSignals.m --> dB = 10*( log10(active) - log10(baseline) );
%
% Modules to add
% - inverse project sens_noise to true source dipoles using leadfield weights to yield "source_noise" --> then project sens_noise using inv_soln weights and compare to source_noise
% Aslo, project sim_data.noise_wav to sensor space to yield "source_noise"
%
version_num = '2.4d';
% hm = warndlg(sprintf('This version is to be used only by Alex Moiseev and Tony Herdman!\n\nYou are viloating Intellectual Property Rights if you are not either of these persons.\n\n'));
% waitfor(hm);
% clear h
global h
warning('off','all');
% opengl software;
[h.simmeeg_dir,h.simmeeg_prog] = fileparts(which('SimMEEG_GUI'));
addpath(h.simmeeg_dir);
%% function handles
h.fcn_handle.plot_3D_mri = @plot_3D_mri;
h.fcn_handle.menu_head_model_CallBack = @menu_head_model_CallBack;
h.fcn_set_topo_caxis = @set_topo_caxis;
h.fcn_update_source_data = @update_source_data;
h.fcn_edit_source_CallBack = @edit_source_CallBack;
h.fcn_plot_3D_mri = @plot_3D_mri;
h.fcn_update_cfg = @update_cfg;
h.fcn_plot_sens_data = @plot_sens_data;
h.fcn_listbox_inv_solns_Callback = @listbox_inv_solns_Callback;
%% Finding varargin that has anatomy variables called from Brainstorm
h.bst_called_flag = 0;
for vi = 1:length(varargin)
if isfield(varargin{1},'subj_MriFile')
bst = varargin{vi};
if isfield(bst,'simmeeg_v24d')
msgbox(sprintf('New "bst_simmeeg.m" was needed to be installed.\nPlease run SimMEEG again.'))
return
end
h.bst_called_flag = 1; % SimMEEG was called from Brainstorm
h.bst = bst;
end
end
% btn = questdlg(sprintf('SimMEEG Software\n\nCopyright (C) 2020 \nDr. Anthony Thomas Herdman and The University of British Columbia\n\nThis program comes with ABSOLUTELY NO WARRANTY\n\nThis program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation\n\nPlease kindly acknowledge Dr. Anthony Herdman at UBC when presenting work from SimMEEG and/or redistributing this software.\n\nThis software is not licensed for clinical use or training.\n\n Liability: The developers, distrubtors, and licensors of this product are not liable in any form or in any way for losses that you, the licensee, may incur from use or re-distribution of this software.\n\n Click "Accept" if you agree to these licensing terms, otherwise click "Decline"'),'License Agreement','Accept','Decline','Accept');
if exist('bst','var') % SimMEEG opened from Brainstorm so license already accepted
h.license_flag = 1;
else % SimMEEG opened from matlab directly
h.license_flag = 0;
sm_popup_license_terms;
end
if h.license_flag==1
%% %%%%%%%%%%%%%%%%%%%%%%%%%%% Adding paths %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h.pwd=pwd;
%% User-defined or Brainstorm paths
if exist('bst','var') % Brainstorm preset paths - if SimMEEG called directly from BrainStorm
if isfield(bst,'subj_anat_dir') && isfield(bst,'subj_data_dir') && isfield(bst,'FieldTrip_dir')
h.data_dir = bst.subj_data_dir;
h.anat_path = bst.subj_anat_dir;
h.FieldTrip_dir = bst.FieldTrip_dir;
try h.Brainstorm_dir = bst.Brainstorm_dir; catch; h.Brainstorm_dir = uigetdir(h.pwd,'Open Brainstorm Directory'); end
else % User-defined paths
h.data_dir = uigetdir(h.pwd,'Set Data Directory');
h.anat_path = uigetdir(h.pwd,'Set Anatomy Directory');
h.FieldTrip_dir = uigetdir(h.pwd,'Open Field Trip Directory');
h.Brainstorm_dir = uigetdir(h.pwd,'Open Brainstorm Directory');
end
else % User-defined paths
h.data_dir = uigetdir(h.pwd,'Set Data Directory');
try
sidx = findstr(h.simmeeg_dir,'\'); spath = h.simmeeg_dir(1:sidx(end));
h.anat_path = fullfile(spath,'anatomy\'); % exist(h.anat_path,'dir');
% h.FieldTrip_dir = fullfile(spath,'fieldtrip-20200911\');
h.FieldTrip_dir = fullfile(spath,'fieldtrip-20240201\');
h.Brainstorm_dir = fullfile(spath,'brainstorm3\');
catch
h.anat_path = uigetdir(h.pwd,'Set Anatomy Directory');
h.FieldTrip_dir = uigetdir(h.pwd,'Open Field Trip Directory');
h.Brainstorm_dir = uigetdir(h.pwd,'Open Brainstorm Directory');
end
h.bst = []; % SimMEEG start up directly
h.bst_subj_data_dir ='';
end
%% Adding FieldTrip paths
cd(h.FieldTrip_dir); %C:\BRANELab\Software\BRANE_Lab_v3\fieldtrip-20200519\;
ft_defaults;
cd(h.pwd);
% Field Trip's external directory with filtfilt messes up BRANE Lab's filter_data_new.m function so need to remove this directory for filtering function
h.FieldTrip_dir_external = genpath([ h.FieldTrip_dir,'\external\']);
rmpath(h.FieldTrip_dir_external);
%% Adding Brainstorm Directory
if ~isempty(h.Brainstorm_dir)
cd(h.Brainstorm_dir)
brainstorm setpath
cd(h.pwd)
else
msgbox(sprintf('Brainstorm Path ws not set properly.\nBrainstorms inverse modeling functions will not work.'),'Warning!');
end
%% Initializing UserData
h.UserData.bkg_clr = [1 1 1]; % background color
% h.cfg.study.source_locs = [91 48 78; 35 109 78; 151 109 78]; % [primary vis, Left Aud, Right Aud];
h.cfg.study.source_locs = [86 26 77; 37 114 77; 150 110 79]; % [primary vis, Left Aud, Right Aud];
% h.tfr_ROI(1)=''; h.tfr_ROI(2)=''; h.tfr_ROI(3)=''; % time-frequency ROIs for each source
h.src_clr=[0 .6 0; 0 0 1; 1 0 0]; %[.8 .8 1; 1 .8 .8; .8 1 .8];
h.src_clr2=[.7 .9 .7; .8 .8 1; 1 .8 .8];
h.FA_clr = [0.8 0.6 0]; %[115 77 38]/255;
% h.plv_clr = [.7 0 .9; 1 0 1; 1 .6 0];
% h.plv_clr2 = [.7 0 .9; 1 0 1; 1 .6 0]*.5;
h.plv_clr = [0 0 0; 1 0 1; 0 .6 1];
h.plv_clr2 = [0 0 0; 1 0 1; 0 .6 1]*.5;
% h.src_clr=[0 0 0; .8 0 .8; 1 .5 0]; %[.8 .8 1; 1 .8 .8; .8 1 .8];
% h.src_clr2=[.6 .6 .6; 1 .8 1; 1 .8 .7];
h.tfr_clr = [0 0 0; 0 1 .5; 1 .5 0]; % TotPwr, IndPwr, EvkPwr
h.chan_clr = [1 0 .5]*.7; %[1 0 1];
h.sens_clr = [0 0 0];
h.brain_clr = [1 1 1]*.5; % [.6 .8 1]; %
h.scalp_clr = [178 116 62]/255; %[1 .8 .8]; %[.6 .8 1];
h.trial_wave_clr = [1 1 1]*.8;
% h.evk_clr=[0 0 1; 1 0 0; 0 1 0]; % Evoked not determined for this GUI. Evoked waves are calculated while running the simulation.
h.freq_vals=1:200;
h.caxis_power=[-100 100]; h.caxis_PLV=[-100 100]; h.caxis_PLI=[-100 100];
h.num_sig_freqs=0;
h.current_source_num=1; h.current_tfr_roi_idx=1;
h.topo_lat_samp =[];
h.inv_soln = [];
h.current_3D_thresh = .5;
h.current_filt_freqs = [0 0 0 0];
h.current_inv_soln = [];
h.plv_contrasts = [1 2; 1 3; 2 3];
h.monte_carlo_flag = 0;
h.new_study_flag = 0;
h.start_flag = 1;
% h.bst_subj_anat_dir = h.data_dir;
% h.bst_subj_data_dir = h.data_dir;
h.brainstorm_db = h.data_dir;
h.bst_subj_anat_dir = h.data_dir;
h.cfg.study.bst_params.inv_NoiseMethod = {'reg' 'median' 'diag' 'none' 'shrink'};
h.anatomy = struct('mri','','sens_eeg','','sens_meg','','mesh_volumes',[],'headmodel_eeg_vol','','headmodel_meg_vol','','headmodel_eeg_cortex','','headmodel_meg_cortex','','leadfield_eeg_vol','','leadfield_eeg_cortex','','leadfield_meg_vol','','leadfield_meg_cortex','','sens','','headmodel','','leadfield','','mesh_cortex','');
h.real_noise_datadir = ' ';
h.real_source_datadir = ' ';
h.font_size_warndlg = 11;
h.find_spatiotemp_peaks_flag = 0; % (0) regular peak search inv_soln map (1) spatiotemporal search for peaks in inv_soln source waveforms
h.false_positive_FaceAlpha = .5; % FaceAlpha transparency for plotting source locations for false positives
h.false_positive_lineAlpha = .25; % lineAlpha transparency for plotting source waves for false positives
h.sim_data.cfg.source.TFR_results = []; % True Source Time-freq results
h.current_inv_tfr_time_point = []; % time-freq point on inverse-source modleing Tab's TFR plots
h.current_inv_true_fc_data = []; %
h.current_inv_peak_fc_data = []; %
h.fieldtrip_tfr_data = [];
h.current_inv_tfr_freq_samp = 1;
h.current_fieldtrip_tfr_data = [];
h.plot_topo_movie_flag = 0; % flag for plotting movie of topography
h.cfg.study.sensor_noise_cov_exp = 0.273; % default Exponent for Covariance shaping of noise
h.run_inv_soln_flag = 0; % flag to designate that user pressed "Run Modeling" so that all calls during this are to reset "hit_idx, ..."
h.calc_results_flag = 0; % flag to not update image plots while calculating results (1)=don't update plots (0)=update plots
%% timer function
h.timer_plot_topo_movie = timer('Name','plot_topo_movie', ...
'Period',0.1, ... % This is fixed and should not be changed
'StartDelay',0.001, ...
'TasksToExecute',inf, ...
'ExecutionMode','fixedSpacing', ...
'BusyMode','drop', ...
'TimerFcn',@plot_topo_data_movie);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MAIN Figure %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h.main_fig = figure; set(h.main_fig,'Units','normalized','Position',[.05 .05 .85 .85],'Name',sprintf('SimMEEG v%.1f',version_num),'NumberTitle','off');
addToolbarExplorationButtons(h.main_fig) % Adds zoom, rotate, ... buttons to figure toolbar
h.main_fig.CloseRequestFcn = @closereq_SimMEEG;
h.main_fig.Name = sprintf('BRANE Lab: SimMEEG v%s',version_num);
%% %%%%% Panel "Study Parameters" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h.study_panel = uipanel(h.main_fig,'Title','Study & Source Parameters','FontSize',12,'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',[.6 0 1],...
'Units','normalize','Position',[.005 .865 .86 .13],'FontWeight','bold');
h.txt_length = .12;
h.ui_length = .05;
h.ui_height = .2;
h.txt_clmn_pos = .01:.185:.99; %.01:.205:.99;
h.ui_clmn_pos = .135:.185:.99; %.135:.205:.99;
h.txt_row_pos = fliplr(.1:h.ui_height+.025:1-h.ui_height+.02);
%% srate
h.edit_srate_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(1) h.txt_row_pos(1) h.txt_length h.ui_height],'FontSize',10,'HorizontalAlignment','left','String','Sample Rate');
h.edit_srate = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Tag','edit_srate','Position',[h.ui_clmn_pos(1) h.txt_row_pos(1) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','256','Callback',@update_study_cfg);
%% Trial Duration
h.edit_dur_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(1) h.txt_row_pos(2) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Trial Duration (sec)');
h.edit_dur = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Tag','edit_dur','Position',[h.ui_clmn_pos(1) h.txt_row_pos(2) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','-1 1','Callback',@update_study_cfg);
% update_study_cfg;
% h.num_samps_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
% 'Position',[h.edit_dur.Position(1)+h.edit_dur.Position(3)+.01 1-h.study_panel.Position(4)-.01 .1 h.study_panel.Position(4)],...
% 'FontSize',10,'HorizontalAlignment','left','String',sprintf('Samples = %.f',h.cfg.study.num_samps));
%% Numbers of Trials
h.edit_num_trials_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(1) h.txt_row_pos(3) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Number Trials');
h.edit_num_trials = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(1) h.txt_row_pos(3) h.ui_length h.ui_height],...
'FontSize',8,'HorizontalAlignment','center','String','90','Callback',@update_study_cfg);
%% Signal-to-Noise Ratio (SNR)
h.edit_sens_SNR_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(1) h.txt_row_pos(4) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','SNR (dB)');
h.edit_sens_SNR = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(1) h.txt_row_pos(4) h.ui_length h.ui_height],...
'FontSize',8,'HorizontalAlignment','center','String','-2','Value',1,'Tooltip',sprintf('SNR (dB) = 20*log10(signal/noise))\n where\n "signal" is RMS of post-event interval \n "noise" is the RMS of the baseline interval'));
%% Noise Amplitude Percent
h.edit_noise_amp_perc_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(2) h.txt_row_pos(2) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Noise Ampltidue (%)');
h.edit_noise_amp_perc = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(2) h.txt_row_pos(2) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','10','Callback',@update_study_cfg);
%% Noise Frequncy Band
h.edit_noise_freqs_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(2) h.txt_row_pos(1) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Noise Band (Hz)');
h.edit_noise_freqs = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(2) h.txt_row_pos(1) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','1 100','Callback',@update_study_cfg);
%% Noise Type
h.edit_noise_flag_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(2) h.txt_row_pos(3) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Noise Type');
h.edit_noise_flag = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[h.ui_clmn_pos(2)-.05 h.txt_row_pos(3) h.ui_length+.05 h.ui_height],...
'FontSize',8,'HorizontalAlignment','center','String',{'Broad Band' 'Narrow Band' 'Notched Band' 'Pink/Brown'},'Value',2,'Callback',@update_study_cfg);
h.edit_pink_noise_slope_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(2) h.txt_row_pos(4)-.05 h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Pink Noise Slope');
h.edit_pink_noise_slope = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(2) h.txt_row_pos(4)-.05 h.ui_length h.ui_height],'Tag','pink_slope','ToolTip','Value must be between 1.0 to 2.0',...
'FontSize',10,'HorizontalAlignment','center','String','1 100','Callback',@update_study_cfg);
%% Baseline Interval
h.edit_base_int_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(3) h.txt_row_pos(1) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Baseline Interval');
h.edit_base_int = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(3) h.txt_row_pos(1) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','-0.5 0','Callback',@update_study_cfg);
%% Post-Event Interval
h.edit_poststim_int_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(3) h.txt_row_pos(2) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Post-Event Interval','Tooltip','(seconds) Used for calculating SNR');
h.edit_poststim_int = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(3) h.txt_row_pos(2) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','0 0.5','Callback',@update_study_cfg,'Tooltip','(seconds) Used for calculating SNR');
%% PLV Target Threshold
h.edit_plv_thresh_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(3) h.txt_row_pos(3) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','PLV Target Threshold');
h.edit_plv_thresh = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(3) h.txt_row_pos(3) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','0.05','Callback',@update_study_cfg);
%% plots Simulated Data pop-ups
% h.radio_plot_sim_flag = uicontrol(h.study_panel,'Style','radiobutton', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
% 'Position',[.89 h.txt_row_pos(1) h.txt_length h.ui_height],...
% 'FontSize',10,'HorizontalAlignment','left','String','Plot Sim Data');
%% Num PLV Perms
h.edit_max_perm_plv_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(3) h.txt_row_pos(4) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','PLV Permutations');
h.edit_max_perm_plv = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[h.ui_clmn_pos(3) h.txt_row_pos(4) h.ui_length h.ui_height],...
'FontSize',8,'HorizontalAlignment','center','String',{'7' '8' '9' '10'},'Value',3,'Callback',@update_study_cfg);
%% Plot Time Interval
h.edit_plot_time_int_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(4) h.txt_row_pos(1) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Plot Interval (sec)');
h.edit_plot_time_int = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(4) h.txt_row_pos(1) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','-1 1','Callback',@update_study_cfg);
%% Plot Freq Interval
h.edit_plot_freq_int_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(4) h.txt_row_pos(2) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Plot Frequencies (Hz)');
h.edit_plot_freq_int = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(4) h.txt_row_pos(2) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','1 60','Callback',@update_study_cfg);
%% Plot Color Axis
h.edit_plot_caxis_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(4) h.txt_row_pos(3) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Plot Power Scale (%)');
h.edit_plot_caxis = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(4) h.txt_row_pos(3) h.ui_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','center','String','-100 100','Callback',@update_study_cfg);
%% Edit Study Name
h.edit_study_name_txt = uicontrol(h.study_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.txt_clmn_pos(4) h.txt_row_pos(4) h.txt_length h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','Study Name Prefix:','Tooltip','Study Name to be used as a prefix for saving Datasets.');
h.edit_study_name = uicontrol(h.study_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[h.ui_clmn_pos(4) h.txt_row_pos(4) h.ui_length*4 h.ui_height],...
'FontSize',10,'HorizontalAlignment','left','String','SimMEEG','Tooltip','Study Name to be used as a prefix for saving Datasets.');
%% Save Study
h.btn_save_study = uicontrol(h.study_panel,'BackgroundColor',[1 .8 .8],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.91 .79 .075 h.ui_height],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','Save Study','Callback',@save_study);
%% Load Study
h.btn_load_study = uicontrol(h.study_panel,'BackgroundColor',[.8 1 .8],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.91 .57 .075 h.ui_height],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','Load Study','Callback',@load_study);
%% New Study
h.btn_new_study = uicontrol(h.study_panel,'BackgroundColor',[.8 .8 1],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.91 .35 .075 h.ui_height],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','New Study','Callback',@new_study);
%% Study Directory
h.btn_datadir = uicontrol(h.study_panel,'BackgroundColor',[1 1 1]*.9,'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.91 .13 .075 h.ui_height],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','Set Data Dir','Callback',@get_datadir);
%% Initializing h.cfg.study data
h.cfg.study.srate=str2num(h.edit_srate.String);
h.cfg.study.dur=str2num(h.edit_dur.String); % (sec) start and end times for whole trial
h.cfg.study.lat_sim=[h.cfg.study.dur(1):1/h.cfg.study.srate:h.cfg.study.dur(2)-(1/h.cfg.study.srate)]; % latency of each trial
h.cfg.study.num_samps=length(h.cfg.study.lat_sim);
h.cfg.study.num_trials = str2num(h.edit_num_trials.String); %{h.edit_num_trials.Value});
h.cfg.study.max_perm_plv = str2num(h.edit_max_perm_plv.String{h.edit_max_perm_plv.Value}); %h.cfg.study.num_trials/10; % integer of cfg.study.num_trials/10 = maximum number of permutations to search for PLV_trials (must be <10 or memory will fail on most computers) .
h.cfg.study.noise_flag=h.edit_noise_flag.Value; % Whitening noise to be added to each sources
h.cfg.study.noise_amp_perc=str2num(h.edit_noise_amp_perc.String); % percent of noise to add to overall signal throughout the num_samps to whiten the data for time-freq analyses.
h.cfg.study.noise_freqs=str2num(h.edit_noise_freqs.String); % [1 100] Frequency (Hz) of noise to add to overall signal throughout the num_samps to whiten the data for time-freq analyses.
h.cfg.study.plv_thresh=str2num(h.edit_plv_thresh.String); % stoppping criterion when search for best PLV/PLI matched to sig_PLV_targets, sig_PLI_targets, etc. (e.g., 0.05).
h.cfg.study.plot_sim_flag=0; %h.radio_plot_sim_flag.Value; % plots evoked, trial, and PLV results. Note: This can take time because of filtering.
h.cfg.study.plot_time_int=str2num(h.edit_plot_time_int.String); % time interval to plot
h.cfg.study.plot_freq_int=str2num(h.edit_plot_freq_int.String); % frequencies for calculating and plotting PLV/PLI
h.cfg.study.base_int=str2num(h.edit_base_int.String); % base line interval for plotting
h.cfg.study.poststim_int=str2num(h.edit_poststim_int.String); % base line interval for plotting
h.cfg.study.act_samps = (round( (h.cfg.study.poststim_int(1)-h.cfg.study.lat_sim(1))*h.cfg.study.srate ):round( (h.cfg.study.poststim_int(2)-h.cfg.study.lat_sim(1))*h.cfg.study.srate )) +1;
h.cfg.study.ctrl_samps = (round( (h.cfg.study.base_int(1)-h.cfg.study.lat_sim(1))*h.cfg.study.srate ):round( (h.cfg.study.base_int(2)-h.cfg.study.lat_sim(1))*h.cfg.study.srate )) +1;
% ss = find(h.cfg.study.lat_sim<=h.cfg.study.poststim_int(1)); sx(1) = ss(end); ss = find(h.cfg.study.lat_sim<=h.cfg.study.poststim_int(2)); sx(2) = ss(end);
% h.cfg.study.act_samps = sx(1):sx(2);
% ss = find(h.cfg.study.lat_sim<=h.cfg.study.base_int(1)); sx(1) = ss(end); ss = find(h.cfg.study.lat_sim<=h.cfg.study.base_int(2)); sx(2) = ss(end);
% h.cfg.study.ctrl_samps = (round( (h.cfg.study.base_int(1)-h.cfg.study.lat_sim(1))*h.cfg.study.srate ):round( (h.cfg.study.base_int(2)-h.cfg.study.lat_sim(1))*h.cfg.study.srate )) +1;
%
h.cfg.study.plot_time_vals=h.cfg.study.plot_time_int(1):1/h.cfg.study.srate:h.cfg.study.plot_time_int(2);
h.cfg.study.plot_freq_vals=h.cfg.study.plot_freq_int(1):h.cfg.study.plot_freq_int(2);
h.cfg.study.pink_noise_slope = normrnd(1.8,.1,1); % Arbitrarily set to be randomized with overall mean 1.8 % seemed to best match the slope from a couple of resting-state data from LetterAll study
if h.cfg.study.pink_noise_slope<1; h.cfg.study.pink_noise_slope=1; elseif h.cfg.study.pink_noise_slope>2; h.cfg.study.pink_noise_slope=2; end
h.edit_pink_noise_slope.String = sprintf('%.1f',h.cfg.study.pink_noise_slope);
h.current_3D_plv_contrasts_listbox_order =[];
h.current_3D_plv_contrasts = [];
%% Update Study Information
update_study_cfg;
%% %%%%% Panel "Simulate Sources" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h.run_simulation_panel = uipanel(h.main_fig,'Title','Simulate Sources','FontSize',12,'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',[.6 0 1],...
'Units','normalize','Position',[.87 .865 .125 .13],'Visible','on');
%% Btn Update cfg
h.btn_update_cfg = uicontrol(h.run_simulation_panel,'BackgroundColor',[1 .8 .8],'ForegroundColor',[0 0 0],'Style','pushbutton','Units','normalize',...
'Position',[.05 .78 .9 .2],'Visible','on','UserData',1,...
'FontSize',10,'HorizontalAlignment','center','String','Update Params','Callback',@update_cfg);
%% Btn Simulate Source data
h.btn_run_sim = uicontrol(h.run_simulation_panel,'BackgroundColor',[.8 1 .8],'ForegroundColor',[0 0 0],'Style','pushbutton','Units','normalize',...
'Position',[.05 .78-.25 .9 .2],'Visible','on','UserData',1,...
'FontSize',10,'HorizontalAlignment','center','String','Sim Source Data','Callback',@run_sim);
%% Btn "Calc Source PLV" Data
h.btn_plot_sim_data = uicontrol(h.run_simulation_panel,'BackgroundColor',[.8 .8 1],'ForegroundColor',[0 0 0],'Style','pushbutton','Units','normalize',...
'Position',[.05 .78-.5 .9 .2],'Visible','on','UserData',1,...
'FontSize',10,'HorizontalAlignment','center','String','Calc Source PLV','Callback',@plot_SimSignals);
%% Edit: Wavelet Time-Bandwitdh parameter
% delete(h.edit_wavelet_TB_txt); delete(h.edit_wavelet_TB);
h.edit_wavelet_TB_txt = uicontrol(h.run_simulation_panel,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[.1 .02 .55 .2],...
'FontSize',10,'HorizontalAlignment','left','String','Wavelet TB');
h.edit_wavelet_TB = uicontrol(h.run_simulation_panel,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[.65 .02 .2 .2],'Tooltip',sprintf('The larger the time-bandwidth parameter, \nthe more spread out the wavelet is in time\nand narrower the wavelet is in frequency.'),...
'FontSize',9,'HorizontalAlignment','center','String','30');
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tabs for Source, PLV, and PLI parameters and Simulate M/EEG %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Creating Tabs
h.tabgrp = uitabgroup(h.main_fig,'Units','normalize','Position',[.005 .005 .995 .86],'Visible','on');
% h.tab_anatomy = uitab(h.tabgrp,'Title','Anatomy','BackgroundColor',[1 1 1],'Foregroundcolor',[0 0 0]);
h.tab_power = uitab(h.tabgrp,'Title','Event-Related Power','BackgroundColor',[1 1 1],'Foregroundcolor',[0 .6 0]);
h.tab_PLV = uitab(h.tabgrp,'Title','Phase-Locking Value (PLV)','BackgroundColor',[1 1 1],'Foregroundcolor',h.plv_clr(1,:));
h.tab_PLI = uitab(h.tabgrp,'Title','Phase-Lag Index (PLI)','BackgroundColor',[1 1 1],'Foregroundcolor',h.plv_clr(2,:));
h.tab_PAC = uitab(h.tabgrp,'Title','Phase-Amplitude Coupling (PAC)','BackgroundColor',[1 1 1],'Foregroundcolor',[.2 .75 0]);
h.tab_sim_meeg = uitab(h.tabgrp,'Title','Simulate M/EEG','BackgroundColor',[1 1 1],'Foregroundcolor',[0 .6 .6]);
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tab "Source Modeling" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
create_tab_source_modeling;
h.tab_monte_carlo = uitab(h.tabgrp,'Title','Monte Carlo','BackgroundColor',[1 1 1],'Foregroundcolor',[0 .2 .6]);
% h.tab_preprocess = uitab(h.tabgrp,'Title','Data Preprocess','BackgroundColor',[1 1 1],'Foregroundcolor',[.3 .6 .5]);
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tab "Event-Related Power" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%% SOURCE TFR Paramaters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% standard parameters for text and edit boxes
h.tfr_xpos=[.05 .35 .65];
h.tfr_ypos=.55; h.tfr_pos_size=[.265 .3];
h.sig_ypos=.3; h.sig_pos_size=[.265 .2];
h.prepost_ypos=.05;
h.source_edit_length = .035; h.source_edit_height = .03; h.source_edit_ypos = [.92 .88];
%% Source Triplets - Visible 'Off" to be added in future versions
% delete(h.menu_triplets_txt); delete(h.menu_triplets);
h.menu_triplets_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize','Visible','off',...
'Position',[.005 .965 .0275 .03],'FontSize',10,'HorizontalAlignment','right','String','Triplets');
h.menu_triplets = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize','Visible','off',...
'Position',[.035 .968 .045 .03],'FontSize',8,'HorizontalAlignment','center','String',{'1'},'Value',1,'Callback',{@update_triplet,'update'});
%% Button Add & Delete triplets
% delete(h.btn_add_triplets);
h.btn_add_triplets = uicontrol(h.tab_power,'BackgroundColor',[1 1 1]*.9,'ForegroundColor',h.src_clr(1,:),'Style','pushbutton','Units','normalize',...
'Position',[0.005 .925 .075 .035],'Visible','off','UserData',1,...
'FontSize',10,'HorizontalAlignment','center','String','Copy Triplet','Callback',{@update_triplet,'copy'});
% delete(h.btn_del_triplets);
h.btn_del_triplets = uicontrol(h.tab_power,'BackgroundColor',[1 1 1]*.9,'ForegroundColor','r','Style','pushbutton','Units','normalize','Visible','off',...
'Position',[0.005 .885 .075 .035],'Visible','off','UserData',1,...
'FontSize',10,'HorizontalAlignment','center','String','Delete Triplet','Callback',{@update_triplet,'del'});
%% Signal Window Type
h.menu_sig_win_type_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[.075 .965 .055 .03],'FontSize',10,'HorizontalAlignment','right','String','Windowing');
h.menu_sig_win_type = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[.135 .968 .045 .03],'FontSize',8,'HorizontalAlignment','center','String',{'Hanning' 'Gaussian' 'Triangular','Blackmann'},'Value',3,'Callback',@update_study_cfg);
h.menu_sig_win_type.Enable='on'; % currently setting it so that it only does triangular windowing
%% Button Select TFR ROI
h.btn_ROI_source1 = uicontrol(h.tab_power,'BackgroundColor',[1 1 1]*.9,'ForegroundColor',h.src_clr(1,:),'Style','pushbutton','Units','normalize',...
'Position',[sum(h.menu_sig_win_type.Position([1 3]))+.01 .965 .075 .035],'Visible','on','UserData',1,...
'FontSize',10,'HorizontalAlignment','center','String','Select ROI','Callback',@bl_rbbox_gca_v2);
%% Menu: ROI
h.menu_tfr_roi_idx_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.btn_ROI_source1.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .035 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','ROI #');
h.menu_tfr_roi_idx = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_tfr_roi_idx_txt.Position([1 3]))+.005 .968 .065 .03],'FontSize',8,'HorizontalAlignment','center','String',{''},'Value',1,'Callback',{@set_current_ROI,0}); % menu listing TFR ROIs
%% Menu: Source #
h.menu_source_idx_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.menu_tfr_roi_idx.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .04 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Source');
h.menu_source_idx = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_source_idx_txt.Position([1 3]))+.005 .968 .035 .03],'FontSize',8,'HorizontalAlignment','center','String',{'1' '2' '3'},'Value',1,'Callback',{@set_current_source,0}); % menu listing TFR ROIs
%% Edit: TFR ROI limits
% Frequency
h.edit_tfr_roi_ylim_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.menu_source_idx.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .105 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Frequency Range');
h.edit_tfr_roi_ylim = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_ylim_txt.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .05 .035],...
'Tag','TFR Frequency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
% Latency
h.edit_tfr_roi_xlim_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_ylim.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .095 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Latency Range');
h.edit_tfr_roi_xlim = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_xlim_txt.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .075 .035],...
'Tag','TFR Latency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
% Rise Time
h.edit_tfr_roi_risetime_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_xlim.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .095 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Rise/Fall Time');
h.edit_tfr_roi_risetime = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_risetime_txt.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .045 .035],...
'Tag','TFR Latency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
%% Edit: Source Power & Evoked Percent
sig_tag = {'Sig 1 ' 'Sig 2 ' 'Sig 3 '};
prepost_tag = {'Pre 1 ' 'Pre 2 ' 'Pre 3 '};
box_type = {'Power' 'PLV' 'PLI' 'Latency Range' 'Frequency Range' };
for v=1:3
%% Signal Power Percent
h.edit_sig_power_perc_txt(v) = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(v,:),'Units','normalize',...
'Position',[h.tfr_xpos(v) h.source_edit_ypos(1) .105 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Power (%) Signal ');
h.edit_sig_power_perc(v) = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.src_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_sig_power_perc_txt(v).Position([1 3]))+.005 h.source_edit_ypos(1) h.source_edit_length h.source_edit_height],...
'Tag',[sig_tag{v} box_type{1}],'FontSize',10,'HorizontalAlignment','center','String','100','Callback',@set_tfr_roi_cfg);
%% PrePost power Percent
h.edit_prepost_power_perc_txt(v) = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(v,:),'Units','normalize',...
'Position',[sum(h.edit_sig_power_perc(v).Position([1 3]))+.005 h.source_edit_ypos(1) .05 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Prepost');
h.edit_prepost_power_perc(v) = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.src_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_prepost_power_perc_txt(v).Position([1 3]))+.005 h.source_edit_ypos(1) h.source_edit_length h.source_edit_height],...
'Tag',[prepost_tag{v} box_type{1}],'FontSize',10,'HorizontalAlignment','center','String','50','Callback',@set_tfr_roi_cfg);
%% Signal Evoked Percent
h.edit_sig_evoked_perc_txt(v) = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(v,:),'Units','normalize',...
'Position',[h.tfr_xpos(v) h.source_edit_ypos(2) .105 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Evoked (%) Signal ');
h.edit_sig_evoked_perc(v) = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.src_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_sig_evoked_perc_txt(v).Position([1 3]))+.005 h.source_edit_ypos(2) h.source_edit_length h.source_edit_height],...
'Tag',[sig_tag{v} box_type{1}],'FontSize',10,'HorizontalAlignment','center','String','50','Callback',@set_tfr_roi_cfg);
%% PrePost Evoked Percent
h.edit_prepost_evoked_perc_txt(v) = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(v,:),'Units','normalize',...
'Position',[sum(h.edit_sig_evoked_perc(v).Position([1 3]))+.005 h.source_edit_ypos(2) .05 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Prepost');
h.edit_prepost_evoked_perc(v) = uicontrol(h.tab_power,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.src_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_prepost_evoked_perc_txt(v).Position([1 3]))+.005 h.source_edit_ypos(2) h.source_edit_length h.source_edit_height],...
'Tag',[prepost_tag{v} box_type{1}],'FontSize',10,'HorizontalAlignment','center','String','0','Callback',@set_tfr_roi_cfg);
end
%% Source 1 Power Axes
h.ax_power(1)=axes(h.tab_power,'Position',[h.tfr_xpos(1) h.tfr_ypos h.tfr_pos_size]);
h.tfr_data.s1=surf(h.ax_power(1),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_power(1),0,90); shading(h.ax_power(1),'flat'); axis(h.ax_power(1),'tight'); axis(h.ax_power(1),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.tfr_data.tfr_zero_line(1) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 1 Power','Color',h.src_clr(1,:)); colormap(jet(255)); caxis(h.caxis_power);
% disableDefaultInteractivity(h.ax_power(1)); %h.tfr_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
h.ax_power(1).YLabel.String='Frequency (Hz)';
%% Source 2 Power Axes
h.ax_power(2)=axes(h.tab_power,'Position',[h.tfr_xpos(2) h.tfr_ypos h.tfr_pos_size]);
h.tfr_data.s2=surf(h.ax_power(2),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_power(2),0,90); shading(h.ax_power(2),'flat'); axis(h.ax_power(2),'tight'); axis(h.ax_power(2),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.tfr_data.tfr_zero_line(2) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 2 Power','Color',h.src_clr(2,:)); colormap(jet(255)); caxis(h.caxis_power);
% disableDefaultInteractivity(h.ax_power(2)); %h.tfr_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
%% Source 3 Power Axes
h.ax_power(3)=axes(h.tab_power,'Position',[h.tfr_xpos(3) h.tfr_ypos h.tfr_pos_size]);
h.tfr_data.s3=surf(h.ax_power(3),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_power(3),0,90); shading(h.ax_power(3),'flat'); axis(h.ax_power(3),'tight'); axis(h.ax_power(3),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.tfr_data.tfr_zero_line(3) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 3 Power','Color',h.src_clr(3,:)); colormap(jet(255)); caxis(h.caxis_power);
% disableDefaultInteractivity(h.ax_power(3)); %h.tfr_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
pos=h.ax_power(3).Position; cb=colorbar;
h.ax_power(3).Position=pos;
%% Source Power Wave Axes
h.ax_sig_waves(1)=axes(h.tab_power,'Position',[h.tfr_xpos(1) h.sig_ypos h.sig_pos_size]); box on; title('Source 1 Target Signal Waves','Color',h.src_clr(1,:));
h.ax_sig_waves(2)=axes(h.tab_power,'Position',[h.tfr_xpos(2) h.sig_ypos h.sig_pos_size]); box on; title('Source 2 Target Signal Waves','Color',h.src_clr(2,:));
h.ax_sig_waves(3)=axes(h.tab_power,'Position',[h.tfr_xpos(3) h.sig_ypos h.sig_pos_size]); box on; title('Source 3 Target Signal Waves','Color',h.src_clr(3,:));
h.ax_prepost_waves(1)=axes(h.tab_power,'Position',[h.tfr_xpos(1) h.prepost_ypos h.sig_pos_size]); box on; title('Source 1 Target PrePost Waves','Color',h.src_clr(1,:));
h.ax_prepost_waves(2)=axes(h.tab_power,'Position',[h.tfr_xpos(2) h.prepost_ypos h.sig_pos_size]); box on; title('Source 2 Target PrePost Waves','Color',h.src_clr(2,:));
h.ax_prepost_waves(3)=axes(h.tab_power,'Position',[h.tfr_xpos(3) h.prepost_ypos h.sig_pos_size]); box on; title('Source 3 Target PrePost Waves','Color',h.src_clr(3,:));
%% point position when dragging cursor point
h.pt_txt = uicontrol(h.tab_power,'Style','text', 'BackgroundColor',h.tab_power.BackgroundColor,'Foregroundcolor','k','Units','normalize',...
'Position',[.35 0 .3 .025],'FontSize',10,'HorizontalAlignment','center','String','Lat = 0 ms Amp = 0');
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tab "Phase-Locking Value (PLV)" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%% SOURCE PLV Paramaters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Source 1 vs 2 PLV Axes
h.ax_PLV(1)=axes(h.tab_PLV,'Position',[h.tfr_xpos(1) h.tfr_ypos h.tfr_pos_size]);
h.plv_data.s1=surf(h.ax_PLV(1),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_PLV(1),0,90); shading(h.ax_PLV(1),'flat'); axis(h.ax_PLV(1),'tight'); axis(h.ax_PLV(1),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.plv_data.tfr_zero_line(1) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 1 vs 2 Target PLV','Color',h.plv_clr(1,:)); colormap(jet(255)); caxis(h.caxis_PLV);
% disableDefaultInteractivity(h.ax_PLV(1)); %h.plv_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
h.ax_PLV(1).YLabel.String='Frequency (Hz)';
%% Source 1 vs 3 PLV Axes
h.ax_PLV(2)=axes(h.tab_PLV,'Position',[h.tfr_xpos(2) h.tfr_ypos h.tfr_pos_size]);
h.plv_data.s2=surf(h.ax_PLV(2),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_PLV(2),0,90); shading(h.ax_PLV(2),'flat'); axis(h.ax_PLV(2),'tight'); axis(h.ax_PLV(2),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.plv_data.tfr_zero_line(2) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 1 vs 3 Target PLV','Color',h.plv_clr(2,:)); colormap(jet(255)); caxis(h.caxis_PLV);
% disableDefaultInteractivity(h.ax_PLV(2)); %h.plv_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
%% Source 2 vs 3 PLV Axes
h.ax_PLV(3)=axes(h.tab_PLV,'Position',[h.tfr_xpos(3) h.tfr_ypos h.tfr_pos_size]);
h.plv_data.s3=surf(h.ax_PLV(3),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_PLV(3),0,90); shading(h.ax_PLV(3),'flat'); axis(h.ax_PLV(3),'tight'); axis(h.ax_PLV(3),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.plv_data.tfr_zero_line(3) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 2 vs 3 Target PLV','Color',h.plv_clr(3,:)); colormap(jet(255)); caxis(h.caxis_PLV);
% disableDefaultInteractivity(h.ax_PLV(3)); %h.plv_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
pos=h.ax_PLV(3).Position; cb=colorbar;
h.ax_PLV(3).Position=pos;
%% Source PLV Wave Axes
h.ax_sig_plv(1)=axes(h.tab_PLV,'Position',[h.tfr_xpos(1) h.sig_ypos h.sig_pos_size]); box on; title('Source 1 vs 2 Target Signal PLV Waves','Color',h.plv_clr(1,:));
h.ax_sig_plv(2)=axes(h.tab_PLV,'Position',[h.tfr_xpos(2) h.sig_ypos h.sig_pos_size]); box on; title('Source 1 vs 3 Target Signal PLV Waves','Color',h.plv_clr(2,:));
h.ax_sig_plv(3)=axes(h.tab_PLV,'Position',[h.tfr_xpos(3) h.sig_ypos h.sig_pos_size]); box on; title('Source 2 vs 3 Target Signal PLV Waves','Color',h.plv_clr(3,:));
h.ax_prepost_plv(1)=axes(h.tab_PLV,'Position',[h.tfr_xpos(1) h.prepost_ypos h.sig_pos_size]); box on; title('Source 1 vs 2 Target PrePost PLV Waves','Color',h.plv_clr(1,:));
h.ax_prepost_plv(2)=axes(h.tab_PLV,'Position',[h.tfr_xpos(2) h.prepost_ypos h.sig_pos_size]); box on; title('Source 1 vs 3 Target PrePost PLV Waves','Color',h.plv_clr(2,:));
h.ax_prepost_plv(3)=axes(h.tab_PLV,'Position',[h.tfr_xpos(3) h.prepost_ypos h.sig_pos_size]); box on; title('Source 2 vs 3 Target PrePost PLV Waves','Color',h.plv_clr(3,:));
for a=1:3; h.ax_PLV(a).Toolbar.Visible = 'off'; h.ax_sig_plv(a).Toolbar.Visible = 'off'; h.ax_prepost_plv(a).Toolbar.Visible = 'off'; end
%% Menu: ROI
h.menu_tfr_roi_idx_txt_PLV = uicontrol(h.tab_PLV,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.btn_ROI_source1.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .035 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','ROI #');
h.menu_tfr_roi_idx_PLV = uicontrol(h.tab_PLV,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_tfr_roi_idx_txt_PLV.Position([1 3]))+.005 .968 .065 .03],'FontSize',8,'HorizontalAlignment','center','String',{''},'Value',1,'Callback',{@set_current_ROI,1}); % menu listing TFR ROIs
%% Menu: Source #
h.menu_source_idx_txt_PLV = uicontrol(h.tab_PLV,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.menu_tfr_roi_idx_PLV.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .04 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Source');
h.menu_source_idx_PLV = uicontrol(h.tab_PLV,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_source_idx_txt_PLV.Position([1 3]))+.005 .968 .035 .03],'FontSize',8,'HorizontalAlignment','center','String',{'1' '2' '3'},'Value',1,'Callback',{@set_current_source,1}); % menu listing TFR ROIs
%% ROI limits
% Frequency
h.edit_tfr_roi_ylim_txt_PLV = uicontrol(h.tab_PLV,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.menu_source_idx_PLV.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .105 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Frequency Range');
h.edit_tfr_roi_ylim_PLV = uicontrol(h.tab_PLV,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_ylim_txt_PLV.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .05 .035],...
'Tag','PLV Frequency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
% Latency
h.edit_tfr_roi_xlim_txt_PLV = uicontrol(h.tab_PLV,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_ylim_PLV.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .095 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Latency Range');
h.edit_tfr_roi_xlim_PLV = uicontrol(h.tab_PLV,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_xlim_txt_PLV.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .075 .035],...
'Tag','PLV Latency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
% Rise Time
h.edit_tfr_roi_risetime_txt_PLV = uicontrol(h.tab_PLV,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_xlim_PLV.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .095 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Rise/Fall Time');
h.edit_tfr_roi_risetime_PLV = uicontrol(h.tab_PLV,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_risetime_txt_PLV.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .045 .035],...
'Tag','PLV Latency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
%% Edit Boxes
for v=1:3
%% Signal Phase-Locking Value
h.edit_sig_phase_locking_txt(v) = uicontrol(h.tab_PLV,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.plv_clr(v,:),'Units','normalize',...
'Position',[h.tfr_xpos(v) h.source_edit_ypos(1) .12 .0275],...
'FontSize',10,'HorizontalAlignment','left','String','Phase Locking: Signal ');
h.edit_sig_phase_locking(v) = uicontrol(h.tab_PLV,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.plv_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_sig_evoked_perc_txt(v).Position([1 3]))+.01 h.source_edit_ypos(1) h.source_edit_length h.source_edit_height],...
'Tag',[sig_tag{v} box_type{2}],'FontSize',10,'HorizontalAlignment','center','String','0.4','Callback',@set_tfr_roi_cfg);
%% PrePost Phase-Locking Value
h.edit_prepost_phase_locking_txt(v) = uicontrol(h.tab_PLV,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.plv_clr(v,:),'Units','normalize',...
'Position',[sum(h.edit_sig_evoked_perc(v).Position([1 3]))+.005 h.source_edit_ypos(1) .05 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Prepost');
h.edit_prepost_phase_locking(v) = uicontrol(h.tab_PLV,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.plv_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_prepost_evoked_perc_txt(v).Position([1 3]))+.005 h.source_edit_ypos(1) h.source_edit_length h.source_edit_height],...
'Tag',[prepost_tag{v} box_type{2}],'FontSize',10,'HorizontalAlignment','center','String','0.0','Callback',@set_tfr_roi_cfg);
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tab "Phase-Lag Index (PLI)" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%% SOURCE PLI Paramaters %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Signal Phase Lag
%% Menu: ROI
h.menu_tfr_roi_idx_txt_PLI = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.btn_ROI_source1.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .035 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','ROI #');
h.menu_tfr_roi_idx_PLI = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_tfr_roi_idx_txt_PLI.Position([1 3]))+.005 .968 .065 .03],'FontSize',8,'HorizontalAlignment','center','String',{''},'Value',1,'Callback',{@set_current_ROI,2}); % menu listing TFR ROIs
%% Menu: Source #
h.menu_source_idx_txt_PLI = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.menu_tfr_roi_idx_PLI.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .04 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Source');
h.menu_source_idx_PLI = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_source_idx_txt_PLI.Position([1 3]))+.005 .968 .035 .03],'FontSize',8,'HorizontalAlignment','center','String',{'1' '2' '3'},'Value',1,'Callback',{@set_current_source,2}); % menu listing TFR ROIs
%% Edit: ROI limits
% Frequency
h.edit_tfr_roi_ylim_txt_PLI = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.menu_source_idx_PLI.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .105 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Frequency Range');
h.edit_tfr_roi_ylim_PLI = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_ylim_txt_PLI.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .05 .035],...
'Tag','PLI Frequency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
% Latency
h.edit_tfr_roi_xlim_txt_PLI = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_ylim_PLI.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .095 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Latency Range');
h.edit_tfr_roi_xlim_PLI = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_xlim_txt_PLI.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .075 .035],...
'Tag','PLV Latency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
% Rise Time
h.edit_tfr_roi_risetime_txt_PLI = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_xlim_PLI.Position([1 3]))+.01 h.menu_sig_win_type_txt.Position(2) .095 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Rise/Fall Time');
h.edit_tfr_roi_risetime_PLI = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_tfr_roi_risetime_txt_PLI.Position([1 3]))+.005 h.menu_sig_win_type_txt.Position(2) .045 .035],...
'Tag','PLV Latency Range','FontSize',10,'HorizontalAlignment','center','String','0 0','Callback',@set_tfr_roi_cfg);
%% Edit Boxes
for v=1:3
h.edit_sig_phase_lag_txt(v) = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.plv_clr(v,:),'Units','normalize',...
'Position',[h.tfr_xpos(v) h.source_edit_ypos(1)-.025 .11 .05],...
'FontSize',10,'HorizontalAlignment','right','String','Phase Lag: Signal ');
h.edit_sig_phase_lag(v) = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.plv_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_sig_evoked_perc_txt(v).Position([1 3]))+.01 h.source_edit_ypos(1) h.source_edit_length h.source_edit_height],...
'Tag',[sig_tag{v} box_type{3}],'FontSize',10,'HorizontalAlignment','center','String','0.4','Callback',@set_tfr_roi_cfg);
%% PrePost Evoked Percent
h.edit_prepost_phase_lag_txt(v) = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.plv_clr(v,:),'Units','normalize',...
'Position',[sum(h.edit_sig_evoked_perc(v).Position([1 3]))+.005 h.source_edit_ypos(1) .05 .0275],...
'FontSize',10,'HorizontalAlignment','right','String','Prepost');
h.edit_prepost_phase_lag(v) = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.plv_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_prepost_evoked_perc_txt(v).Position([1 3]))+.005 h.source_edit_ypos(1) h.source_edit_length h.source_edit_height],...
'Tag',[prepost_tag{v} box_type{3}],'FontSize',10,'HorizontalAlignment','center','String','0.0','Callback',@set_tfr_roi_cfg);
%% Starting Phase relative to trial onset - determines the relative correlations among sources 1, 2, and 3
%% Signal Starting Phase
h.edit_sig_phase_start_txt(v) = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.plv_clr(v,:),'Units','normalize',...
'Position',[h.tfr_xpos(v) h.source_edit_ypos(2) .11 .0275],...
'FontSize',10,'HorizontalAlignment','left','String','Starting Phase (deg): Signal ');
h.edit_sig_phase_start(v) = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.plv_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum(h.edit_sig_phase_start_txt(v).Position([1 3]))+.005 h.source_edit_ypos(2) h.source_edit_length h.source_edit_height],'Tooltip',sprintf('inter-source correlation = cos( deg2rad (phase difference between sources) ) )'),...
'Tag',[sig_tag{v} box_type{2}],'FontSize',10,'HorizontalAlignment','center','String','0','Callback',@update_cfg);
%% PrePost Starting Phase
h.edit_prepost_phase_start_txt(v) = uicontrol(h.tab_PLI,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.plv_clr(v,:),'Units','normalize',...
'Position',[sum(h.edit_sig_phase_start(v).Position([1 3]))+.005 h.source_edit_ypos(2) .04 .0275],...
'FontSize',10,'HorizontalAlignment','left','String','Prepost');
h.edit_prepost_phase_start(v) = uicontrol(h.tab_PLI,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',h.plv_clr(v,:),'Style','edit','Units','normalize',...
'Position',[sum( h.edit_prepost_phase_start_txt(v).Position([1 3]))+.005 h.source_edit_ypos(2) h.source_edit_length h.source_edit_height],'Tooltip',sprintf('inter-source correlation = cos( deg2rad (phase difference between sources) ) )'),...
'Tag',[prepost_tag{v} box_type{2}],'FontSize',10,'HorizontalAlignment','center','String','0','Callback',@update_cfg);
end
%% Source 1 vs 2 PLI Axes
h.ax_PLI(1)=axes(h.tab_PLI,'Position',[h.tfr_xpos(1) h.tfr_ypos h.tfr_pos_size]);
h.pli_data.s1=surf(h.ax_PLI(1),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_PLI(1),0,90); shading(h.ax_PLI(1),'flat'); axis(h.ax_PLI(1),'tight'); axis(h.ax_PLI(1),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.pli_data.tfr_zero_line(1) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 1 vs 2 Target PLI','Color',h.plv_clr(1,:)); colormap(jet(255)); caxis(h.caxis_PLI);
% disableDefaultInteractivity(h.ax_PLI(1)); %h.pli_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
h.ax_PLI(1).YLabel.String='Frequency (Hz)';
%% Source 1 vs 3PLI Axes
h.ax_PLI(2)=axes(h.tab_PLI,'Position',[h.tfr_xpos(2) h.tfr_ypos h.tfr_pos_size]);
h.pli_data.s2=surf(h.ax_PLI(2),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_PLI(2),0,90); shading(h.ax_PLI(2),'flat'); axis(h.ax_PLI(2),'tight'); axis(h.ax_PLI(2),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.pli_data.tfr_zero_line(2) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 1 vs 3 Target PLI','Color',h.plv_clr(2,:)); colormap(jet(255)); caxis(h.caxis_PLI);
% disableDefaultInteractivity(h.ax_PLI(2)); %h.pli_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
%% Source 2 vs 3 PLI Axes
h.ax_PLI(3)=axes(h.tab_PLI,'Position',[h.tfr_xpos(3) h.tfr_ypos h.tfr_pos_size]);
h.pli_data.s3=surf(h.ax_PLI(3),h.cfg.study.lat_sim,h.freq_vals,zeros(length(h.freq_vals),length(h.cfg.study.lat_sim)));
view(h.ax_PLI(3),0,90); shading(h.ax_PLI(3),'flat'); axis(h.ax_PLI(3),'tight'); axis(h.ax_PLI(3),[h.cfg.study.plot_time_vals([1 end]) h.cfg.study.plot_freq_vals([1 end])]);
hold on; h.pli_data.tfr_zero_line(3) = plot([0 0],[h.cfg.study.plot_freq_int],'k--'); box on; title('Source 2 vs 3 PLI','Color',h.plv_clr(3,:)); colormap(jet(255)); caxis(h.caxis_PLI);
% disableDefaultInteractivity(h.ax_PLI(3)); %h.pli_data.s1.ButtonDownFcn=@bl_rbbox_gca_v2;
pos=h.ax_PLI(3).Position; cb=colorbar;
h.ax_PLI(3).Position=pos;
%% Source PLI Wave Axes
h.ax_sig_pli(1)=axes(h.tab_PLI,'Position',[h.tfr_xpos(1) h.sig_ypos h.sig_pos_size]); box on; title('Source 1 vs 2 Target Signal PLI Waves','Color',h.plv_clr(1,:));
h.ax_sig_pli(2)=axes(h.tab_PLI,'Position',[h.tfr_xpos(2) h.sig_ypos h.sig_pos_size]); box on; title('Source 1 vs 3 Target Signal PLI Waves','Color',h.plv_clr(2,:));
h.ax_sig_pli(3)=axes(h.tab_PLI,'Position',[h.tfr_xpos(3) h.sig_ypos h.sig_pos_size]); box on; title('Source 2 vs 3 Target Signal PLI Waves','Color',h.plv_clr(3,:));
h.ax_prepost_pli(1)=axes(h.tab_PLI,'Position',[h.tfr_xpos(1) h.prepost_ypos h.sig_pos_size]); box on; title('Source 1 vs 2 Target PrePost PLI Waves','Color',h.plv_clr(1,:));
h.ax_prepost_pli(2)=axes(h.tab_PLI,'Position',[h.tfr_xpos(2) h.prepost_ypos h.sig_pos_size]); box on; title('Source 1 vs 3 Target PrePost PLI Waves','Color',h.plv_clr(2,:));
h.ax_prepost_pli(3)=axes(h.tab_PLI,'Position',[h.tfr_xpos(3) h.prepost_ypos h.sig_pos_size]); box on; title('Source 2 vs 3 Target PrePost PLI Waves','Color',h.plv_clr(3,:));
for a=1:3; h.ax_PLI(a).Toolbar.Visible = 'off'; h.ax_sig_pli(a).Toolbar.Visible = 'off'; h.ax_prepost_pli(a).Toolbar.Visible = 'off'; end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tab "Phase-Amplitude Coupling (PAC)" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%% Panel "Phase-Amplitude Coupling (PAC) Parameters" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% delete(h.panel_PAC_params)
h.panel_PAC_params = uipanel(h.tab_PAC,'Title','Phase-Amplitude Coupling (PAC) Parameters','FontSize',10,'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',[0 0 0],...
'Units','normalize','Position',[.01 .64 .98 .355],'Visible','on');
% index (1) = Source 1 v Source 2; (2)=[1 3]; (2)=[2 1]; (2)=[2 3]; (2)=[3 ]; (2)=[3 2];
%% Button Update PAC waves
% delete(h.btn_update_PAC_waves)
h.btn_update_PAC_waves = uicontrol(h.panel_PAC_params,'BackgroundColor',[1 1 1]*.9,'ForegroundColor',h.src_clr(1,:),'Style','pushbutton','Units','normalize',...
'Position',[.87 .91 .12 .085],'Visible','on','UserData',1,...
'FontSize',10,'HorizontalAlignment','center','String','Update PAC Waves','Callback',{@btn_update_PAC_waves,0});
%% Menu & Text for Source contrasts for PAC parameters
h.PAC_source_contrasts = [1 2; 1 3; 2 1; 2 3; 3 1; 3 2];
xsize = .055; xpos = [];
ysize = .075; ypos = .8-[ysize:ysize+.05:.95];
xsize_edit = .075;
for a=1:6
%% Signal PAC
% text for Carrier Source
h.menu_PAC_sig_carrier_source_txt(a) = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,1),:),...
'Units','normalize','Position',[.01 ypos(a) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String',sprintf('Source %.f',h.PAC_source_contrasts(a,1)));
% Menu for Carrier Source Frequency
h.menu_PAC_sig_carrier_source_freq(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_PAC_sig_carrier_source_txt(a).Position([1 3]))+.0025 h.menu_PAC_sig_carrier_source_txt(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,1),:),'HorizontalAlignment','center','String',{''},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
% text for Modulator Source
h.menu_PAC_sig_modulator_source_txt(a) = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),...
'Units','normalize','Position',[sum(h.menu_PAC_sig_carrier_source_freq(a).Position([1 3]))+.01 h.menu_PAC_sig_carrier_source_freq(a).Position(2) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String',sprintf('Source %.f',h.PAC_source_contrasts(a,2)));
% Menu for Modulator Source Frequency
h.menu_PAC_sig_modulator_source_freq(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_PAC_sig_modulator_source_txt(a).Position([1 3]))+.0025 h.menu_PAC_sig_modulator_source_txt(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),'HorizontalAlignment','center','String',{''},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
% Signal Depth of modulator
h.edit_PAC_modulator_sig_depth(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.menu_PAC_sig_modulator_source_freq(1).Position([1 3]))+.02 h.menu_PAC_sig_modulator_source_freq(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),'HorizontalAlignment','center','String',{'0'},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
h.edit_PAC_modulator_sig_depth_range(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_PAC_modulator_sig_depth(a).Position([1 3]))+.02 h.edit_PAC_modulator_sig_depth(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),'HorizontalAlignment','center','String',{'0'},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
%% Prepost PAC
% text for Carrier Source
h.menu_PAC_prepost_carrier_source_txt(a) = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,1),:),...
'Units','normalize','Position',[sum(h.edit_PAC_modulator_sig_depth_range(a).Position([1 3]))+.05 ypos(a) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String',sprintf('Source %.f',h.PAC_source_contrasts(a,1)));
% Menu for Carrier Source Frequency
h.menu_PAC_prepost_carrier_source_freq(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_PAC_prepost_carrier_source_txt(a).Position([1 3]))+.0025 h.menu_PAC_prepost_carrier_source_txt(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,1),:),'HorizontalAlignment','center','String',{''},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
% text for Modulator Source
h.menu_PAC_prepost_modulator_source_txt(a) = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),...
'Units','normalize','Position',[sum(h.menu_PAC_prepost_carrier_source_freq(a).Position([1 3]))+.01 h.menu_PAC_prepost_carrier_source_freq(a).Position(2) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String',sprintf('Source %.f',h.PAC_source_contrasts(a,2)));
% Menu for Modulator Source Frequency
h.menu_PAC_prepost_modulator_source_freq(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_PAC_prepost_modulator_source_txt(a).Position([1 3]))+.0025 h.menu_PAC_prepost_modulator_source_txt(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),'HorizontalAlignment','center','String',{''},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
% Prepost Depth of modulator
h.edit_PAC_modulator_prepost_depth(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.menu_PAC_prepost_modulator_source_freq(a).Position([1 3]))+.02 h.menu_PAC_prepost_modulator_source_freq(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),'HorizontalAlignment','center','String',{'0'},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
h.edit_PAC_modulator_prepost_depth_range(a) = uicontrol(h.panel_PAC_params,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','edit','Units','normalize',...
'Position',[sum(h.edit_PAC_modulator_prepost_depth(a).Position([1 3]))+.02 h.edit_PAC_modulator_prepost_depth(a).Position(2) xsize_edit ysize],'FontSize',8,...
'Foregroundcolor',h.src_clr(h.PAC_source_contrasts(a,2),:),'HorizontalAlignment','center','String',{'0'},'Value',1,'Callback',{@update_PAC,0}); % menu listing PAC carrier frequencies
end
%% Text along top
%% Signal heading texts
% text for Signal Carrier and Modulator
h.PAC_sig_carrier_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_sig_carrier_source_txt(1).Position(1) .82 xsize ysize*2],...
'FontSize',10,'HorizontalAlignment','left','String','Signal Carrier');
h.PAC_sig_modulator_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_sig_modulator_source_txt(1).Position(1) h.PAC_sig_carrier_txt.Position(2) xsize ysize*2],...
'FontSize',10,'HorizontalAlignment','left','String','Signal Modulator');
% text "Frequency" for Signal Carrier and Modulator
h.PAC_sig_carrier_freq_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_sig_carrier_source_freq(1).Position(1) h.PAC_sig_carrier_txt.Position(2) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Frequency');
h.PAC_sig_modulator_freq_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_sig_modulator_source_freq(1).Position(1) h.PAC_sig_carrier_txt.Position(2) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Frequency');
% Text for Depth & Range
h.PAC_sig_depth_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.edit_PAC_modulator_sig_depth(1).Position(1) h.PAC_sig_carrier_txt.Position(2) .1 ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Modulator Depth');
h.PAC_sig_range_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.edit_PAC_modulator_sig_depth_range(1).Position(1) h.PAC_sig_carrier_txt.Position(2) h.PAC_sig_depth_txt.Position(3) ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Depth Range');
%% Prepost heading texts
% text for Signal Carrier and Modulator
h.PAC_prepost_carrier_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_prepost_carrier_source_txt(1).Position(1) h.PAC_sig_carrier_txt.Position(2) xsize ysize*2],...
'FontSize',10,'HorizontalAlignment','left','String','PrePost Carrier');
h.PAC_prepost_modulator_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_prepost_modulator_source_txt(1).Position(1) h.PAC_sig_carrier_txt.Position(2) xsize ysize*2],...
'FontSize',10,'HorizontalAlignment','left','String','PrePost Modulator');
h.PAC_prepost_depth_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.edit_PAC_modulator_prepost_depth(1).Position(1) h.PAC_sig_carrier_txt.Position(2) .1 ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Prepost Depth');
h.PAC_prepost_range_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.edit_PAC_modulator_prepost_depth_range(1).Position(1) h.PAC_sig_carrier_txt.Position(2) h.PAC_prepost_depth_txt.Position(3) ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Depth Range');
% text "Frequency" for Signal Carrier and Modulator
h.PAC_prepost_carrier_freq_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_prepost_carrier_source_freq(1).Position(1) h.PAC_sig_carrier_txt.Position(2) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Frequency');
h.PAC_prepost_modulator_freq_txt = uicontrol(h.panel_PAC_params,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.menu_PAC_prepost_modulator_source_freq(1).Position(1) h.PAC_prepost_carrier_txt.Position(2) xsize ysize],...
'FontSize',10,'HorizontalAlignment','left','String','Frequency');
%% %%%% Panel "Target PAC Waves" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% delete(h.panel_PAC_waves)
h.panel_PAC_waves = uipanel(h.tab_PAC,'Title','Target PAC waves','FontSize',10,'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',[0 0 0],...
'Units','normalize','Position',[.01 .01 .98 .63],'Visible','on');
%% Axes PAC waves
% delete(h.axes_PAC_waves_sig); delete(h.axes_PAC_waves_prepost)
xsize = .22; ysize = .25;
xpos1 = [.02 .27 .02 .27 .02 .27];
xpos2 = [.02 .27 .02 .27 .02 .27]+.5;
ypos = [.7 .7 .375 .375 .05 .05];
for a=1:6
h.axes_PAC_waves_sig(a)=axes(h.panel_PAC_waves,'Position',[xpos1(a) ypos(a) xsize ysize]); box on; title(sprintf('Signal PAC: Source %.f mod by %.f ',h.PAC_source_contrasts(a,:)));
h.axes_PAC_waves_prepost(a)=axes(h.panel_PAC_waves,'Position',[xpos2(a) ypos(a) xsize ysize]); box on; title(sprintf('PrePost PAC: Source %.f mod by %.f ',h.PAC_source_contrasts(a,:)));
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Tab "Simulate M/EEG" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%% Panel "Forward Model: Anatomy & Source Locations" on Tab "Simulate M/EEG" %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h.panel_anatomy = uipanel(h.tab_sim_meeg,'Title','Forward Model: Anatomy & Source Locations','FontSize',10,'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor',[0 0 0],...
'Units','normalize','Position',[.01 .01 .49 .98],'Visible','on');
%% Load SimMEEG Anatomy.mat - must specific struct (see SimMEEG.m program for details)
h.btn_load_default_anatomy = uicontrol(h.panel_anatomy,'BackgroundColor',[.2 .2 1]*1,'ForegroundColor',[1 1 1]*1,'Style','pushbutton','Units','normalize',...
'Position',[.01 .96 .225 .035],...
'FontSize',10,'HorizontalAlignment','center','String','SimMEEG Anatomy','Callback',@load_default_anatomy);
%% Load Brainstorm Anatomy from subj anat directory
h.btn_load_bst_anatomy = uicontrol(h.panel_anatomy,'BackgroundColor',[1 1 1]*.4,'ForegroundColor',[1 1 1]*1,'Style','pushbutton','Units','normalize',...
'Position',[sum(h.btn_load_default_anatomy.Position([1 3]))+.01 .96 .25 .035],...
'FontSize',10,'HorizontalAlignment','center','String','BrainStorm Anatomy','Callback',@load_bst_anatomy);
%% Load FieldTrip Anatomy.mat - must have mri, sens_eeg, sens_MEG, etc. saved inside the *.mat file
h.btn_load_ft_anatomy = uicontrol(h.panel_anatomy,'BackgroundColor',[.1 .6 .1]*1,'ForegroundColor',[1 1 1]*1,'Style','pushbutton','Units','normalize',...
'Position',[sum(h.btn_load_bst_anatomy.Position([1 3]))+.01 .96 .25 .035],...
'FontSize',10,'HorizontalAlignment','center','String','FieldTrip Anatomy','Callback',@sm_load_FieldTrip_Anatomy);
%% New Anatomy by clearing h.anatomy
h.btn_clear_SimMEEG_anatomy = uicontrol(h.panel_anatomy,'BackgroundColor',[1 .9 .8],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[sum(h.btn_load_ft_anatomy.Position([1 3]))+.05 .96 .185 .035],...
'FontSize',10,'HorizontalAlignment','center','String','Clear Anatomy','Callback',@sm_clear_SimMEEG_Anatomy);
%% Save FieldTrip Anatomy.mat - must have mri, sens_eeg, sens_MEG, etc. saved inside the *.mat file
h.btn_save_SimMEEG_anatomy = uicontrol(h.panel_anatomy,'BackgroundColor',[.8 .9 1],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[sum(h.btn_load_ft_anatomy.Position([1 3]))+.05 h.btn_clear_SimMEEG_anatomy.Position(2)-.04 .185 .035],...
'FontSize',10,'HorizontalAlignment','center','String','Save Anatomy','Callback',@sm_save_SimMEEG_Anatomy);
%% Anatomy File Name
h.mri_path_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[.01 .925 .2 .03],'FontSize',10,'HorizontalAlignment','right','String','Anatomy Folder:');
h.mri_path = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[.22 h.mri_path_txt.Position(2) .8-sum(h.btn_load_default_anatomy.Position([1 3]))+.01 .03],'FontSize',10,'HorizontalAlignment','left','String','Anatomy Folder');
h.mri_file_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[.01 h.mri_path_txt.Position(2)-.0325 .2 .03],'FontSize',10,'HorizontalAlignment','right','String','Anatomy File:');
h.anatomy_file_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[.22 h.mri_file_txt.Position(2) .8-sum(h.btn_load_default_anatomy.Position([1 3]))+.01 .03],...
'FontSize',10,'HorizontalAlignment','left','String','Default MRI','Callback',@set_anat_file);
%% Load MRI - created in Field Trip format
h.btn_load_anatomy = uicontrol(h.panel_anatomy,'BackgroundColor',[1 .7 .7],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.01 h.anatomy_file_txt.Position(2)-.035 .2 .03],...
'FontSize',10,'HorizontalAlignment','center','String','Load MRI','Callback',@sm_load_mri);
h.mri_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.btn_load_anatomy.Position([1 3]))+.01 h.btn_load_anatomy.Position(2) .8-sum(h.btn_load_anatomy.Position([1 3]))+.01 .03],...
'FontSize',10,'HorizontalAlignment','left','String','MRI Info:____________________________________');
%% Load Sensors - created in Field Trip format
h.btn_load_sensors = uicontrol(h.panel_anatomy,'BackgroundColor',[1 .8 .4],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.01 h.btn_load_anatomy.Position(2)-.035 .1 .03],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','Load Sensors','Callback',@sm_load_sensors);
h.btn_change_sensors = uicontrol(h.panel_anatomy,'BackgroundColor',[1 .8 .4],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[sum(h.btn_load_sensors.Position([1 3]))+.01 h.btn_load_anatomy.Position(2)-.035 .09 .03],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','Locations','Callback',{@sm_change_sensors,'on'});
h.sensors_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[h.mri_txt.Position(1) h.btn_load_sensors.Position(2) .8-sum(h.btn_load_sensors.Position([1 3]))+.01 .03],...
'FontSize',10,'HorizontalAlignment','left','String','Sensor Info:____________________________________');
h.menu_sens_type = uicontrol(h.panel_anatomy,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[1-.21 h.sensors_txt.Position(2)+.01 .08 .025],...
'FontSize',8,'HorizontalAlignment','center','String',{'MEG' 'EEG'},'Value',1,'Callback',@menu_head_model_CallBack);
h.menu_sens_montage = uicontrol(h.panel_anatomy,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...
'Position',[sum(h.menu_sens_type.Position([1 3]))+.01 h.menu_sens_type.Position(2) .08 .025],...
'FontSize',8,'HorizontalAlignment','center','String',{'151'},'Value',1,'Callback',@menu_sens_montage_CallBack);
%% Load HeadModel - created in Field Trip format
h.btn_load_headmodel = uicontrol(h.panel_anatomy,'BackgroundColor',[.8 1 .8],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.01 h.btn_load_sensors.Position(2)-.035 .2 .03],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','Create HeadModel','Callback',@sm_create_headmodel);
h.headmodel_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.btn_load_headmodel.Position([1 3]))+.01 h.btn_load_headmodel.Position(2) .8-sum(h.btn_load_headmodel.Position([1 3]))+.01 .03],...
'FontSize',10,'HorizontalAlignment','left','String','Head Model Info:________________________________');
%% Load Lead Field - created in Field Trip format
h.btn_load_leadfield = uicontrol(h.panel_anatomy,'BackgroundColor',[.8 .8 1],'ForegroundColor',[1 1 1]*0,'Style','pushbutton','Units','normalize',...
'Position',[.01 h.btn_load_headmodel.Position(2)-.035 .2 .03],'Visible','on',...
'FontSize',10,'HorizontalAlignment','center','String','Create LeadField','Callback',@sm_create_leadfield);
h.leadfield_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
'Position',[sum(h.btn_load_leadfield.Position([1 3]))+.01 h.btn_load_leadfield.Position(2) .8-sum(h.btn_load_leadfield.Position([1 3]))+.01 .03],...
'FontSize',10,'HorizontalAlignment','left','String','Lead Field Info:_________________________________');
%% Menu Head Model - Whole Head or Cortical Surface
% h.menu_head_model_txt = uicontrol(h.panel_anatomy,'Style','text', 'BackgroundColor',h.UserData.bkg_clr,'Foregroundcolor','k','Units','normalize',...
% 'Position',[1-.38 h.btn_load_leadfield.Position(2)-.035 .16 .02],...
% 'FontSize',10,'HorizontalAlignment','left','String','Head Model');
h.menu_head_model = uicontrol(h.panel_anatomy,'BackgroundColor',h.UserData.bkg_clr,'ForegroundColor',[1 1 1]*0,'Style','popupmenu','Units','normalize',...