-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bike_ERSPs.m
405 lines (355 loc) · 15.4 KB
/
Bike_ERSPs.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
clear all
close all
% -------------------------------------------------------------------------
%
% -------------------------------------------------------------------------
%% Input Information
exp = 'Bike2';
% *************************************************************************
subs = {'100' '101' '102' '103' '104' '106' '107' '108' '110' '114'...
'115' '116' '117' '118' '119' '120' '121' '123' '126' '127'...
'128' '129' '130' '131' '132' '133' '134' '135' '136'};
nsubs = length(subs);
% *************************************************************************
conds = {'sask' '110st' '83ave'};
nconds = length(conds);
% *************************************************************************
Pathname = 'M:\Data\Bike_lanes\';
% Location of electrode information
electrode_loc = 'M:\Analysis\Skateboard\Skate_Vamp_Active_16.ced';
% *************************************************************************
% A few electrodes
electrode = [13 15];
elec_names = {'Fz';'Pz'};
% Multiple electrodes
% electrode = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15];
% elec_names = {'Oz';'P7';'T7';'P3';'C3';'F3';'Pz';'Cz';'Fz';'P4';'C4';'F4';'P8';'T8';'FP2'};
% *************************************************************************
% Pick the type of trials
% 1 = standards
% 2 = targets
% 3 = standards and targets
perms = 3;
trialevent = {'Standards';'Targets'};
%trialevent = {'Standards'};
%trialevent = {'Targets'};
% *************************************************************************
% If using eeglab to plot ersp
elab_plot = 'Off'; % No
% *************************************************************************
% Set baseline
baseln = [-1000 -500];
%baseln = [NaN];
% *************************************************************************
[ALLEEG EEG CURRENTSET ALLCOM] = eeglab;
%time frequency parameters
tf_epochslim = [-1 1.9];
tf_cycles = 3;
dum1 = [];
dum2 = [];
timesout = 200;
analfreq = [4 20];
pratio = 8; %not using it for now. DR
%
%-------------------------------------------------------------------------
%% TF Analysis
% -------------------------------------------------------------------------
% clear ersp freqs itc powbase times
i_count = 0;
for i_sub = 1:nsubs
for i_cond = 1:nconds
i_count = i_count + 1; % counter to select data from ALLEEG
Filename = [subs{i_sub} '_' exp '_' conds{i_cond}];
if perms == 1 % Load standards data
EEG = pop_loadset('filename',[Filename '_Corrected_Standard.set'],'filepath','M:\Data\Bike_lanes\segmentsFFT\');
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
for i_chan = 1:length(electrode)
EEG = eeg_checkset(EEG);
% Caption if creating plots with pop_newtimef
% i_cap = strcat(exp, '_', subs(i_sub), '_', elec_names(i_chan),...
% '_', conds(i_cond));
% If plotting with the pop_newtimef function
if strcmp(elab_plot, 'Yes')
figure
end
% FFT with output ersp & itc in the order of each subj, cond,
% trial type (perm), and channel.
[ersp(i_sub,i_cond,1,i_chan,:,:),itc(i_sub,i_cond,1,i_chan,:,:),powbase,times,freqs] =...
pop_newtimef(EEG, 1, i_chan, tf_epochslim*1000, tf_cycles, 'topovec', i_chan,...
'elocs', EEG.chanlocs, 'chaninfo', EEG.chaninfo, 'baseline', baseln,...
'freqs', analfreq, 'plotersp', elab_plot, 'plotitc', elab_plot,...
'padratio', pratio, 'timesout', timesout);
end
elseif perms == 2 % Load targets data
EEG = pop_loadset('filename',[Filename '_Corrected_Target.set'],'filepath','M:\Data\Bike_lanes\segmentsFFT\');
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
for i_chan = 1:length(electrode)
EEG = eeg_checkset(EEG);
% Caption if creating plots with pop_newtimef
% i_cap = strcat(exp, '_', subs(i_sub), '_', elec_names(i_chan),...
% '_', conds(i_cond));
% If plotting with the pop_newtimef function
if strcmp(elab_plot, 'Yes')
figure
end
% FFT with output ersp & itc in the order of each subj, cond,
% trial type (perm), and channel.
[ersp(i_sub,i_cond,1,i_chan,:,:),itc(i_sub,i_cond,1,i_chan,:,:),powbase,times,freqs] =...
pop_newtimef(EEG, 1, i_chan, tf_epochslim*1000, tf_cycles, 'topovec', i_chan,...
'elocs', EEG.chanlocs, 'chaninfo', EEG.chaninfo, 'baseline', baseln,...
'freqs', analfreq, 'plotphase', 'Off', 'plotersp', elab_plot,...
'plotitc', elab_plot, 'padratio', pratio, 'timesout', timesout);
end
elseif perms == 3
% Load standards data
EEG = pop_loadset('filename',[Filename '_Corrected_Standard.set'],'filepath','M:\Data\Bike_lanes\segmentsFFT\');
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
for i_chan = 1:length(electrode)
EEG = eeg_checkset(EEG);
% Caption if creating plots with pop_newtimef
% i_cap = strcat(exp, '_', subs(i_sub), '_', elec_names(i_chan),... commented this out for now DR
% '_', conds(i_cond));
% If plotting with the pop_newtimef function
if strcmp(elab_plot, 'Yes')
figure
end
% FFT with output ersp & itc in the order of each subj, cond,
% trial type (perm), and channel.
[ersp(i_sub,i_cond,1,i_chan,:,:),itc(i_sub,i_cond,1,i_chan,:,:),powbase,times,freqs] =...
pop_newtimef(EEG, 1, i_chan, tf_epochslim*1000, tf_cycles, 'topovec', i_chan,...
'elocs', EEG.chanlocs, 'chaninfo', EEG.chaninfo, 'baseline', baseln,...
'freqs', analfreq, 'plotphase', 'Off', 'plotersp', elab_plot,...
'plotitc', elab_plot, 'padratio', pratio, 'timesout', timesout);
end
% Load targets data
EEG = pop_loadset('filename',[Filename '_Corrected_Target.set'],'filepath','M:\Data\Bike_lanes\segmentsFFT\');
[ALLEEG, EEG, CURRENTSET] = eeg_store( ALLEEG, EEG, 0 );
for i_chan = 1:length(electrode)
EEG = eeg_checkset(EEG);
% Caption if creating plots with pop_newtimef
% i_cap = strcat(exp, '_', subs(i_sub), '_', elec_names(i_chan),...
% '_', conds(i_cond));
% If plotting with the pop_newtimef function
if strcmp(elab_plot, 'Yes')
figure
end
% FFT with output ersp & itc in the order of each subj, cond,
% trial type (perm), and channel.
[ersp(i_sub,i_cond,2,i_chan,:,:),itc(i_sub,i_cond,2,i_chan,:,:),powbase,times,freqs] =...
pop_newtimef(EEG, 1, i_chan, tf_epochslim*1000, tf_cycles, 'topovec', i_chan,...
'elocs', EEG.chanlocs, 'chaninfo', EEG.chaninfo, 'baseline', baseln,...
'freqs', analfreq, 'plotphase', 'Off', 'plotersp', elab_plot,...
'plotitc', elab_plot, 'padratio', pratio, 'timesout', timesout);
end
end
end
end
eeglab redraw
%
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% PLOTTING SPECTRA WITHOUT CALLING THE FUNCTION
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% ERSP plots averaged over subjects for each channels
CLim = [-1.5 1.5];
electrode = [13 15];
for i_event = 1:length(trialevent)
for ch_ersp = 1:length(electrode)
% ERSP values by electrode
% (participants x conditions x events x electrodes x frequencies x timepoints)
ersp_sask = squeeze(mean(ersp(:,1,i_event,ch_ersp,:,:),1));
ersp_110 = squeeze(mean(ersp(:,2,i_event,ch_ersp,:,:),1));
ersp_83 = squeeze(mean(ersp(:,3,i_event,ch_ersp,:,:),1));
figure;
colormap(redblue)
% Subplot 1: Sask
subplot(3,1,1);
imagesc(times,freqs,ersp_sask,CLim);
title({['ERSP: ' char(trialevent{i_event}) ', Sask Drive']; char(elec_names(ch_ersp))});
set(gca,'Ydir','Normal')
line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
ylabel('Freq (Hz)');
colorbar
% Subplot 1: 110
subplot(3,1,2);
imagesc(times,freqs,ersp_110,CLim);
title({['ERSP: ' char(trialevent{i_event}) ', 110 St']; char(elec_names(ch_ersp))});
set(gca,'Ydir','Normal')
line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
ylabel('Freq (Hz)');
colorbar
% Subplot 1: out-in
subplot(3,1,3);
imagesc(times,freqs,ersp_83,CLim);
title({['ERSP: ' char(trialevent{i_event}) ', 83 Av']; char(elec_names(ch_ersp))});
set(gca,'Ydir','Normal')
line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
ylabel('Freq (Hz)'); xlabel('Time (ms)');
colorbar
%Overall subplot title
% supertitle(['ERSP: ' char(elec_names(ch_ersp))],'FontSize',12)
%clear in_ersp_chan out_ersp_chan
end
%clear ch_ersp
end
clear i_event
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%PLOTS USING DIFFERENCE ERSPS %continue here
%
% TARGETS(2) - STANDARDS(1)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
electrode = 1; %loaded 2 electrodes only. 2 = Pz
%(participants x conditions x events x electrodes x frequencies x timepoints)
%standards
stan_sask = squeeze(mean(ersp(:,1,1,electrode,:,:),1));
stan_110 = squeeze(mean(ersp(:,2,1,electrode,:,:),1));
stan_83 = squeeze(mean(ersp(:,3,1,electrode,:,:),1));
%targets
targ_sask = squeeze(mean(ersp(:,1,2,electrode,:,:),1));
targ_110 = squeeze(mean(ersp(:,2,2,electrode,:,:),1));
targ_83 = squeeze(mean(ersp(:,3,2,electrode,:,:),1));
%targets-standards
diff_ersp_sask = targ_sask - stan_sask;
diff_ersp_110 = targ_110 - stan_110;
diff_ersp_83 = targ_83 - stan_83;
CLim = [-1.5 1.5];
figure;
colormap('redblue')
% Subplot 1: sask
subplot(3,1,1);
imagesc(times,freqs,diff_ersp_sask,CLim);
title('ERSP:Targ-Stan, Sask Dr');
set(gca,'Ydir','Normal')
line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
line([min(times) max(times)],[12 12],'Color','k','LineStyle','--','LineWidth',.1)
ylabel('Freq (Hz)');
colorbar
% Subplot 2: 110
subplot(3,1,2);
imagesc(times,freqs,diff_ersp_110,CLim);
title('ERSP:Targ-Stan, 110 St');
set(gca,'Ydir','Normal')
line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
line([min(times) max(times)],[12 12],'Color','k','LineStyle','--','LineWidth',.1)
ylabel('Freq (Hz)');
colorbar
% Subplot 3: 83 ave
subplot(3,1,3);
imagesc(times,freqs,diff_ersp_83,CLim);
title('ERSP:Targ-Stand, 83 Ave');
set(gca,'Ydir','Normal')
line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
line([min(times) max(times)],[12 12],'Color','k','LineStyle','--','LineWidth',.1)
ylabel('Freq (Hz)'); xlabel('Time (ms)');
colorbar
clear line
clear electrode
%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
% EXPLORATORY CODE
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %% *******************************************************************************
% % THETA PLOTS
%
% pref_ersp_stand_fz = squeeze(mean(mean(ersp(:,[1,2],1,1,:,:),1),2));
% pref_ersp_targ_fz = squeeze(mean(mean(ersp(:,[1,2],2,1,:,:),1),2));
% pref_ersp_dif_fz = squeeze(pref_ersp_targ_fz-pref_ersp_stand_fz);
%
% npref_ersp_stand_fz = squeeze(mean(mean(ersp(:,[3,4],1,1,:,:),1),2));
% npref_ersp_targ_fz = squeeze(mean(mean(ersp(:,[3,4],2,1,:,:),1),2));
% npref_ersp_dif_fz = squeeze(npref_ersp_targ_fz-npref_ersp_stand_fz);
%
%
% CLim = [-1.5 1.5];
% figure;
% colormap('jet')
%
% % Subplot 1: pref
% subplot(3,1,1);
% imagesc(times,freqs,pref_ersp_stand_fz,CLim);
% title('ERSP:Standards, Preferred @Fz');
% set(gca,'Ydir','Normal')
% line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
% line([min(times) max(times)],[4 4],'Color','k','LineStyle','--','LineWidth',.1)
% line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
% ylabel('Freq (Hz)');
% colorbar
% % Subplot 1: in
% subplot(3,1,2);
% imagesc(times,freqs,pref_ersp_targ_fz,CLim);
% title('ERSP:Targets, Preferred');
% set(gca,'Ydir','Normal')
% line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
% line([min(times) max(times)],[4 4],'Color','k','LineStyle','--','LineWidth',.1)
% line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
% ylabel('Freq (Hz)');
% colorbar
% % Subplot 1: out-in
% subplot(3,1,3);
% imagesc(times,freqs,pref_ersp_dif_fz,CLim);
% title('ERSP:Targets-Standards, Preferred');
% set(gca,'Ydir','Normal')
% line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
% line([min(times) max(times)],[4 4],'Color','k','LineStyle','--','LineWidth',.1)
% line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
% ylabel('Freq (Hz)'); xlabel('Time (ms)');
% colorbar
%
% %NON-PREF
% CLim = [-1.5 1.5];
% figure;
% colormap('jet')
%
% % Subplot 1: pref
% subplot(3,1,1);
% imagesc(times,freqs,npref_ersp_stand_fz,CLim);
% title('ERSP:Standards, Non Preferred @ Fz');
% set(gca,'Ydir','Normal')
% line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
% line([min(times) max(times)],[4 4],'Color','k','LineStyle','--','LineWidth',.1)
% line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
% ylabel('Freq (Hz)');
% colorbar
% % Subplot 1: in
% subplot(3,1,2);
% imagesc(times,freqs,npref_ersp_targ_fz,CLim);
% title('ERSP:Targets, Non Preferred');
% set(gca,'Ydir','Normal')
% line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
% line([min(times) max(times)],[4 4],'Color','k','LineStyle','--','LineWidth',.1)
% line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
% ylabel('Freq (Hz)');
% colorbar
% % Subplot 1: out-in
% subplot(3,1,3);
% imagesc(times,freqs,npref_ersp_dif_fz,CLim);
% title('ERSP:Targets-Standards, Non Preferred');
% set(gca,'Ydir','Normal')
% line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
% line([min(times) max(times)],[4 4],'Color','k','LineStyle','--','LineWidth',.1)
% line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
% ylabel('Freq (Hz)'); xlabel('Time (ms)');
% colorbar
%
% pnp_grand_diff_fz = squeeze(pref_ersp_dif_fz-npref_ersp_dif_fz);
% figure
% subplot(3,1,1);
% imagesc(times,freqs,pnp_grand_diff_fz,CLim);
% title('ERSP:Preferred-Unpreferred, Target-Standards');
% set(gca,'Ydir','Normal')
% line([0 0],[min(freqs) max(freqs)],'Color','m','LineStyle','--','LineWidth',1.5)
% line([min(times) max(times)],[4 4],'Color','k','LineStyle','--','LineWidth',.1)
% line([min(times) max(times)],[8 8],'Color','k','LineStyle','--','LineWidth',.1)
% ylabel('Freq (Hz)'); xlabel('Time (ms)');
% colorbar