|
1 |
| -% THe basic idea was to base the code off of the categorizetrials.m file, but make a few |
| 1 | +% The basic idea was to base the code off of the categorizetrials.m file, but make a few |
2 | 2 | % adjustments to pull at error trials. The types of errors was split into 2 types: the monkey
|
3 | 3 | % pulling the lever for no reason, and the monkey failing to respond to the odd stimulus of the
|
4 | 4 | % specified type. Using the same structure as categorizetrials.m, the data was stored the stimcount
|
|
9 | 9 |
|
10 | 10 | datadir = 'C:/Users/Felicity/macaqueERP/data/raw/R7475/';
|
11 | 11 | addpath(datadir) % So X_loadcnt() is available
|
12 |
| -outfile='tmp.mat'; % Output filename |
13 |
| -dosave = 0; % Whether or not to save |
| 12 | +outfile='C:/Users/Felicity/macaqueERP/data/errordata.mat'; % Output filename |
| 13 | +dosave = 1; % Whether or not to save |
14 | 14 | oldrate=2000; % Sampling rate in Hz
|
15 | 15 | epochstart=-0.2; % Start of epoch in s
|
16 | 16 | epochend=0.4; % End of epoch in s
|
|
25 | 25 | %% 1. Loading data
|
26 | 26 |
|
27 | 27 | allfiles=dir([datadir '*.cnt']); % Get all file names
|
28 |
| -% nfiles=length(allfiles); |
29 |
| -nfiles = 1; |
| 28 | +nfiles=length(allfiles); |
| 29 | +% nfiles = 1; |
30 | 30 |
|
31 | 31 |
|
32 |
| -for Z=1:1 % Loop over files (stay as 1 just for error checking) |
| 32 | +for Z=1:nfiles % Loop over files (stay as 1 just for error checking) |
33 | 33 | fprintf('\nLoading file %i of %i (%s)...\n',Z,nfiles,allfiles(Z).name)
|
34 | 34 | tmpdata=X_loadcnt(allfiles(Z).name);
|
35 | 35 | origdata=tmpdata.data'; % Pull out the interesting array and transpose it
|
|
40 | 40 | xaxis=(0:length(origdata)-1)/oldrate; % Set up an x-axis to plot everything
|
41 | 41 |
|
42 | 42 | labels={'Auditory target (green: lever)','Visual target (green: lever)'};
|
43 |
| - levertimes=diff(origdata(:,61)); levertimes=find(levertimes>200)/oldrate; % Pull out lever times |
| 43 | + levertimes=diff(origdata(:,61)); levertimes=find(levertimes>200); % Pull out lever times |
44 | 44 | npulls=length(levertimes); % How many times the monkey pulled the lever
|
45 |
| - audodd=diff(origdata(:,58)); audodd=find(audodd<-200)/oldrate; % Pull out auditory oddball stimuli |
46 |
| - visodd=diff(origdata(:,60)); visodd=find(visodd<-200)/oldrate; % Pull out visual oddball stimuli |
| 45 | + audodd=diff(origdata(:,58)); audodd=find(audodd<-200); % Pull out auditory oddball stimuli |
| 46 | + visodd=diff(origdata(:,60)); visodd=find(visodd<-200); % Pull out visual oddball stimuli |
47 | 47 | audpositive=0;
|
48 | 48 | vispositive=0;
|
49 | 49 |
|
50 | 50 |
|
51 | 51 | % Time to find the errors
|
52 | 52 |
|
53 | 53 | % First, find the errors for using the lever for no reason.
|
54 |
| - errorlevertimes = zeros(50, 1); % store the times in row vector |
55 |
| - levercounting = 0 % to get the position in vector (also count errors) |
| 54 | + errorlevertimes = zeros(1, 30); % store the times in row vector |
| 55 | + levercounting = 0; % to get the position in vector (also count errors) |
56 | 56 |
|
57 | 57 | for i=1:length(levertimes)
|
58 | 58 | tmpaud=levertimes(i)-audodd; % Find the time difference between the lever press and the stimuli
|
59 | 59 | tmpvis=levertimes(i)-visodd; % Find the time difference between the lever press and the stimuli
|
60 |
| - tmpaud=tmpaud(tmpaud>0.05 & tmpaud<1.2); % Give it between 100 ms and 1 s to respond |
61 |
| - tmpvis=tmpvis(tmpvis>0.05 & tmpvis<1.2); % Give it between 100 ms and 1 s to respond |
| 60 | + tmpaud=tmpaud(tmpaud>0.05*oldrate & tmpaud<1.2*oldrate); % Give it between 100 ms and 1 s to respond |
| 61 | + tmpvis=tmpvis(tmpvis>0.05*oldrate & tmpvis<1.2*oldrate); % Give it between 100 ms and 1 s to respond |
62 | 62 |
|
63 | 63 | if isempty(tmpvis)&&isempty(tmpaud)
|
64 | 64 | levercounting = levercounting + 1;
|
65 |
| - errorlevertimes(levercounting) = levertimes(i); |
| 65 | + errorlevertimes(1, levercounting) = levertimes(i); |
66 | 66 | end
|
67 | 67 | end
|
68 | 68 | fprintf('%d errors for pulling lever for no reason\n', levercounting)
|
69 | 69 |
|
70 | 70 |
|
71 | 71 | % Next, find the errors (assuming audio-attend) for not responding to odd auditory stimulus
|
72 | 72 | audcounting = 0;
|
73 |
| - erroraudtimes = zeros(50, 1); |
| 73 | + erroraudtimes = zeros(1, 30); |
74 | 74 | for i = 1:length(audodd)
|
75 | 75 | diffaud = levertimes-audodd(i);
|
76 |
| - diffaud = diffaud(diffaud>0.05 & diffaud<1.2); |
| 76 | + diffaud = diffaud(diffaud>0.05*oldrate & diffaud<1.2*oldrate); |
77 | 77 | if isempty(diffaud)
|
78 | 78 | audcounting = audcounting + 1;
|
79 |
| - erroraudtimes(audcounting) = audodd(i); |
| 79 | + erroraudtimes(1, audcounting) = audodd(i); |
80 | 80 | end
|
81 | 81 | end
|
82 | 82 |
|
83 | 83 |
|
84 | 84 | % Then, find the errors (assuming visual-attend) for not responding to odd visual stimulus
|
85 | 85 | viscounting = 0;
|
86 |
| - errorvistimes = zeros(500, 1); |
| 86 | + errorvistimes = zeros(1, 30); |
87 | 87 | for i = 1:length(visodd)
|
88 | 88 | diffvis = levertimes-visodd(i);
|
89 |
| - diffvis = diffvis(diffvis>0.05 & diffvis<1.2); |
| 89 | + diffvis = diffvis(diffvis>0.05*oldrate & diffvis<1.2*oldrate); |
90 | 90 | if isempty(diffvis)
|
91 | 91 | viscounting = viscounting + 1;
|
92 |
| - errorvistimes(viscounting) = visodd(i); |
| 92 | + errorvistimes(1, viscounting) = visodd(i); |
93 | 93 | end
|
94 | 94 | end
|
95 | 95 |
|
|
99 | 99 | if viscounting > audcounting
|
100 | 100 | fprintf('%d errors for failing to respond to odd auditory stimulus\n', audcounting);
|
101 | 101 |
|
102 |
| - A = 1 % A= 1 means we are attending audio |
103 |
| - errortimes = [errorlevertimes; erroraudtimes] |
| 102 | + A = 1; % A= 1 means we are attending audio |
| 103 | + errortimes = [errorlevertimes; erroraudtimes]; |
104 | 104 | elseif audcounting > viscounting
|
105 | 105 | fprintf('%d errors for failing to respond to odd visual stimulus\n', viscounting);
|
106 |
| - A = 2 % A= 2 means we are attending visual |
107 |
| - errortimes = [errorlevertimes; errorvistimes] |
| 106 | + A = 2; % A= 2 means we are attending visual |
| 107 | + errortimes = [errorlevertimes; errorvistimes]; |
108 | 108 |
|
109 | 109 | else
|
110 | 110 | disp('Monkey confused about which stimulus to attend to\n');
|
111 | 111 | A=input('Auditory (1) or visual (2)? ');
|
112 | 112 | if A == 1
|
113 |
| - errortimes = [errorlevertimes; erroraudtimes] |
| 113 | + errortimes = [errorlevertimes; erroraudtimes]; |
114 | 114 | fprintf('%d errors for failing to respond to odd auditory stimulus\n', audcounting);
|
115 | 115 | else
|
116 |
| - errortimes = [errorlevertimes; errorvistimes] |
| 116 | + errortimes = [errorlevertimes; errorvistimes]; |
117 | 117 | fprintf('%d errors for failing to respond to odd visual stimulus\n', viscounting);
|
118 | 118 | end
|
119 | 119 | end
|
120 |
| - |
| 120 | + |
121 | 121 | % Now begin to collate the data into a nice structure thing
|
122 | 122 |
|
123 | 123 | for Q=1:2 % Loop over V4 vs. IT
|
|
142 | 142 | end
|
143 | 143 |
|
144 | 144 | %% 3. Split the data up into trials
|
145 |
| - trialtypes={'no stimulus','no lever reponse'}; % Trial types -- audio no stim, audio no response, visno stim , vis no response |
| 145 | + trialtypes={'nostimulus','noleverresponse'}; % Trial types -- audio no stim, audio no response, visno stim , vis no response |
146 | 146 | ntypes=length(trialtypes);
|
147 | 147 | nchannels=length(channels);
|
148 | 148 | npts=ceil((epochend-epochstart)*newrate); % Number of points in each trial window
|
|
160 | 160 | % totalpts=length(thisstim); % Total number of data points
|
161 | 161 | % stimdiff=diff(thisstim); % Detect changes in the stimuli
|
162 | 162 | % stimtimes=find(stimdiff<-200); % Changes are huge decreases (~-500) in the stim time series
|
163 |
| - totalpts = length(xaxis) |
164 |
| - stimtimes = errortimes(i) |
| 163 | + totalpts = length(origdata(:, 57)); |
| 164 | + stimtimes = errortimes(i, :); |
| 165 | + |
165 | 166 | stimtimes=stimtimes(stimtimes>oldptsbefore & stimtimes<(totalpts-oldptsafter)); % Remove stimuli that are too close to the beginning or end of the recording
|
| 167 | + stimtimes = stimtimes(stimtimes ~=0); |
166 | 168 | nstims=length(stimtimes); % Number of stimuli
|
167 |
| - |
168 | 169 | % Set up the array to store results in
|
169 | 170 | if Z==1, data{A,Q}.(trialtypes{i})=zeros(nchannels,3000,npts); end % Set up array if not set up before, 3000 is arbitrary to make it big enough
|
170 | 171 |
|
171 | 172 | % Pull out the corresponding data
|
172 | 173 | for j=1:nchannels
|
173 | 174 | for k=1:nstims
|
174 | 175 | stimcount(A,Q,i,j)=stimcount(A,Q,i,j)+1; % Total number of stimuli -- sum over files (Z) and k but nothing else
|
175 |
| - thisdata=origdata(stimtimes(k)*oldrate-oldptsbefore:stimtimes(k)*oldrate+oldptsafter+oldrate/newrate,channels(Q,j)); |
| 176 | + thisdata=origdata(stimtimes(k)-oldptsbefore:stimtimes(k)+oldptsafter,channels(Q,j)); |
176 | 177 | % Pull out the data; oldrate/newrate is to give one extra data point. Also need to *stimtimes by old rate to get correct numbers
|
177 |
| - tmp=downsample(thisdata,oldrate,newrate); % Downsample to the desired rate |
| 178 | + |
| 179 | + tmp=downsample(thisdata,oldrate/newrate); % Downsample to the desired rate |
178 | 180 | data{A,Q}.(trialtypes{i})(j,stimcount(A,Q,i,j),:)=tmp; % Append to entire array
|
179 | 181 | end
|
180 | 182 | end
|
181 | 183 | end
|
182 | 184 | end
|
183 | 185 | end
|
184 | 186 |
|
185 |
| -disp('Done'); |
| 187 | +for A=1:2 |
| 188 | + for Q=1:2 |
| 189 | + for i=1:ntypes |
| 190 | + data{A,Q}.(trialtypes{i})=data{A,Q}.(trialtypes{i})(:,1:stimcount(A,Q,i,1),:); % Trim extra "rows" |
| 191 | + end |
| 192 | + end |
| 193 | +end |
| 194 | + |
| 195 | +if dosave |
| 196 | + fprintf('\nSaving data...\n') |
| 197 | + save(outfile,'data') % Save data |
| 198 | + disp('...done.') |
| 199 | +end |
| 200 | + |
| 201 | +% checkplot = data{2,1}; |
| 202 | +% xdata = checkplot.xaxis; |
| 203 | +% meanydata = squeeze(mean(checkplot.noleverresponse(2,1,:),2)); |
| 204 | +% plot(xdata,meanydata) |
| 205 | +% xlabel('Time (s)') |
| 206 | +% ylabel('Voltage (\muV)') |
| 207 | +% |
| 208 | +% disp('Done'); |
0 commit comments