-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAGA_GUI.m
More file actions
3275 lines (2889 loc) · 169 KB
/
SAGA_GUI.m
File metadata and controls
3275 lines (2889 loc) · 169 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
classdef SAGA_GUI < matlab.apps.AppBase
% Properties that correspond to app components
properties (Access = public)
SAGADataViewerUIFigure matlab.ui.Figure
TriggerChannelEditField matlab.ui.control.NumericEditField
TriggerChannelEditFieldLabel matlab.ui.control.Label
TriggerSyncBitEditField matlab.ui.control.NumericEditField
TriggerSyncBitEditFieldLabel matlab.ui.control.Label
DateTimeLabel matlab.ui.control.Label
SAGALabel matlab.ui.control.Label
TabGroup matlab.ui.container.TabGroup
UnipolarStreamTab matlab.ui.container.Tab
UnipolarStreamGridLayout matlab.ui.container.GridLayout
UnipolarStreamSettingsPanel matlab.ui.container.Panel
UnipolarCARCheckBox matlab.ui.control.CheckBox
UnipolarCutoff2EditField matlab.ui.control.NumericEditField
Cutoff2HzEditFieldLabel matlab.ui.control.Label
UnipolarCutoff1EditField matlab.ui.control.NumericEditField
Cutoff1HzEditFieldLabel matlab.ui.control.Label
UnipolarFilterCheckBox matlab.ui.control.CheckBox
UnipolarPerChannelOffsetEditField matlab.ui.control.NumericEditField
PerChannelOffsetVEditFieldLabel matlab.ui.control.Label
ToggleAllUnipolarChannelsSwitch matlab.ui.control.ToggleSwitch
AllChannelsSwitchLabel matlab.ui.control.Label
UnipolarStreamChannelsPanel matlab.ui.container.Panel
UNI64SwitchLabel matlab.ui.control.Label
UNI64Switch matlab.ui.control.Switch
UNI63SwitchLabel matlab.ui.control.Label
UNI63Switch matlab.ui.control.Switch
UNI62SwitchLabel matlab.ui.control.Label
UNI62Switch matlab.ui.control.Switch
UNI61SwitchLabel matlab.ui.control.Label
UNI61Switch matlab.ui.control.Switch
UNI60SwitchLabel matlab.ui.control.Label
UNI60Switch matlab.ui.control.Switch
UNI59SwitchLabel matlab.ui.control.Label
UNI59Switch matlab.ui.control.Switch
UNI58SwitchLabel matlab.ui.control.Label
UNI58Switch matlab.ui.control.Switch
UNI57SwitchLabel matlab.ui.control.Label
UNI57Switch matlab.ui.control.Switch
UNI56SwitchLabel matlab.ui.control.Label
UNI56Switch matlab.ui.control.Switch
UNI55SwitchLabel matlab.ui.control.Label
UNI55Switch matlab.ui.control.Switch
UNI54SwitchLabel matlab.ui.control.Label
UNI54Switch matlab.ui.control.Switch
UNI53SwitchLabel matlab.ui.control.Label
UNI53Switch matlab.ui.control.Switch
UNI52SwitchLabel matlab.ui.control.Label
UNI52Switch matlab.ui.control.Switch
UNI51SwitchLabel matlab.ui.control.Label
UNI51Switch matlab.ui.control.Switch
UNI50SwitchLabel matlab.ui.control.Label
UNI50Switch matlab.ui.control.Switch
UNI49SwitchLabel matlab.ui.control.Label
UNI49Switch matlab.ui.control.Switch
UNI48SwitchLabel matlab.ui.control.Label
UNI48Switch matlab.ui.control.Switch
UNI47SwitchLabel matlab.ui.control.Label
UNI47Switch matlab.ui.control.Switch
UNI46SwitchLabel matlab.ui.control.Label
UNI46Switch matlab.ui.control.Switch
UNI45SwitchLabel matlab.ui.control.Label
UNI45Switch matlab.ui.control.Switch
UNI44SwitchLabel matlab.ui.control.Label
UNI44Switch matlab.ui.control.Switch
UNI43SwitchLabel matlab.ui.control.Label
UNI43Switch matlab.ui.control.Switch
UNI42SwitchLabel matlab.ui.control.Label
UNI42Switch matlab.ui.control.Switch
UNI41SwitchLabel matlab.ui.control.Label
UNI41Switch matlab.ui.control.Switch
UNI40SwitchLabel matlab.ui.control.Label
UNI40Switch matlab.ui.control.Switch
UNI39SwitchLabel matlab.ui.control.Label
UNI39Switch matlab.ui.control.Switch
UNI38SwitchLabel matlab.ui.control.Label
UNI38Switch matlab.ui.control.Switch
UNI37SwitchLabel matlab.ui.control.Label
UNI37Switch matlab.ui.control.Switch
UNI36SwitchLabel matlab.ui.control.Label
UNI36Switch matlab.ui.control.Switch
UNI35SwitchLabel matlab.ui.control.Label
UNI35Switch matlab.ui.control.Switch
UNI34SwitchLabel matlab.ui.control.Label
UNI34Switch matlab.ui.control.Switch
UNI33SwitchLabel matlab.ui.control.Label
UNI33Switch matlab.ui.control.Switch
UNI32SwitchLabel matlab.ui.control.Label
UNI32Switch matlab.ui.control.Switch
UNI31SwitchLabel matlab.ui.control.Label
UNI31Switch matlab.ui.control.Switch
UNI30SwitchLabel matlab.ui.control.Label
UNI30Switch matlab.ui.control.Switch
UNI29SwitchLabel matlab.ui.control.Label
UNI29Switch matlab.ui.control.Switch
UNI28SwitchLabel matlab.ui.control.Label
UNI28Switch matlab.ui.control.Switch
UNI27SwitchLabel matlab.ui.control.Label
UNI27Switch matlab.ui.control.Switch
UNI26SwitchLabel matlab.ui.control.Label
UNI26Switch matlab.ui.control.Switch
UNI25SwitchLabel matlab.ui.control.Label
UNI25Switch matlab.ui.control.Switch
UNI24SwitchLabel matlab.ui.control.Label
UNI24Switch matlab.ui.control.Switch
UNI23SwitchLabel matlab.ui.control.Label
UNI23Switch matlab.ui.control.Switch
UNI22SwitchLabel matlab.ui.control.Label
UNI22Switch matlab.ui.control.Switch
UNI21SwitchLabel matlab.ui.control.Label
UNI21Switch matlab.ui.control.Switch
UNI20SwitchLabel matlab.ui.control.Label
UNI20Switch matlab.ui.control.Switch
UNI19SwitchLabel matlab.ui.control.Label
UNI19Switch matlab.ui.control.Switch
UNI18SwitchLabel matlab.ui.control.Label
UNI18Switch matlab.ui.control.Switch
UNI17SwitchLabel matlab.ui.control.Label
UNI17Switch matlab.ui.control.Switch
UNI16SwitchLabel matlab.ui.control.Label
UNI16Switch matlab.ui.control.Switch
UNI15SwitchLabel matlab.ui.control.Label
UNI15Switch matlab.ui.control.Switch
UNI14SwitchLabel matlab.ui.control.Label
UNI14Switch matlab.ui.control.Switch
UNI13SwitchLabel matlab.ui.control.Label
UNI13Switch matlab.ui.control.Switch
UNI12SwitchLabel matlab.ui.control.Label
UNI12Switch matlab.ui.control.Switch
UNI11SwitchLabel matlab.ui.control.Label
UNI11Switch matlab.ui.control.Switch
UNI10SwitchLabel matlab.ui.control.Label
UNI10Switch matlab.ui.control.Switch
UNI09SwitchLabel matlab.ui.control.Label
UNI09Switch matlab.ui.control.Switch
UNI08SwitchLabel matlab.ui.control.Label
UNI08Switch matlab.ui.control.Switch
UNI07SwitchLabel matlab.ui.control.Label
UNI07Switch matlab.ui.control.Switch
UNI06SwitchLabel matlab.ui.control.Label
UNI06Switch matlab.ui.control.Switch
UNI05SwitchLabel matlab.ui.control.Label
UNI05Switch matlab.ui.control.Switch
UNI04SwitchLabel matlab.ui.control.Label
UNI04Switch matlab.ui.control.Switch
UNI03SwitchLabel matlab.ui.control.Label
UNI03Switch matlab.ui.control.Switch
UNI02SwitchLabel matlab.ui.control.Label
UNI02Switch matlab.ui.control.Switch
UNI01Switch matlab.ui.control.Switch
UNI01SwitchLabel matlab.ui.control.Label
UnipolarUIAxes matlab.ui.control.UIAxes
UnipolarAverageTab matlab.ui.container.Tab
UnipolarAverageGridLayout matlab.ui.container.GridLayout
UnipolarAverageSettingsPanel matlab.ui.container.Panel
UnipolarAverageRectifyCheckBox matlab.ui.control.CheckBox
ResetUnipolarAverageButton matlab.ui.control.Button
UnipolarAverageNEditField matlab.ui.control.NumericEditField
NEditFieldLabel matlab.ui.control.Label
StopUnipolarAverageSpinner matlab.ui.control.Spinner
StopDatamsSpinnerLabel matlab.ui.control.Label
StartUnipolarAverageSpinner matlab.ui.control.Spinner
StartDatamsSpinnerLabel matlab.ui.control.Label
UnipolarAverageCARCheckBox matlab.ui.control.CheckBox
UnipolarAverageCutoff2EditField matlab.ui.control.NumericEditField
Cutoff2HzEditFieldLabel_2 matlab.ui.control.Label
UnipolarAverageCutoff1EditField matlab.ui.control.NumericEditField
Cutoff1HzEditFieldLabel_2 matlab.ui.control.Label
UnipolarAverageFilterCheckBox matlab.ui.control.CheckBox
UnipolarAverageChannelEditField matlab.ui.control.NumericEditField
UNIChannelEditFieldLabel matlab.ui.control.Label
UnipolarAverageUIAxes matlab.ui.control.UIAxes
UnipolarRasterTab matlab.ui.container.Tab
UnipolarRasterGridLayout matlab.ui.container.GridLayout
UnipolarRasterSettingsPanel matlab.ui.container.Panel
BipolarStreamTab matlab.ui.container.Tab
BipolarStreamGridLayout matlab.ui.container.GridLayout
BipolarStreamSettingsPanel matlab.ui.container.Panel
BipolarCutoff2EditField matlab.ui.control.NumericEditField
BipolarCutoff2EditFieldLabel matlab.ui.control.Label
BipolarCutoff1EditField matlab.ui.control.NumericEditField
BipolarCutoff1EditFieldLabel matlab.ui.control.Label
BipolarPerChannelOffsetEditField matlab.ui.control.NumericEditField
BipolarPerChannelOffsetVEditFieldLabel matlab.ui.control.Label
BipolarFilterCheckBox matlab.ui.control.CheckBox
ToggleAllBipolarChannelsSwitch matlab.ui.control.ToggleSwitch
ToggleAllBipolarChannelsSwitchLabel matlab.ui.control.Label
BipolarStreamChannelsPanel matlab.ui.container.Panel
BIP04SwitchLabel matlab.ui.control.Label
BIP04Switch matlab.ui.control.Switch
BIP03SwitchLabel matlab.ui.control.Label
BIP03Switch matlab.ui.control.Switch
BIP02SwitchLabel matlab.ui.control.Label
BIP02Switch matlab.ui.control.Switch
BIP01Switch matlab.ui.control.Switch
BIP01SwitchLabel matlab.ui.control.Label
BipolarUIAxes matlab.ui.control.UIAxes
BipolarAverageTab matlab.ui.container.Tab
BipolarAverageGridLayout matlab.ui.container.GridLayout
BipolarAverageSettingsPanel matlab.ui.container.Panel
BipolarAverageRectifyCheckBox matlab.ui.control.CheckBox
BipolarAverageNEditField matlab.ui.control.NumericEditField
NEditFieldLabel_2 matlab.ui.control.Label
ResetBipolarAverageButton matlab.ui.control.Button
StopBipolarAverageSpinner matlab.ui.control.Spinner
StopDatamsSpinner_2Label matlab.ui.control.Label
StartBipolarAverageSpinner matlab.ui.control.Spinner
StartDatamsSpinner_2Label matlab.ui.control.Label
BipolarAverageCutoff2EditField matlab.ui.control.NumericEditField
Cutoff2HzEditFieldLabel_3 matlab.ui.control.Label
BipolarAverageCutoff1EditField matlab.ui.control.NumericEditField
Cutoff1HzEditFieldLabel_3 matlab.ui.control.Label
BipolarAverageChannelEditField matlab.ui.control.NumericEditField
BIPChannelLabel matlab.ui.control.Label
BipolarAverageFilterCheckBox matlab.ui.control.CheckBox
BipolarAverageUIAxes matlab.ui.control.UIAxes
RMSContourTab matlab.ui.container.Tab
RMSContourGridLayout matlab.ui.container.GridLayout
RMSContourSettingsPanel matlab.ui.container.Panel
ICAStreamTab matlab.ui.container.Tab
ICAStreamGridLayout matlab.ui.container.GridLayout
ICAStreamChannelsPanel matlab.ui.container.Panel
ToggleAllICAChannelsSwitch matlab.ui.control.ToggleSwitch
ToggleAllBipolarChannelsSwitchLabel_2 matlab.ui.control.Label
ICA20SwitchLabel matlab.ui.control.Label
ICA20Switch matlab.ui.control.Switch
ICA19SwitchLabel matlab.ui.control.Label
ICA19Switch matlab.ui.control.Switch
ICA18SwitchLabel matlab.ui.control.Label
ICA18Switch matlab.ui.control.Switch
ICA17Switch matlab.ui.control.Switch
ICA17SwitchLabel matlab.ui.control.Label
ICA16SwitchLabel matlab.ui.control.Label
ICA16Switch matlab.ui.control.Switch
ICA15SwitchLabel matlab.ui.control.Label
ICA15Switch matlab.ui.control.Switch
ICA14SwitchLabel matlab.ui.control.Label
ICA14Switch matlab.ui.control.Switch
ICA13Switch matlab.ui.control.Switch
ICA13SwitchLabel matlab.ui.control.Label
ICA12SwitchLabel matlab.ui.control.Label
ICA12Switch matlab.ui.control.Switch
ICA11SwitchLabel matlab.ui.control.Label
ICA11Switch matlab.ui.control.Switch
ICA10SwitchLabel matlab.ui.control.Label
ICA10Switch matlab.ui.control.Switch
ICA09Switch matlab.ui.control.Switch
ICA09SwitchLabel matlab.ui.control.Label
ICA08SwitchLabel matlab.ui.control.Label
ICA08Switch matlab.ui.control.Switch
ICA07SwitchLabel matlab.ui.control.Label
ICA07Switch matlab.ui.control.Switch
ICA06SwitchLabel matlab.ui.control.Label
ICA06Switch matlab.ui.control.Switch
ICA05Switch matlab.ui.control.Switch
ICA05SwitchLabel matlab.ui.control.Label
ICA04SwitchLabel matlab.ui.control.Label
ICA04Switch matlab.ui.control.Switch
ICA03SwitchLabel matlab.ui.control.Label
ICA03Switch matlab.ui.control.Switch
ICA02SwitchLabel matlab.ui.control.Label
ICA02Switch matlab.ui.control.Switch
ICA01Switch matlab.ui.control.Switch
ICA01SwitchLabel matlab.ui.control.Label
ICAUIAxes matlab.ui.control.UIAxes
ICARasterTab matlab.ui.container.Tab
ICARasterGridLayout matlab.ui.container.GridLayout
ICARasterSettingsPanel matlab.ui.container.Panel
ConfigTab matlab.ui.container.Tab
ConfigGridLayout matlab.ui.container.GridLayout
ResponsesStopEditField matlab.ui.control.NumericEditField
ResponsesStopEditFIeldLabel matlab.ui.control.Label
ResponsesStartEditField matlab.ui.control.NumericEditField
ResponsesStartEditFieldLabel matlab.ui.control.Label
ResponsesConnectionStatusLamp matlab.ui.control.Lamp
ResponsesConnectionStatusLampLabel matlab.ui.control.Label
ResponsesConnectButton matlab.ui.control.Button
ResponsesPortEditField matlab.ui.control.NumericEditField
ResponsesPortEditFieldLabel matlab.ui.control.Label
ResponsesIPEditField matlab.ui.control.EditField
ResponsesIPAddressEditFieldLabel matlab.ui.control.Label
end
properties (Access = public)
data
end
properties (Hidden, Access = public)
CDATA
end
properties (GetAccess = public, SetAccess = protected)
tag % Either "A" or "B"
cfg % Parsed configuration struct
connected = struct('parameters', false, 'data', false, 'responses', false); % True if the parameters server (from controller UI) is connected
mode (1,1) enum.TMSiPacketMode = enum.TMSiPacketMode.StreamMode % Current "mode" based on selected visualizer tab
plot_fcn % Callback to use in handling data
filters % Filter coefficients and parameters
H % Struct containing the different graphic objects to update
response_data = cell(68, 1); % Store RMS ratio data for all the (enabled) data channels
n = struct
end
properties (Hidden, Constant)
ICA_OFFSET = 3.5
end
properties (Access = private)
in_configuration_mode_ (1,1) logical = false;
n_new_ (1,1) double = 0;
data_running_ (1,1) logical = false;
data_state_ (1,1) enum.TMSiState = enum.TMSiState.IDLE;
rclient_ % Responses client (secondary visualizer for online stim control/interaction)
udp_receiver_ % UDP port that receives the data streams
end
methods (Access = public)
function handle_udp_data_byte_stream_mode(app, src, ~)
%HANDLE_UDP_DATA_BYTE_STREAM_MODE Default stream mode, this is a callback for the udp_receiver_ that parses byte frames
N = app.n.all_samples;
tab = app.TabGroup.SelectedTab.tag;
switch app.mode
case enum.TMSiPacketMode.StreamMode % Default
b = src.read(N+2, "double");
x = b(end);
if x == 65535
ch = b(1);
y = b(2:(end-1));
switch upper(char(tab))
case 'US'
if (ch < 65) || (ch == 100)
app.update_unipolar_stream_data(ch, y);
else
yf = app.filter_bipolar_data_(ch, y);
snippets = app.parse_snippets_(yf);
app.parse_response_data(ch, snippets);
end
case 'UA'
if (ch < 65) || (ch == 100)
app.update_unipolar_average_data(ch, y);
else
yf = app.filter_bipolar_data_(ch, y);
snippets = app.parse_snippets_(yf);
app.parse_response_data(ch, snippets);
end
case 'BS'
if (ch >= 65) || (ch == 0)
app.update_bipolar_stream_data(ch, y);
else
yf = app.filter_unipolar_data_(ch, y);
snippets = app.parse_snippets_(yf);
app.parse_response_data(ch, snippets);
end
case 'BA'
if (ch >= 65) || (ch == 0)
app.update_bipolar_average_data(ch, y);
else
yf = app.filter_unipolar_data_(ch, y);
snippets = app.parse_snippets_(yf);
app.parse_response_data(ch, snippets);
end
end
else
while (src.BytesAvailable > 0) && (x~= 65535)
x = src.read(1, "double");
end
end
case enum.TMSiPacketMode.RasterMode
case enum.TMSiPacketMode.ContourMode
end
end
function update_bipolar_stream_data(app, ch, data)
%UPDATE_BIPOLAR_STREAM_DATA Update bipolar stream handles
if (ch > 64) && (ch < 100)
ch = ch - 64;
if en(ch)
app.H.streams(ch).YData = app.filter_bipolar_data_(ch, data);
if app.connected.responses
snippets = app.parse_snippets_(data);
app.parse_response_data(ch, snippets);
end
end
elseif ch == 0
set(app.H.streams, 'XData', data);
xl = [data(1) data(app.n.all_samples)];
set(app.BipolarUIAxes, 'XLim', xl, 'XTick', [xl(1), data(app.n.mid_sample), xl(2)]);
drawnow;
if app.connected.responses
app.send_response_tcp_message();
end
elseif ch == 100
app.parse_sync_trigs_(data);
end
end
function update_unipolar_stream_data(app, ch, data)
%UPDATE_UNIPOLAR_STREAM_DATA Update unipolar stream handles
if (ch > 0) && (ch < 100)
if en(ch)
app.H.streams(ch).YData = app.filter_unipolar_data_(ch, data);
if app.connected.responses
snippets = app.parse_snippets_(data);
app.parse_response_data(ch, snippets);
end
end
elseif ch == 0
set(app.H.streams, 'XData', data);
xl = [data(1), data(app.n.all_samples)];
set(app.UnipolarUIAxes, 'XLim', xl, 'XTick', [xl(1), data(app.n.mid_sample), xl(2)]);
drawnow;
if app.connected.responses
app.send_response_tcp_message();
end
elseif ch == 100
app.parse_sync_trigs_(data);
end
end
function update_ica_stream_data(app, ch, data)
%UPDATE_ICA_STREAM_DATA Update ICA stream handles
if (ch > 0) && (ch < 100)
en = app.cfg.SAGA.Channels.en.ICA;
if en(ch)
app.H.streams(ch).YData = data + sum(en(1:ch))*app.ICA_OFFSET;
drawnow;
end
if app.connected.responses
snippets = app.parse_snippets_(data);
app.parse_response_data(ch, snippets);
end
elseif ch == 0
set(app.H.streams, 'XData', data);
xl = [data(1), data(app.n.all_samples)];
set(app.ICAUIAxes, 'XLim', xl, 'XTick', [xl(1), data(app.n.mid_sample), xl(2)]);
drawnow;
if app.connected.responses
app.send_response_tcp_message();
end
elseif ch == 100
app.parse_sync_trigs_(data);
end
end
function update_unipolar_average_data(app, ch, data)
%UPDATE_UNIPOLAR_AVERAGE_DATA Update unipolar average handles
if (ch > 0) && (ch < 100) % ch is either 0 (triggers) or (1-indexed data channel)
if app.filters.UNI_AVG.en
data = filter(app.filters.UNI_AVG.b, app.filters.UNI_AVG.a, data);
end
if app.filters.UNI_AVG.rectify
data = abs(data);
end
snippets = app.parse_snippets_(data);
if ch == app.UnipolarAverageChannelEditField.Value
app.shift_in_new_averaging_snippets_(snippets);
end
if app.connected.responses
app.parse_response_data(ch, snippets);
end
elseif ch == 0 % It's "time" channel- this comes after the "data bolus" so just issue command to any listening response server
if app.connected.responses
app.send_response_tcp_message();
end
else
app.parse_sync_trigs_(data);
end
end
function update_bipolar_average_data(app, ch, data)
%UPDATE_BIPOLAR_AVERAGE_DATA Update unipolar average handles
if (ch > 0) && (ch < 100) % ch is either 0 (triggers) or (1-indexed data channel)
ch = ch - 64;
if app.filters.BIP_AVG.en
data = filter(app.filters.BIP_AVG.b, app.filters.BIP_AVG.a, data);
end
if app.filters.BIP_AVG.rectify
data = abs(data);
end
snippets = app.parse_snippets_(data);
if ch == app.BipolarAverageChannelEditField.Value
app.shift_in_new_averaging_snippets_(snippets);
end
if app.connected.responses
app.parse_response_data(ch, snippets);
end
elseif ch == 0 % It's "time" channel- this comes after the "data bolus" so just issue command to any listening response server
if app.connected.responses
app.send_response_tcp_message();
end
else
app.parse_sync_trigs_(data);
end
end
function parse_response_data(app, ch, snippets)
%PARSE_RESPONSE_DATA Send TCP message to "responses" server for RMS data that is used in online stim controller
fs = app.cfg.Default.Sample_Rate;
n_new = size(snippets,1);
rms_data = zeros(n_new, 1);
i_post = [round(app.ResponsesStartEditField.Value * 1e-3 * fs), ...
round(app.ResponsesStopEditField.Value * 1e-3 * fs)];
vec_post = (app.H.sample_indices >= i_post(1)) & ...
(app.H.sample_indices < i_post(2));
vec_pre = app.H.sample_indices < 0;
mu = mean(snippets(:, vec_pre), 2);
for ii = 1:n_new
pre = mean((snippets(ii, vec_pre) - mu(ii)).^2);
rms_data(ii) = mean((snippets(ii, vec_post) - mu(ii)).^2) ./ pre;
end
app.response_data{ch} = circshift(app.response_data{ch}, n_new, 1);
app.response_data{ch}(1:n_new) = rms_data;
app.n_new_ = n_new;
end
function send_response_tcp_message(app)
%SEND_RESPONSE_TCP_MESSAGE Send TCP message to "responses" server with meta-command like to move to next pulse in queue etc.
ch = 1:68;
ch = ch([app.cfg.SAGA.Channels.en.UNI, app.cfg.SAGA.Channels.en.BIP]);
res = zeros(numel(ch), app.n_new_);
ii = 0;
for ich = ch
ii = ii + 1;
res(ii,:) = app.response_data{ich}(1:app.n_new_);
end
jsondata = msg.json_stim_response(app.tag, app.n_new_, ch, res);
app.rclient_.writeline(jsonencode(jsondata));
end
function setConnectionStatus(app, src, evt) %#ok<INUSL>
%SETCONNECTIONSTATUS Indicate whether the app has a client (the controller application) connected over TCP.
if evt.Connected
app.ParametersConnectionStatusLamp.Color = [0.39,0.83,0.07];
app.connected.parameters = true;
else
app.ParametersConnectionStatusLamp.Color = [0.65,0.65,0.65];
app.connected.parameters = false;
end
app.setDateTimeLabel(evt.AbsoluteTime);
end
function setDateTimeLabel(app, dt)
%SETDATETIMELABEL Set the text of the datetime label at the top of the interface.
%
% Inputs:
% dt - Datetime (scalar)
app.DateTimeLabel.Text = sprintf("%4d-%02d-%02d %02d:%02d:%05.3f", ...
year(dt), month(dt), day(dt), hour(dt), minute(dt), second(dt));
end
end
methods (Access = private)
function filtdata = filter_bipolar_data_(app, ch, data)
%FILTER_BIPOLAR_DATA Apply filters to bipolar data
en = app.cfg.SAGA.Channels.en.BIP;
b = app.filters.BIP.b;
a = app.filters.BIP.a;
apply_filter = app.filters.BIP.en;
if apply_filter
[ydata, app.filters.BIP.z(ch,:)] = filter(b,a,(data - mean(data)), app.filters.BIP.z(ch,:));
filtdata = ydata + sum(en(1:ch))*app.BipolarPerChannelOffsetEditField.Value;
else
filtdata = data - mean(data) + (sum(en(1:ch))-1)*app.BipolarPerChannelOffsetEditField.Value;
end
end
function filtdata = filter_unipolar_data_(app, ch, data)
%FILTER_UNIPOLAR_DATA Apply filters to unipolar data
en = app.cfg.SAGA.Channels.en.UNI;
b = app.filters.UNI.b;
a = app.filters.UNI.a;
apply_filter = app.filters.UNI.en;
if apply_filter
[ydata, app.filters.UNI.z(ch,:)] = filter(b,a,(data - mean(data)), app.filters.UNI.z(ch,:));
filtdata = ydata + sum(en(1:ch))*app.UnipolarPerChannelOffsetEditField.Value;
else
filtdata = data - mean(data) + (sum(en(1:ch))-1)*app.UnipolarPerChannelOffsetEditField.Value;
end
end
function disable_bipolar_stream(app, chnum)
%DISABLE_BIPOLAR_STREAM Disable the selected channel(s)
%
% Syntax:
% app.disable_bipolar_stream(chnum)
%
% Inputs:
% chnum - Scalar or vector of integers indicating 1-indexed
% channel-number(s) to disable.
app.cfg.SAGA.Channels.en.BIP(chnum) = false(size(chnum));
for ii = 1:numel(chnum)
h = findobj(app.BipolarStreamChannelsPanel.Children, 'Tag', sprintf('%d', chnum(ii)), 'Type', 'uiswitch');
app.H.streams(chnum(ii)).Visible = 'off';
h.Value = 'Off';
end
end
function enable_bipolar_stream(app, chnum)
%ENABLE_BIPOLAR_STREAM Enable the selected channel(s)
%
% Syntax:
% app.enable_bipolar_stream(chnum)
%
% Inputs:
% chnum - Scalar or vector of integers indicating 1-indexed
% channel-number(s) to enable.
app.cfg.SAGA.Channels.en.BIP(chnum) = true(size(chnum));
for ii = 1:numel(chnum)
h = findobj(app.BipolarStreamChannelsPanel.Children, 'Tag', sprintf('%d', chnum(ii)), 'Type', 'uiswitch');
app.H.streams(chnum(ii)).Visible = 'on';
h.Value = 'On';
end
end
function disable_unipolar_stream(app, chnum)
%DISABLE_UNIPOLAR_STREAM Disable the selected channel(s)
%
% Syntax:
% app.disable_unipolar_stream(chnum)
%
% Inputs:
% chnum - Scalar or vector of integers indicating 1-indexed
% channel-number(s) to disable.
app.cfg.SAGA.Channels.en.UNI(chnum) = false(size(chnum));
for ii = 1:numel(chnum)
h = findobj(app.UnipolarStreamChannelsPanel.Children, 'Tag', sprintf('%d', chnum(ii)), 'Type', 'uiswitch');
app.H.streams(chnum(ii)).Visible = 'off';
h.Value = 'Off';
end
end
function enable_unipolar_stream(app, chnum)
%ENABLE_UNIPOLAR_STREAM Enable the selected channel(s)
%
% Syntax:
% app.enable_unipolar_stream(chnum)
%
% Inputs:
% chnum - Scalar or vector of integers indicating 1-indexed
% channel-number(s) to enable.
app.cfg.SAGA.Channels.en.UNI(chnum) = true(size(chnum));
for ii = 1:numel(chnum)
h = findobj(app.UnipolarStreamChannelsPanel.Children, 'Tag', sprintf('%d', chnum(ii)), 'Type', 'uiswitch');
app.H.streams(chnum(ii)).Visible = 'on';
h.Value = 'On';
end
end
function disable_ica_stream(app, chnum)
%DISABLE_ICA_STREAM Disable the selected channel(s)
%
% Syntax:
% app.disable_ica_stream(chnum)
%
% Inputs:
% chnum - Scalar or vector of integers indicating 1-indexed
% channel-number(s) to disable.
app.cfg.SAGA.Channels.en.ICA(chnum) = false(size(chnum));
for ii = 1:numel(chnum)
h = findobj(app.ICAStreamChannelsPanel.Children, 'Tag', sprintf('%d', chnum(ii)), 'Type', 'uiswitch');
app.H.streams(chnum(ii)).Visible = 'off';
h.Value = 'Off';
end
end
function enable_ica_stream(app, chnum)
%ENABLE_ICA_STREAM Enable the selected channel(s)
%
% Syntax:
% app.enable_ica_stream(chnum)
%
% Inputs:
% chnum - Scalar or vector of integers indicating 1-indexed
% channel-number(s) to enable.
app.cfg.SAGA.Channels.en.ICA(chnum) = true(size(chnum));
for ii = 1:numel(chnum)
h = findobj(app.ICAStreamChannelsPanel.Children, 'Tag', sprintf('%d', chnum(ii)), 'Type', 'uiswitch');
app.H.streams(chnum(ii)).Visible = 'on';
h.Value = 'On';
end
end
function c = init_cdata(app)
%INIT_CDATA Helper function to initialize the colormap stuff
my_colormap = cm.map('rosette');
cmobj = cm.cmap([1 size(my_colormap,1)], my_colormap);
c = struct( ...
'UNI', double(cmobj(linspace(1,32,64)))./255.0, ...
'BIP', double(cmobj(linspace(1,32, 4)))./255.0, ...
'ICA', double(cmobj(linspace(1,32,app.cfg.Default.N_ICs)))./255.0 ...
);
app.CDATA = c;
end
function init_filters(app)
%INIT_FILTERS Helper function to initialize filter coefficients
% Setup filters struct
% 'b' - numerator coefficients
% 'a' - denominator coefficients
% 'z' - filter state (final state values from previous
% step; rows are channels columns are values for each
% state coefficient which depend on filter order;
% since we don't allow order to change (2nd order
% butterworth IIR bandpass filter design, so we
% know this will have 4 columns). For UNI, we add 1
% more row in case we are filtering the CAR signal.
% 'en' - Apply BPF?
app.filters = struct(...
'UNI', struct('b', [], 'a', [], 'z', zeros(65,4), 'en', app.UnipolarFilterCheckBox.Value, 'CAR', app.UnipolarCARCheckBox.Value), ...
'BIP', struct('b', [], 'a', [], 'z', zeros(4,4), 'en', app.BipolarFilterCheckBox.Value), ...
'UNI_AVG', struct('b', [], 'a', [], 'z', zeros(1,4), 'en', app.UnipolarAverageFilterCheckBox.Value, 'CAR', app.UnipolarAverageCARCheckBox.Value, 'rectify', app.UnipolarAverageRectifyCheckBox.Value), ...
'BIP_AVG', struct('b', [], 'a', [], 'z', zeros(1,4), 'en', app.BipolarAverageFilterCheckBox.Value, 'rectify', app.BipolarAverageRectifyCheckBox.Value));
[app.filters.UNI.b,app.filters.UNI.a] = ...
butter(2,([app.UnipolarCutoff1EditField.Value, app.UnipolarCutoff2EditField.Value])./(app.cfg.Default.Sample_Rate/2), 'bandpass');
[app.filters.BIP.b,app.filters.BIP.a] = ...
butter(2,([app.BipolarCutoff1EditField.Value, app.BipolarCutoff2EditField.Value])./(app.cfg.Default.Sample_Rate/2), 'bandpass');
[app.filters.UNI_AVG.b,app.filters.UNI_AVG.a] = ...
butter(2,([app.UnipolarAverageCutoff1EditField.Value, app.UnipolarAverageCutoff2EditField.Value])./(app.cfg.Default.Sample_Rate/2), 'bandpass');
[app.filters.BIP_AVG.b,app.filters.BIP_AVG.a] = ...
butter(2,([app.BipolarAverageCutoff1EditField.Value, app.BipolarAverageCutoff2EditField.Value])./(app.cfg.Default.Sample_Rate/2), 'bandpass');
end
function tf = getEnabledChannels(app, tag)
if nargin < 2
tag = app.TabGroup.SelectedTab.Tag;
end
switch string(upper(tag))
case {"US", "UA", "UR"}
n_ch = numel(app.cfg.SAGA.Channels.UNI);
tf = false(n_ch,1);
for ii = 1:n_ch
name = sprintf("UNI%02dSwitch", ii);
try
tf(ii) = app.(name).Value;
catch me
warning("No matching element for name == '%s'", name);
rethrow(me);
end
end
case {"BS", "BA"}
n_ch = numel(app.cfg.SAGA.Channels.BIP);
tf = false(n_ch,1);
for ii = 1:n_ch
name = sprintf("BIP%02dSwitch", ii);
tf(ii) = app.(name).Value;
end
case {"IS", "IR"}
n_ch = numel(app.cfg.SAGA.Channels.ICA);
tf = false(n_ch,1);
for ii = 1:n_ch
name = sprintf("ICA%02dSwitch", ii);
tf(ii) = app.(name).Value;
end
case "RC"
otherwise
error("Unrecognized tab Tag value: %s", app.TabGroup.SelectedTab.Tag);
end
end
function snippets = parse_snippets_(app, data)
%PARSE_SNIPPETS_ Get "triggered" snippets for averaging (single-channel)
%
% Syntax:
% snippets = app.parse_snippets_(data);
nt = numel(app.H.trigs);
snippets = nan(nt, numel(app.H.sample_indices));
for ii = 1:nt
vec = app.H.sample_indices + app.H.trigs(ii);
idx = (vec > 0) & (vec < numel(data));
snippets(ii, idx) = data(vec(idx));
end
end
function send_uni_stream_udp_message(app)
%SEND_UNI_STREAM_UDP_MESSAGE Sends message to configure as UDP stream with currently-enabled UNIPOLAR (ARRAY) channel-set.
ch = char(app.cfg.SAGA.Channels.UNI(app.cfg.SAGA.Channels.en.UNI) + 96);
message = char(sprintf('%s.%s.%d.%s', app.mode, app.tag, double(app.filters.UNI.CAR), ch));
app.send_message_(message);
end
function send_uni_average_udp_message(app)
%SEND_UNI_AVERAGE_UDP_MESSAGE Sends message to configure as UDP averaging with currently-selected array channel.
% message = char(sprintf('%s.%s.%d.%d', app.mode, app.Tag, double(app.filters.UNI_AVG.CAR), app.cfg.SAGA.Channels.UNI(app.UnipolarAverageChannelEditField.Value)));
ch = char([app.cfg.SAGA.Channels.UNI(app.cfg.SAGA.Channels.en.UNI), app.cfg.SAGA.Channels.BIP(app.cfg.SAGA.Channels.en.BIP)] + 96);
message = char(sprintf('%s.%s.%d.%s', app.mode, app.tag, double(app.filters.UNI.CAR), ch));
app.send_message_(message);
end
function send_bip_stream_udp_message(app)
%SEND_BIP_STREAM_UDP_MESSAGE Sends message to configure as UDP stream with currently-enabled BIPOLAR channel-set.
ch = char(app.cfg.SAGA.Channels.BIP(app.cfg.SAGA.Channels.en.BIP) + 96);
message = char(sprintf('%s.%s.%s', app.mode, app.tag, ch));
app.send_message_(message);
end
function send_bip_average_udp_message(app)
%SEND_BIP_AVERAGE_UDP_MESSAGE Sends message to configure as UDP averaging with currently-selected bipolar channel.
% message = char(sprintf('%s.%s.%d', app.mode, app.Tag, app.cfg.SAGA.Channels.BIP(app.BipolarAverageChannelEditField.Value)));
ch = char([app.cfg.SAGA.Channels.UNI(app.cfg.SAGA.Channels.en.UNI), app.cfg.SAGA.Channels.BIP(app.cfg.SAGA.Channels.en.BIP)] + 96);
message = char(sprintf('%s.%s.%d.%s', app.mode, app.tag, double(app.filters.UNI.CAR), ch));
app.send_message_(message);
end
function send_ica_stream_udp_message(app)
%SEND_ICA_STREAM_UDP_MESSAGE Sends message to configure as UDP stream with currently-enabled BIPOLAR channel-set.
ch = char(app.cfg.SAGA.Channels.ICA(app.cfg.SAGA.Channels.en.ICA) + 96);
message = char(sprintf('%s.%s.%s', app.mode, app.tag, ch));
app.send_message_(message);
end
function send_mode_only_udp_message(app)
%SEND_MODE_ONLY_UDP_MESSAGE Sends message to configure as UDP stream with currently-enabled BIPOLAR channel-set.
message = char(sprintf('%s.%s', app.mode, app.tag));
app.send_message_(message);
end
function send_message_(app, message)
%SEND_MESSAGE_ Sends message via UDP and also to the parameters TCP client.
if app.data_running_
fprintf(1,'[SAGA-%s VISUALIZER]\tData is running; no parameter message sent.\n', app.tag);
else
fprintf(1,'[SAGA-%s VISUALIZER]\tSending message: %s\n', app.tag, message);
if app.connected.data
app.udp_receiver_.writeline(message, app.cfg.Host.streams, app.cfg.UDP.tmsi.config);
end
end
end
function h = init_uni_stream_tab_graphics(app)
xvec = (0:(app.cfg.SAGA.Channels.n.samples-1))./app.cfg.Default.Sample_Rate;
h = struct('streams', gobjects(numel(app.cfg.SAGA.Channels.UNI), 1), 'trigs', []);
for ii = 1:numel(h.streams)
offset = app.UnipolarPerChannelOffsetEditField.Value * (ii-1);
h.streams(ii) = line(app.UnipolarUIAxes, xvec, zeros(size(xvec)) + offset, ...
'Color', app.CDATA.UNI(ii,:), ...
'LineWidth', 1.5, ...
'DisplayName', sprintf('UNI%02d', ii), ...
'Visible', 'off' );
end
end
function h = init_uni_average_tab_graphics(app)
fs = app.cfg.Default.Sample_Rate;
sample_indices = round(app.StartUnipolarAverageSpinner.Value * fs * 1e-3):round(app.StopUnipolarAverageSpinner.Value * fs * 1e-3);
t_vec = sample_indices / fs * 1e3;
h = struct('ax', app.UnipolarAverageUIAxes, 'mean', gobjects(1,1), 'sd', gobjects(1,1), 'history', nan(app.UnipolarAverageNEditField.Value, numel(sample_indices)), 'n', 0, 'n_max', app.UnipolarAverageNEditField.Value, 'sample_indices', sample_indices, 'trigs', []);
npt= numel(sample_indices);
faces = [1:2*npt, 1];
verts = [[t_vec'; flipud(t_vec')], [ones(npt,1); -1.*ones(npt,1)]];
app.UnipolarAverageUIAxes.Title.String = "(N = 0)";
h.sd = patch(app.UnipolarAverageUIAxes, 'Faces', faces, 'Vertices', verts, 'FaceColor', [0.65 0.65 0.65], 'DisplayName', '\pm1SD','EdgeColor', 'none');
h.mean = line(app.UnipolarAverageUIAxes, t_vec, zeros(size(t_vec)), 'Color', 'k', 'LineWidth', 2.5, 'DisplayName', 'Mean');
if app.UnipolarAverageRectifyCheckBox.Value
set(app.UnipolarAverageUIAxes, 'YLim', [-10 100], 'XLim', [t_vec(1), t_vec(end)]);
else
set(app.UnipolarAverageUIAxes, 'YLim', [-100 100], 'XLim', [t_vec(1), t_vec(end)]);
end
end
function h = init_uni_raster_tab_graphics(app)
h = struct;
end
function h = init_bip_stream_tab_graphics(app)
xvec = (0:(app.cfg.SAGA.Channels.n.samples-1))./app.cfg.Default.Sample_Rate;
h = struct('streams', gobjects(numel(app.cfg.SAGA.Channels.BIP), 1), 'trigs', []);
for ii = 1:numel(h.streams)
offset = app.BipolarPerChannelOffsetEditField.Value * (ii-1);
h.streams(ii) = line(app.BipolarUIAxes, xvec, zeros(size(xvec)) + offset, ...
'Color', app.CDATA.BIP(ii,:), ...
'LineWidth', 1.5, ...
'DisplayName', sprintf('BIP%02d', ii), ...
'Visible', 'off' );
end
end
function h = init_bip_average_tab_graphics(app)
fs = app.cfg.Default.Sample_Rate;
sample_indices = round(app.StartBipolarAverageSpinner.Value * fs * 1e-3):round(app.StopBipolarAverageSpinner.Value * fs * 1e-3);
t_vec = sample_indices / fs * 1e3;
h = struct('ax', app.BipolarAverageUIAxes, 'mean', gobjects(1,1), 'sd', gobjects(1,1), 'history', nan(app.BipolarAverageNEditField.Value, numel(sample_indices)), 'n', 0, 'n_max', app.BipolarAverageNEditField.Value, 'sample_indices', sample_indices, 'trigs', []);
npt= numel(sample_indices);
faces = [1:2*npt, 1];
verts = [[t_vec'; flipud(t_vec')], [ones(npt,1); -1.*ones(npt,1)]];
app.BipolarAverageUIAxes.Title.String = "(N = 0)";
h.sd = patch(app.BipolarAverageUIAxes, 'Faces', faces, 'Vertices', verts, 'FaceColor', [0.65 0.65 0.65], 'DisplayName', '\pm1SD','EdgeColor', 'none');
h.mean = line(app.BipolarAverageUIAxes, t_vec, zeros(size(t_vec)), 'Color', 'k', 'LineWidth', 2.5, 'DisplayName', 'Mean');
if app.BipolarAverageRectifyCheckBox.Value
set(app.BipolarAverageUIAxes, 'YLim', [-10 100], 'XLim', [t_vec(1), t_vec(end)]);
else
set(app.BipolarAverageUIAxes, 'YLim', [-100 100], 'XLim', [t_vec(1), t_vec(end)]);
end
end
function h = init_ica_stream_tab_graphics(app)
xvec = (0:(app.cfg.SAGA.Channels.n.samples-1))./app.cfg.Default.Sample_Rate;
h = struct('streams', gobjects(app.cfg.Default.N_ICs, 1), 'trigs', []);
for ii = 1:numel(h.streams)
offset = app.ICA_OFFSET * (ii-1);
h.streams(ii) = line(app.ICAUIAxes, xvec, zeros(size(xvec)) + offset, ...
'Color', app.CDATA.ICA(ii,:), ...
'LineWidth', 1.5, ...
'DisplayName', sprintf('ICA%02d', ii), ...
'Visible', 'off' );
end
end
function h = init_ica_raster_tab_graphics(app)
h = struct;
end
function h = init_rms_contour_tab_graphics(app)
h = struct;
end
function shift_in_new_averaging_snippets_(app, snippets)
if isempty(snippets)
return;
end
n_snips = size(snippets,1);
app.H.n = min(app.H.n+n_snips, app.H.n_max);
app.H.history = circshift(app.H.history, n_snips, 1);
app.H.history(1:n_snips,:) = snippets;
mu = nanmean(app.H.history(1:app.H.n,:), 1); %#ok<*NANMEAN>
sd = nanstd(app.H.history(1:app.H.n,:), [], 1); %#ok<*NANSTD>
app.H.mean.YData = mu;
app.H.sd.Vertices(:,2) = [(mu + sd)'; flipud((mu - sd)')];
app.H.ax.Title.String = sprintf('(N = %d)', app.H.n);
drawnow;
end
function parse_sync_trigs_(app, data, n_samples_debounce)
fs = app.cfg.Default.Sample_Rate;
if nargin < 3
n_samples_debounce = fs * 0.100; % 100-ms default
end
sync_bit = app.TriggerSyncBitEditField.Value;
sync_data = bitand(data, 2^sync_bit) ~= 2^sync_bit;
trigs = find([false; diff(sync_data(:)) > 0]);
% Remove triggers that don't have the correct pre- or post-
% sample count:
trigs(trigs <= (app.StartUnipolarAverageSpinner.Value * fs * -1e-3)) = [];
trigs(trigs > (numel(data) - (app.StopUnipolarAverageSpinner.Value * fs * 1e-3))) = [];
% Debounce triggers that are too close together (i.e. multiple
% pulses within a single stimulus burst; we only want to
% average in alignment to the rising-edge of the first pulse)
k = 1;
curTrig = -inf;
while k < numel(trigs)
if (trigs(k) - curTrig) > n_samples_debounce
curTrig = trigs(k); % Save this trigger as new "last trig"
k = k + 1; % increment counter since we do not drop sample
else % Otherwise, this trigger is too soon- remove it
trigs(k) = []; % k does not increment.
end
end
app.H.trigs = trigs;
end
end
methods (Static, Access = protected)
function WipeTabGraphics(tab)
%WIPETABGRAPHICS Delete all child-axes graphics, given a tab.
h = findobj(tab.Children, 'Type', 'axes');
delete(h.Children);
end
end
% Callbacks that handle component events
methods (Access = private)
% Code that executes after component creation
function startupFcn(app, tag, config, varargin)
app.tag = tag;
% If this is the second SAGA figure move it right.
if strcmpi(tag, "B")
app.SAGADataViewerUIFigure.Position(1) = app.SAGADataViewerUIFigure.Position(1) + app.SAGADataViewerUIFigure.Position(3)*0.85;
end
% Setup the title and stuff:
set(app.SAGADataViewerUIFigure, ...
'Name', sprintf("SAGA-%s Data Viewer", app.tag), ...
'Tag', sprintf('fig.DataViewer.%s', app.tag));