-
Notifications
You must be signed in to change notification settings - Fork 0
/
RUN_VNS_EXP.m
1214 lines (910 loc) · 42.2 KB
/
RUN_VNS_EXP.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function varargout = RUN_VNS_EXP(varargin)
% RUN VNS experiment
% Last Modified by GUIDE v2.5 07-Mar-2017 10:38:13
% YBS/MFY March 2017
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @RUN_VNS_EXP_OpeningFcn, ...
'gui_OutputFcn', @RUN_VNS_EXP_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before RUN_VNS_EXP is made visible.
function RUN_VNS_EXP_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to RUN_VNS_EXP (see VARARGIN)
% Choose default command line output for RUN_VNS_EXP
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
%% define DAQ settings section
% Define analog and digital sessions
% release the DAQ card if busy from another session
try
daqreset;
catch
end
% Check if daq devices are available and abort if they are not
d = daq.getDevices;
if isempty(d)
warndlg('No DAQ object found. Aborting','RUN VNS experiment');
return
end
% Establish analog and digital connections
try
continS = daq.createSession('ni');
analog_ch_1 = continS.addAnalogOutputChannel('Dev1','ao0', 'Voltage'); % Sound (speaker)
analog_ch_2 = continS.addAnalogOutputChannel('Dev1','ao1', 'Voltage'); % SNT (stimulator)
analog_ch_3 = continS.addAnalogOutputChannel('Dev1','ao2', 'Voltage'); % Wash (valve)
continS.Rate = 10000; % sampling rate of data
digiS = daq.createSession ('ni');
% 8 bits for re[prting trial ID
digi_ch_0 = digiS.addDigitalChannel('Dev1', 'Port0/Line0', 'OutputOnly');
digi_ch_1 = digiS.addDigitalChannel('Dev1', 'Port0/Line1', 'OutputOnly');
digi_ch_2 = digiS.addDigitalChannel('Dev1', 'Port0/Line2', 'OutputOnly');
digi_ch_3 = digiS.addDigitalChannel('Dev1', 'Port0/Line3', 'OutputOnly');
digi_ch_4 = digiS.addDigitalChannel('Dev1', 'Port0/Line4', 'OutputOnly');
digi_ch_5 = digiS.addDigitalChannel('Dev1', 'Port0/Line5', 'OutputOnly');
digi_ch_6 = digiS.addDigitalChannel('Dev1', 'Port0/Line6', 'OutputOnly');
digi_ch_7 = digiS.addDigitalChannel('Dev1', 'Port0/Line7', 'OutputOnly');
catch
warndlg('Unable to establish DAQ session. Aborting','RUN VNS experiment');
return
end
% save sessions definitions into DATA structure
handles.DATA.analog_session = continS;
handles.DATA.digital_session = digiS;
handles.DATA.pause = 0;
handles.DATA.stopped = 0;
%% establish paths and create forlder if these do not exist
% get or create the log file - one is used per day
[BASE_P,~,~] = fileparts(mfilename('fullpath'));
LOG_FILE_PATH = [BASE_P filesep 'log_files'];
PARAM_FILE_PATH = [BASE_P filesep 'exp_params_files'];
if ~exist(LOG_FILE_PATH,'dir')
mkdir(LOG_FILE_PATH);
end
if ~exist(PARAM_FILE_PATH,'dir')
mkdir(PARAM_FILE_PATH);
end
handles.DATA.PARAM_FILE_PATH = PARAM_FILE_PATH;
%% Check if a log file exists, and if so, update the interface
log_file_name = [ LOG_FILE_PATH '\VNS_EXP_LOG_' date];
handles.DATA.log_file_name = log_file_name;
if exist([log_file_name '.mat'],'file')
load(log_file_name,'log_data');
if isfield(log_data,'params')
k = 1;
for i = 1:length(log_data)
if log_data(i).good_trial
SS{k} = [log_data(i).stim_name '(' num2str(log_data(i).unique_trial_id) ')'];
k = k + 1;
end
end
if k > 1
set(handles.event_listbox,'string',SS);
end
end
if isempty(log_data)
handles.DATA.unique_trial_id = 0;
else
handles.DATA.unique_trial_id = log_data(end).unique_trial_id;
end
else
log_data = [];
save(log_file_name,'log_data');
handles.DATA.unique_trial_id = 0;
end
handles.DATA.log_file_name = log_file_name;
handles.DATA.log_data = log_data;
guidata(hObject,handles);
% load the default settings defined prviously
load_default_params_button_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Outputs from this function are returned to the command line.
function varargout = RUN_VNS_EXP_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function VNO_stim_frequency_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function VNO_stim_frequency_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to VNO_stim_frequency_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function VNO_stim_duration_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function VNO_stim_duration_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to VNO_stim_duration_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function VNO_stim_pulse_width_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function VNO_stim_pulse_width_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to VNO_stim_pulse_width_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function VNO_stim_interphase_delay_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function VNO_stim_interphase_delay_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to VNO_stim_interphase_delay_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function VNO_stim_amplitude_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function VNO_stim_amplitude_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to VNO_stim_amplitude_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function ITI_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function ITI_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to ITI_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function application_to_stim_delay_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function application_to_stim_delay_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to application_to_stim_delay_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function stim_to_wash_delay_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function stim_to_wash_delay_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to stim_to_wash_delay_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function wash_start_to_wash_stim_delay_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function wash_start_to_wash_stim_delay_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to wash_start_to_wash_stim_delay_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function wash_stim_to_wash_end_delay_edit_Callback(hObject, eventdata, handles)
update_stim_params(hObject,handles);
% --- Executes during object creation, after setting all properties.
function wash_stim_to_wash_end_delay_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to wash_stim_to_wash_end_delay_edit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function update_stim_params(hObject,handles)
% get values for all
Params.SR = handles.DATA.analog_session.Rate; % SR in Hz
StimParams(1).name = 'ITI_edit';
StimParams(1).default = 5;
StimParams(1).range = [1 60];
StimParams(2).name = 'application_to_stim_delay_edit';
StimParams(2).default = 10;
StimParams(2).range = [2 30];
StimParams(3).name = 'stim_to_wash_delay_edit';
StimParams(3).default = 20;
StimParams(3).range = [2 40];
StimParams(4).name = 'wash_start_to_wash_stim_delay_edit';
StimParams(4).default = 10;
StimParams(4).range = [1 20];
StimParams(5).name = 'wash_stim_to_wash_end_delay_edit';
StimParams(5).default = 10;
StimParams(5).range = [2 30];
StimParams(6).name = 'VNO_stim_frequency_edit';
StimParams(6).default = 10;
StimParams(6).range = [5 40];
StimParams(7).name = 'VNO_stim_duration_edit';
StimParams(7).default = 1.6;
StimParams(7).range = [0.1 2];
StimParams(8).name = 'VNO_stim_pulse_width_edit';
StimParams(8).default = 2;
StimParams(8).range = [1 3];
StimParams(9).name = 'VNO_stim_interphase_delay_edit';
StimParams(9).default = 0.2;
StimParams(9).range = [0.1 0.3];
StimParams(10).name = 'VNO_stim_amplitude_edit';
StimParams(10).default = 10;
StimParams(10).range = [0 10];
for i = 1:length(StimParams)
eval(['tmpval = str2num(get(handles.' StimParams(i).name ',''string''));' ]);
if isempty(tmpval)
errordlg([StimParams(i).name([1:end-5]) ' must be a number']);
tmpval = StimParams(i).default;
end
if tmpval < StimParams(i).range(1) || tmpval > StimParams(i).range(2)
errordlg([StimParams(i).name([1:end-5]) ' must be between ' num2str(StimParams(i).range(1)) ' and ' num2str(StimParams(i).range(2))]);
tmpval = StimParams(i).default;
end
eval(['Params.' StimParams(i).name([1:end-5]) ' = ' num2str(tmpval) ';']);
eval(['set(handles.' StimParams(i).name ',''string'',''' num2str(tmpval) ''')']);
end
[SOUND_chan,VNO_chan,VALVE_chan, apply_sample] = generate_single_VNS_trial_scan(Params);
apply_time = apply_sample/Params.SR;
timevec = [1:length(SOUND_chan)]/Params.SR;
ITI = Params.ITI;
TE = timevec(end);
TD = TE + ITI;
% plot the signals in the relevant axes of the GUI
axes(handles.soundaxes);
hold off
plot(timevec,SOUND_chan,'g')
set(gca,'ylim',[-12 12],'xlim',[-ITI TE],'ytick',[],'xtick',[]);
hold on; lh(1) = line([apply_time apply_time],[-12 12]);
zeroLH(1) = line([0 0],[-12 12]);
ch(1) = line([-ITI -ITI],[-12 12]);
ylabel('sound (V)');
axes(handles.stimaxes);
hold off
plot(timevec,VNO_chan,'r')
set(gca,'ylim',[-12 12],'xlim',[-ITI TE],'ytick',[],'xtick',[]);
hold on; lh(2) = line([apply_time apply_time],[-12 12]);
zeroLH(2) = line([0 0],[-12 12]);
ch(2) = line([-ITI -ITI],[-12 12]);
ylabel('SNT (V)');
axes(handles.valveaxes);
hold off
plot(timevec,VALVE_chan,'b')
set(gca,'ylim',[-1 5],'xlim',[-ITI TE],'ytick',[]);
set(gca,'xtick',[-ITI 0:5:TE]);
hold on; lh(3) = line([apply_time apply_time],[-1 5]);
zeroLH(3) = line([0 0],[-5 5]);
ch(3) = line([-ITI -ITI],[-1 5]);
ylabel('Valve (V)');
xlabel('Time(S)')
set(lh,'color','k','linestyle',':', 'linewidth',2);
% the moving cursor
set(ch,'color','r','linewidth',2);
set(zeroLH,'color','k','linewidth',1);
ITI_zeros = zeros(1,ceil(Params.SR*ITI));
handles = guidata(hObject);
DATA = handles.DATA;
DATA.Params = Params;
UPV = -10; % minimum amplitude of out voltage for the sound signal
DATA.SOUND_chan = [ones(1,100)*UPV ITI_zeros(1:(end-100)) SOUND_chan(1:end-5) zeros(1,5)];% add 100 high sound samples in the begining of each trial
DATA.VNO_chan = [ITI_zeros VNO_chan];
DATA.VALVE_chan = [ITI_zeros VALVE_chan];
DATA.plot_line_handles = ch;
DATA.trial_duration = TD;
DATA.apply_time = apply_time;
DATA.SR = Params.SR;
handles.DATA = DATA;
guidata(hObject,handles);
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in run_once_button.
function run_once_button_Callback(hObject, eventdata, handles)
% hObject handle to run_once_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(gcbo);
DATA = handles.DATA;
ITI = DATA.Params.ITI;
TD = DATA.trial_duration;
continS = DATA.analog_session;
continS.queueOutputData([DATA.SOUND_chan; DATA.VNO_chan ; DATA.VALVE_chan]');
continS.startBackground();
tic
TP = 0.2; % Temporal resolution of cursor.
cursor_timer = timer('TimerFcn',{@plot_cursor_callback,handles,ITI}, 'Period', TP,'ExecutionMode','fixedRate','TasksToExecute',floor((TD+TP)/TP),'name','cursor_timer');
DATA.cursor_timer = cursor_timer;
handles.DATA = DATA;
guidata(hObject,handles);
start(cursor_timer);
% --- Executes on button press in stop_button.
function stop_button_Callback(hObject, eventdata, handles)
handles = guidata(gcbo);
DATA = handles.DATA;
continS = DATA.analog_session;
digiS = DATA.digital_session;
ITI = DATA.Params.ITI;
% continS.startForeground();
if continS.IsRunning
try
continS.stop();
catch
return
end
else
return
end
cursor_timer = DATA.cursor_timer;
stop(cursor_timer);
delete(cursor_timer);% why not ...
LHs = DATA.plot_line_handles;
for i = 1:length(LHs)
set(LHs(i),'XData',[-ITI -ITI]);
end
handles.DATA.stopped = 1;
% reset the digital display
digiS.outputSingleScan([0 0 0 0 0 0 0 0]); % reset bit mask
for i = 1:8
eval(['set(handles.bit_panel_' num2str(i) ',''BackgroundColor'',[0.212 0.208 0.200])']);
end
guidata(hObject,handles);
% --- Executes on button press in load_button.
function load_button_Callback(hObject, eventdata, handles)
% hObject handle to load_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[BASE_P,~,~] = fileparts(mfilename('fullpath'));
STIM_FILE_PATH = [BASE_P filesep 'stimulus_files'];
if ~exist(STIM_FILE_PATH,'dir')
mkdir(STIM_FILE_PATH);
end
% Load the file
[filename, filepath, ~] = uigetfile([STIM_FILE_PATH filesep '*.txt'], 'Select an stimulus file');
if ~filename
return
end
% Read stimuli from file
stimulus_strings = read_stimulus_file([filepath filesep filename]);
% set(handles.stim_file_text,'string',filename);
set(handles.all_stims_listbox,'string',[]);
% Write the entire list of odorants in the all_stims_listbox
for k = 1:length(stimulus_strings)
stimulus_strings{k} = [stimulus_strings{k}];
end
set(handles.all_stims_listbox,'string',stimulus_strings);
set(handles.current_stim_number_text,'string','');
set(handles.all_stims_listbox,'value',1);
set(handles.all_stims_listbox,'enable','on');
%update_event_fromfile(handles);
set(handles.run_exp_button,'enable','on');
[UL,IA,IC] = unique(stimulus_strings);
% FInd which stimulus are ES stimuli
% Generate the unique list and generate a list with a unique code for each
DATA = handles.DATA;
STIMS.list = stimulus_strings;
STIMS.unique_stimuli = UL;
STIMS.unique_stimulus_codes = IC;
DATA.next_stim = 1;
DATA.STIMS = STIMS;
handles.DATA = DATA;
set(handles.current_stim_number_text,'string','');
set(handles.current_stim_text,'string','');
set(handles.next_stim_text,'string',STIMS.list(1));
update_stim_params(hObject,handles);
guidata(hObject,handles);
%
% --- Executes on selection change in all_stims_listbox.
function all_stims_listbox_Callback(hObject, eventdata, handles)
% hObject handle to all_stims_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
warndlg('Note that by selecting a different stimulus from the list changes trial flow', 'RUN VNS EXP');
% Hints: contents = cellstr(get(hObject,'String')) returns all_stims_listbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from all_stims_listbox
% --- Executes during object creation, after setting all properties.
function all_stims_listbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to all_stims_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in event_listbox.
function event_listbox_Callback(hObject, eventdata, handles)
% hObject handle to event_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns event_listbox contents as cell array
% contents{get(hObject,'Value')} returns selected item from event_listbox
% --- Executes during object creation, after setting all properties.
function event_listbox_CreateFcn(hObject, eventdata, handles)
% hObject handle to event_listbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in run_exp_button.
function run_exp_button_Callback(hObject, eventdata, handles)
% hObject handle to run_exp_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.event_listbox,'BackgroundColor',[1,1,1])
set(handles.all_stims_listbox,'BackgroundColor',[1,1,1])
stimulus_strings = handles.DATA.STIMS.list;
UL = handles.DATA.STIMS.unique_stimuli;
IC = handles.DATA.STIMS.unique_stimulus_codes;
n_stims = length(stimulus_strings);
current_stim_no = get(handles.all_stims_listbox,'value');
digiS = handles.DATA.digital_session;
continS = handles.DATA.analog_session;
% update the stimuli done box and save the data as well
% update the current stim value in the list, in the figure data and update the next stimuli etc ...
DONE = 0;
while ~DONE
% disable buttons during execution
getset_param_vals(hObject, eventdata, handles,'disable');
set(handles.VNO_single_stimulation,'Enable','off');
set(handles.open_valve_button,'Enable','off');
set(handles.all_stims_listbox,'Enable','off');
set(handles.show_SNT_train_button,'Enable','off');
handles.DATA.unique_trial_id = handles.DATA.unique_trial_id + 1;
guidata(hObject,handles);
% Get next stim number
% no, the next stim is always the current one in the list.
% take the current stimulus from the list
% write it in the now presenting box
set(handles.current_stim_text,'string',stimulus_strings{current_stim_no});
set(handles.current_stim_number_text,'string',num2str(num2str(handles.DATA.unique_trial_id)));
% and if this is not the last item, write the next stim in the up next box
if current_stim_no < n_stims
set(handles.next_stim_text,'string',stimulus_strings{current_stim_no+1});
else
set(handles.next_stim_text,'string','');
end
update_stim_params(hObject,handles);
% Get the appropriate bit mask and set it on the digital port
bit_mask = fliplr(uint8(dec2bin(handles.DATA.unique_trial_id,8)) - uint8(dec2bin(0,8)));
digiS.outputSingleScan(double(bit_mask));
% Update the bit display
for i = 1:8
if bit_mask(i)
eval(['set(handles.bit_panel_' num2str(i) ',''BackgroundColor'',''r'')']);
else
eval(['set(handles.bit_panel_' num2str(i) ',''BackgroundColor'',[0.212 0.208 0.200])']);
end
end
% Run the trial
run_once_button_Callback(hObject, eventdata, handles);
RUNNING = 1;
while RUNNING
RUNNING = continS.IsRunning ;
pause(0.5);
end
% if it was completed successfuly - we advance to the next trial - moving the
% stimulus list value
% otherwise we break...
handles = guidata(gcbo);
if handles.DATA.stopped
% We do not want to advance to the next stimulus
% We do not need to update the list so there is nothing to do
% really
DONE = 1;
handles.DATA.stopped = 0;
guidata(hObject,handles);
good_trial = 0;
elseif current_stim_no < n_stims
% if no pause and we are not at the end of the list
% we do not need to update because we will enter the loop
% again
% update the completed stimuli list box
SS = get(handles.event_listbox,'string');
SS{length(SS)+1} = [stimulus_strings{current_stim_no} '(' num2str(handles.DATA.unique_trial_id) ')'];
set(handles.event_listbox,'string',SS);
good_trial = 1;
% and prepare it for the next one
current_stim_no = current_stim_no + 1;
set(handles.all_stims_listbox,'value',current_stim_no);
%check the length of the intan file
format_date=('ddmmmyy');
date_for_folder=lower(datestr(now,format_date));
% we do everything except continue
if handles.DATA.pause
handles.DATA.pause = 0;
guidata(hObject,handles);
DONE = 1;
end
else % we reached the end of the list
% we have to reset because we won't enter this loop again
% update the completed stimuli list box
SS = get(handles.event_listbox,'string');
SS{length(SS)+1} = [stimulus_strings{current_stim_no} '(' num2str(handles.DATA.unique_trial_id) ')'];
set(handles.event_listbox,'string',SS);
good_trial = 1;
DONE = 1;
current_stim_no = 1;
set(handles.all_stims_listbox,'value',current_stim_no);
set(handles.current_stim_text,'string',stimulus_strings{current_stim_no});
set(handles.current_stim_number_text,'string',num2str(handles.DATA.unique_trial_id));
set(handles.next_stim_text,'string',stimulus_strings{current_stim_no+1});
end
Params = getset_param_vals(hObject, eventdata, handles); % but add this
np = length(Params);
Params(np+1).value = handles.DATA.SR;
Params(np+1).name = 'SR';
Params(np+2).value = handles.DATA.apply_time;
Params(np+2).name = 'apply time';
load(handles.DATA.log_file_name,'log_data');
nt = length(log_data);
log_data(nt+1).good_trial = good_trial;
if current_stim_no==1
log_data(nt+1).stim_name = stimulus_strings{end};
else
log_data(nt+1).stim_name = stimulus_strings{current_stim_no-1};
end
log_data(nt+1).unique_trial_id = (handles.DATA.unique_trial_id);
log_data(nt+1).now = datestr(now);
log_data(nt+1).params = Params;
save(handles.DATA.log_file_name,'log_data');
guidata(hObject,handles);
end
getset_param_vals(hObject, eventdata, handles,'enable');
set(handles.VNO_single_stimulation,'Enable','on');
set(handles.open_valve_button,'Enable','on');
set(handles.all_stims_listbox,'Enable','on');
set(handles.show_SNT_train_button,'Enable','on');
digiS.outputSingleScan(0*bit_mask); % reset bit mask
update_stim_params(hObject,handles);
for i = 1:8
eval(['set(handles.bit_panel_' num2str(i) ',''BackgroundColor'',[0.212 0.208 0.200])']);
end
function plot_cursor_callback(obj,event,handles,ITI)
thistock = toc;
handles = guidata(handles.figure1);
DATA = handles.DATA;
LHs = DATA.plot_line_handles;
for i = 1:length(LHs)
set(LHs(i),'XData',[thistock thistock] - ITI);
end
% --- Executes on button press in pause_experiment_button.
function pause_experiment_button_Callback(hObject, eventdata, handles)
handles = guidata(gcbo);
handles.DATA.pause = 1;
guidata(hObject,handles);
% --- Executes on button press in save_params_as_default_button.
function save_params_as_default_button_Callback(hObject, eventdata, handles)
% hObject handle to save_params_as_default_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% String parameters
StimParams(1).name = 'ITI_edit';
StimParams(2).name = 'application_to_stim_delay_edit';
StimParams(3).name = 'stim_to_wash_delay_edit';
StimParams(4).name = 'wash_start_to_wash_stim_delay_edit';
StimParams(5).name = 'wash_stim_to_wash_end_delay_edit';
StimParams(6).name = 'VNO_stim_frequency_edit';
StimParams(7).name = 'VNO_stim_duration_edit';
StimParams(8).name = 'VNO_stim_pulse_width_edit';
StimParams(9).name = 'VNO_stim_interphase_delay_edit';
StimParams(10).name = 'VNO_stim_amplitude_edit';
for i = 1:length(StimParams)
eval(['Param_str{i} = get(handles.' StimParams(i).name ',''string'');' ]);
end
PARAM_FILE_PATH = handles.DATA.PARAM_FILE_PATH;
save([PARAM_FILE_PATH '\default_params'],'StimParams','Param_str');
% --- Executes on button press in load_default_params_button.
function load_default_params_button_Callback(hObject, eventdata, handles)
% hObject handle to load_default_params_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PARAM_FILE_PATH = handles.DATA.PARAM_FILE_PATH;
fname = [PARAM_FILE_PATH '\default_params.mat'];
if exist(fname,'file')
load(fname);
else
warndlg('A user defined default param file was not found','RUN VNS EXP');
return
end
% String parameters
StimParams(1).name = 'ITI_edit';
StimParams(2).name = 'application_to_stim_delay_edit';
StimParams(3).name = 'stim_to_wash_delay_edit';
StimParams(4).name = 'wash_start_to_wash_stim_delay_edit';
StimParams(5).name = 'wash_stim_to_wash_end_delay_edit';
StimParams(6).name = 'VNO_stim_frequency_edit';
StimParams(7).name = 'VNO_stim_duration_edit';
StimParams(8).name = 'VNO_stim_pulse_width_edit';
StimParams(9).name = 'VNO_stim_interphase_delay_edit';
StimParams(10).name = 'VNO_stim_amplitude_edit';
for i = 1:length(StimParams)
eval(['set(handles.' StimParams(i).name ',''string'',''' Param_str{i} ''');']);
end
update_stim_params(hObject,handles);
% --- Executes on button press in save_params_to_file_button.
function save_params_to_file_button_Callback(hObject, eventdata, handles)
% hObject handle to save_params_to_file_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% String parameters
StimParams(1).name = 'ITI_edit';
StimParams(2).name = 'application_to_stim_delay_edit';
StimParams(3).name = 'stim_to_wash_delay_edit';
StimParams(4).name = 'wash_start_to_wash_stim_delay_edit';
StimParams(5).name = 'wash_stim_to_wash_end_delay_edit';
StimParams(6).name = 'VNO_stim_frequency_edit';
StimParams(7).name = 'VNO_stim_duration_edit';
StimParams(8).name = 'VNO_stim_pulse_width_edit';
StimParams(9).name = 'VNO_stim_interphase_delay_edit';
StimParams(10).name = 'VNO_stim_amplitude_edit';
for i = 1:length(StimParams)
eval(['Param_str{i} = get(handles.' StimParams(i).name ',''string'');' ]);
end
PARAM_FILE_PATH = handles.DATA.PARAM_FILE_PATH;
[param_file, param_path] = uiputfile([PARAM_FILE_PATH '\*.mat'], 'save param file');
if isequal(param_file,0) || isequal(param_path,0)
return
else
save([param_path param_file],'StimParams','Param_str');
end
% --- Executes on button press in load_params_from_file_button.
function load_params_from_file_button_Callback(hObject, eventdata, handles)
% hObject handle to load_params_from_file_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PARAM_FILE_PATH = handles.DATA.PARAM_FILE_PATH;
[param_file, param_path] = uigetfile([PARAM_FILE_PATH '\*.mat'], 'load param file');
if isequal(param_file,0) || isequal(param_path,0)
return
else
load([param_path param_file],'StimParams','Param_str');
end
% String parameters
StimParams(1).name = 'ITI_edit';
StimParams(2).name = 'application_to_stim_delay_edit';
StimParams(3).name = 'stim_to_wash_delay_edit';
StimParams(4).name = 'wash_start_to_wash_stim_delay_edit';
StimParams(5).name = 'wash_stim_to_wash_end_delay_edit';
StimParams(6).name = 'VNO_stim_frequency_edit';
StimParams(7).name = 'VNO_stim_duration_edit';
StimParams(8).name = 'VNO_stim_pulse_width_edit';
StimParams(9).name = 'VNO_stim_interphase_delay_edit';
StimParams(10).name = 'VNO_stim_amplitude_edit';
for i = 1:length(StimParams)
eval(['set(handles.' StimParams(i).name ',''string'',''' Param_str{i} ''');']);
end
update_stim_params(hObject,handles);
function Params = getset_param_vals(hObject, eventdata, handles,operation)
% String parameters
Params(1).name = 'ITI_edit';
Params(2).name = 'application_to_stim_delay_edit';
Params(3).name = 'stim_to_wash_delay_edit';
Params(4).name = 'wash_start_to_wash_stim_delay_edit';
Params(5).name = 'wash_stim_to_wash_end_delay_edit';
Params(6).name = 'VNO_stim_frequency_edit';
Params(7).name = 'VNO_stim_duration_edit';
Params(8).name = 'VNO_stim_pulse_width_edit';
Params(9).name = 'VNO_stim_interphase_delay_edit';
Params(10).name = 'VNO_stim_amplitude_edit';
for i = 1:length(Params)
eval(['Params(i).value = str2num(get(handles.' Params(i).name ',''string''));' ]);
end
more_handles{1} = 'handles.load_params_from_file_button';
more_handles{2} = 'handles.save_params_to_file_button';
more_handles{3} = 'handles.load_default_params_button';
more_handles{4} = 'handles.save_params_as_default_button';
more_handles{5} = 'handles.run_exp_button';
more_handles{6} = 'handles.load_button';
if exist('operation')
switch operation
case 'enable'