forked from davidjuliancaldwell/DBSanalysisCode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdbsFilegen_8_19_2016.m
67 lines (46 loc) · 1.76 KB
/
dbsFilegen_8_19_2016.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
%% - 3-30-2016 - DJC - response timing file generator - updated 8-19-2016
% this script will generate two text files. One of these has the sample
% number at which each stimulus train will be delivered. the second has the
% condition which should be read in
prompt = {'Enter subject name','What is the range of ITI?', 'What is the sample rate of the TDT?','Number Of Trials Per Voltage?','How many stimulation Conditions?','Which file number is this?'};
dlg_title = 'Input';
num_lines = 1;
defaultans = {'DBS','[2.25,2.75]','48828.125','15','4','1'};
answer = inputdlg(prompt,dlg_title,num_lines,defaultans);
sid = answer{1};
ITI = str2num(answer{2});
fs = str2num(answer{3});
numTrials = str2num(answer{4});
stimConds = str2num(answer{5});
fileNum = answer{6};
%% make the timing file
% add 500 ms to the ITI times to account for the 500 ms pulse trains - then
% 2500 off
ITIlo = ITI(1)+0.5;
ITIhi = ITI(2)+0.5;
% number of trials for each voltage - 30.
% so 30 * 6 ?
randTimes = unifrnd(ITIlo,ITIhi,stimConds*numTrials,1);
% here the vector is converted to the sample number where the stimulus
% train should start to be delivered
sample = 1; % start with sample 1
pts = [];
for i = 1:length(randTimes)
sample = floor(sample + randTimes(i)*fs);
pts = [pts; sample];
end
%% make the conditions file
stimRand = [];
for i = 1:numTrials
stimRand = [stimRand randperm(stimConds)];
end
%% write these times to file for stim train delivery
filename = sprintf('%s_stimTrainDelivery_%s.txt',sid,fileNum);
fileID = fopen(filename,'w+');
fprintf(fileID,'%d\r\n',pts);
fclose(fileID);
%% write these times to file for condition
filename = sprintf('%s_condition_%s.txt',sid,fileNum);
fileID = fopen(filename,'w+');
fprintf(fileID,'%d\r\n',stimRand);
fclose(fileID);