/
Extract_for_R_BigDots_stim_locked_beta_TSE.m
204 lines (169 loc) · 7.51 KB
/
Extract_for_R_BigDots_stim_locked_beta_TSE.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
%%% runafew
clear
close all
clc
%%
% path_temp = 'S:\R-MNHS-SPP\Bellgrove-data\4. Dan Newman\Participant Folders_new\'; %Monash PC
path_temp = 'C:\Users\Dan\Desktop\Big_Dots_Data\';
%%
subject_folder = {'LK_07_04_14','AR_08_04_14','MH_14_04_14','AA_15_04_14','NT_16_04_14', ...
'OF_28_04_14','RO_25_04_14','PR_20_04_14','AS_23_04_14','OM_07_05_14', ... % 10
'RM_06_05_14','SB_08_05_14','GW_09_05_14','OS_09_05_14','AC_13_05_14', ...
'ND_16_05_14','SF_20_05_14','TL_23_05_14','JC_23_05_14','EL_24_05_14', ... % 20
'SH_25_05_14','059M_HP','093M_BR','036M_JK','221M_SJ', ...
'068M_CB','301M_MO','118M_CS','265M_EZ','291M_KS', ... % 30
'106M_NH','302M_BS','289M_AS','303M_SA','103M_JK', ...
'314M_LK','226M_SM','037M_JD','338M_SC','091M_SW', ... % 40
'134M_JM','331M_CL','108M_CY','191M_DM','243M_JB', ...
'136M_JC','339M_YV','353M_AT','352M_MK','061M_LG', ... % 50
'235M_JM','374M_PP','325M_KR','279M_FT','114M_CS', ...
'378M_MG','133M_DC','392M_PH','186M_AF','404M_RO', ... % 60
'147M_EB','400M_ED','398M_LO','384M_PD','205M_LE', ...
'328M_EW','418M_AM','189M_WM','203M_VF','234M_SW', ... % 70
'220M_NB','377M_BL','427M_SS','414M_LA','458M_AH', ...
'439M_TM','484M_AI','453M_LB','422M_MK','323M_CZ','240M_FM'}; % 81
allsubj = {'LK','AR','MH','AA','NT','OF','RO','PR','AS','OM', ...
'RM','SB','GW','OS','AC','ND','SF','TL','JC','EL', ...
'SH','HP1M','BR2M','JK3M','SJ4M','CB5M','MO6M','CS7M','EZ8M','KS9M', ...
'NH10M','BS11M','AS12M','SA13M','JK14M','LK15M','SM16M','JD17M','SC18M','SW19M', ...
'JM20M','CL21M','CY22M','DM24M','JB25M','JC26M','YV27M','AT28M','MK29M','LG30M', ...
'JM31M','PP32M','KR33M','FT34M','CS35M','MG36M','DC37M','PH38M','AF39M','RO40M', ...
'EB41M','ED42M','LO43M','PD44M','LE45M','EW46M','AM47M','WM48M','VF49M','SW50M',...
'NB52M','BL53M','SS54M','LA55M','AH56M','TM57M','AI58M','LB59M','MK60M','CZ61M','FM51M'};
%%
TCD_bigdots = {'LK_07_04_14','AR_08_04_14','MH_14_04_14','AA_15_04_14','NT_16_04_14', ...
'OF_28_04_14','RO_25_04_14','PR_20_04_14','AS_23_04_14','OM_07_05_14', ...
'RM_06_05_14','SB_08_05_14','GW_09_05_14','OS_09_05_14','AC_13_05_14', ...
'ND_16_05_14','SF_20_05_14','TL_23_05_14','JC_23_05_14','EL_24_05_14', ...
'SH_25_05_14'};
Monash_bigdots = {'059M_HP','093M_BR','036M_JK','221M_SJ','068M_CB', ...
'118M_CS','265M_EZ','301M_MO','291M_KS','106M_NH', ...
'302M_BS','289M_AS','303M_SA','103M_JK','314M_LK', ...
'226M_SM','037M_JD','338M_SC','091M_SW','134M_JM', ...
'331M_CL','108M_CY','191M_DM','243M_JB','136M_JC', ...
'339M_YV','353M_AT','352M_MK','061M_LG','235M_JM', ...
'374M_PP','325M_KR','279M_FT','114M_CS','378M_MG','133M_DC', ...
'392M_PH','186M_AF','404M_RO','147M_EB','400M_ED','398M_LO', ...
'384M_PD','205M_LE','328M_EW','418M_AM','189M_WM','203M_VF','234M_SW',...
'220M_NB','377M_BL','427M_SS','414M_LA','458M_AH','439M_TM',...
'484M_AI','453M_LB','422M_MK','323M_CZ','240M_FM'};
%%
CSD=0; %Use Current Source Density transformed erp? 1=yes, 0=no
% ch_N2i = [23;27];
% ch_LR=ch_N2i;
% ch_N2c = [27;23]; % right hemi channels for left target, vice versa.
% ch_for_ipsicon(1,:) = [27;23];
% ch_for_ipsicon(2,:) = [23;27];
% ch_l = [23];
% ch_r = [27];
% ch_front = 5; %5=Fz
% ch_CPP = [53];%25=Pz; 53=CPz
ch_beta=[13];
fs=500;
% stim-locked erps
% ts = -0.500*fs:1.800*fs;
% t = ts*1000/fs;
ts = -0.700*fs:1.800*fs;
t = ts*1000/fs;
ts_crop = -0.500*fs:1.500*fs;
t_crop = ts_crop*1000/fs;
% resp-locked erps
trs = [-.700*fs:fs*.100];
tr = trs*1000/fs;
BL_erp = [-100,0];
BL_beta = [-100];
% patch,ITI
targcodes = zeros(2,3);
targcodes(1,1) = [101]; % patch 1, ITI 1
targcodes(2,1) = [102]; % patch 2, ITI 1
targcodes(1,2) = [103]; % patch 1, ITI 2
targcodes(2,2) = [104]; % patch 2, ITI 2
targcodes(1,3) = [105]; % patch 1, ITI 3
targcodes(2,3) = [106]; % patch 2, ITI 3
master_matrix_R = []; % This saves the matrix for SPSS/R analysis.
total_numtr = 0;
ID_vector=cell(32000,1); %this will save the subjects ID for each single trial can be pasted into SPSS for ID column. Code at the end of the script clear the emplt cells
%% beta filter
beta_bandlimits = [20,35]; % defining the filter for beta bandpass.
[H,G]=butter(4,[2*(beta_bandlimits(1)/fs) 2*(beta_bandlimits(2)/fs)]); % beta bandpass for 500Hz
window = 26; % in samples. Time is double this.
skip_step = window/2;
% beta time
beta_t=[]; cca=1;
for tt = 1:skip_step:length(t_crop)-window
beta_t(:,cca) = mean(t_crop(tt:tt+window-1));
cca=cca+1;
end
%%
mat_file='big_dots_erp.mat';
%%
current=1;
for s=1:length(allsubj)
disp(['Subject: ',num2str(s)])
disp(['Subject: ',allsubj{s}])
%% Load the participant's .mat file:
load([path_temp subject_folder{s} '\' allsubj{s} mat_file])
if strcmp(subject_folder{s},'331M_CL') % really odd tiny artifact meant this trial was messing with CSD!
allRT(53) = 0; allrespLR(53) = 0;
end
%%
if CSD
erp=double(erp_LPF_35Hz_CSD);
else
erp=double(erp_LPF_35Hz);
end
%% Baseline erp
baseline_erp = mean(erp(:,find(t>=BL_erp(1) & t<=BL_erp(2)),:),2);
erp = erp-repmat(baseline_erp,[1,size(erp,2),1]); % baseline full erp
%% beta Spectrotemporal Evolution (TSE) a la Thut
beta_TSE = [];
for trial = 1:size(erp,3)
% filtering to beta
ep_filt = filtfilt(H,G,squeeze(erp(:,:,trial))')';
% chop off ends and rectify
ep_filt = abs(ep_filt(:,find(t>=t_crop(1) & t<=t_crop(end))));
% smooth
cca=1;
for tt = 1:skip_step:size(ep_filt,2)-window
beta_TSE(:,cca,trial) = mean(ep_filt(:,tt:tt+window-1),2);
cca=cca+1;
end
end
% Baseline beta
baseline_beta = mean(beta_TSE(:,find(beta_t<=BL_beta),:),2);
beta_TSE_base = beta_TSE-repmat(baseline_beta,[1,size(beta_TSE,2),1]); % baseline full erp
%%
%if the final trial was a miss there will be no RT recorded, just need
%to add a zero for RT in that case
if length(allRT)<length(allrespLR)
allRT(length(allRT):length(allrespLR))=0;
end
allTrials=allTrig; % just renamed this because it makes more sense to me to call it trials
%% DN: master_matrix_R columns:
%1.Subject number; 2.total trial number; 3.inter-subject trial number;
%4.Time; % 5 Response Locked Beta
for trial=1:length(allTrials) % get rid of last trigger?
total_numtr = total_numtr+1;
ID_vector(current:current+(length(beta_t)-1)) = subject_folder(s);
%% 1. Subject number:
master_matrix_R(current:current+(length(beta_t)-1),1) = s;
%% 2. total trial number:
master_matrix_R(current:current+(length(beta_t)-1),2) = total_numtr;
%% 3. inter-subject trial number
master_matrix_R(current:current+(length(beta_t)-1),3) = trial;
%% 4. Time:
master_matrix_R(current:current+(length(beta_t)-1),4)=beta_t;
%% 5. Response Locked Beta TSE (Baselined)
master_matrix_R(current:current+(length(beta_t)-1),5)=beta_TSE_base(ch_beta,:, trial);
%% 6. Response Locked Beta TSE (NOT Baselined)
master_matrix_R(current:current+(length(beta_t)-1),6)=beta_TSE(ch_beta,:, trial);
current=current+length(beta_t);
end
end
% find empty cells in ID_vector
emptyCells = cellfun(@isempty,ID_vector);
% remove empty cells
ID_vector(emptyCells) = [];
%Save the data in .csv format to be read into R for inferential stats analysis
csvwrite (['master_matrix_R_Stim_locked_beta_TSE.csv'],master_matrix_R)
cell2csv ('ID_vector_Stim_locked_beta_TSE.csv',ID_vector)