-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASSR_LI_power.m
249 lines (215 loc) · 9.94 KB
/
ASSR_LI_power.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
%% get data for seperate powers
left_assr39_noVR = [];
left_assr41_noVR = [];
right_assr39_noVR = [];
right_assr41_noVR = [];
% data structure: data{sub, block}{left/right, 39/41}
for i = 1:length(assrMI_data_VR(:,1))
for j = 1:length(assrMI_data_VR(1,:))
left_assr39_noVR = [left_assr39_noVR; mean(cell2mat(assrPOW_data_noVR{i,j}{1,1}),1)];
left_assr41_noVR = [left_assr41_noVR; mean(cell2mat(assrPOW_data_noVR{i,j}{1,2}),1)];
right_assr39_noVR = [right_assr39_noVR; mean(cell2mat(assrPOW_data_noVR{i,j}{2,1}),1)];
right_assr41_noVR = [right_assr41_noVR; mean(cell2mat(assrPOW_data_noVR{i,j}{2,2}),1)];
end
end
%% take middle 60% to only look at curves
index_of_20percent = round(length(left_assr39_noVR()) * 0.20); % same indices can be used for all data, since length should be the same after timewarping
index_of_80percent = round(length(left_assr39_noVR) * 0.80); % same indices can be used for all data, since length should be the same after timewarping
left_assr39_noVR = left_assr39_noVR(:,index_of_20percent:index_of_80percent);
left_assr41_noVR = left_assr41_noVR(:,index_of_20percent:index_of_80percent);
right_assr39_noVR = right_assr39_noVR(:,index_of_20percent:index_of_80percent);
right_assr41_noVR = right_assr41_noVR(:,index_of_20percent:index_of_80percent);
%% stats for ASSR powers
% create struct for fieldtrip
datastr = [];
datastr.individual = zeros(length(left_assr39_noVR(:,1)), 1, length(left_assr39_noVR));
datastr.time = EEG_39_warped_left.times(:,index_of_20percent:index_of_80percent);
datastr.label = {'N1'};
left39 = datastr;
left39.individual(:,1,:) = left_assr39_noVR;
left41 = datastr;
left41.individual(:,1,:) = left_assr41_noVR;
right39 = datastr;
right39.individual(:,1,:) = right_assr39_noVR;
right41 = datastr;
right41.individual(:,1,:) = right_assr41_noVR;
% run test
lengths = length(left_assr39_noVR(:,1));
cfg = [];
cfg.parameter = 'individual';
cfg.latency = 'all'; %[-2 2];
cfg.method = 'montecarlo';
cfg.statistic = 'depsamplesT';
cfg.alpha = 0.05;
cfg.correcttail = 'prob';
cfg.numrandomization = 1000;
cfg.correctm = 'cluster';
cfg.design(1:2*lengths, 1) = [ones(lengths, 1); 2*ones(lengths, 1)];
cfg.design(1:2*lengths, 2) = [repelem(1:6, 1, 1)'; repelem(1:6, 1, 1)'];
cfg.design = cfg.design';
cfg.ivar = 1; % the 1st row in cfg.design contains the independent variable
cfg.uvar = 2; % the 2nd row in cfg.design contains the subject number
stat_left = ft_timelockstatistics(cfg, left39, left41);
stat_right = ft_timelockstatistics(cfg, right39, right41);
%% Prepare plot for seperate powers
% zscore
assrPOW39_left_zscore = zscore(mean(left_assr39_noVR, 1));
assrPOW39_right_zscore = zscore(mean(right_assr39_noVR, 1));
assrPOW41_left_zscore = zscore(mean(left_assr41_noVR, 1));
assrPOW41_right_zscore = zscore(mean(right_assr41_noVR, 1));
% Find the minimum value for each variable
min_values_left39 = min(assrPOW39_left_zscore);
min_values_left41= min(assrPOW41_left_zscore);
min_values_right39 = min(assrPOW39_right_zscore);
min_values_right41 = min(assrPOW41_right_zscore);
% Subtract the minimum value from each variable
assrPOW39_left_zscore = assrPOW39_left_zscore - min(min_values_left39);
assrPOW41_left_zscore = assrPOW41_left_zscore - min(min_values_left41);
assrPOW39_right_zscore = assrPOW39_right_zscore - min(min_values_right39);
assrPOW41_right_zscore = assrPOW41_right_zscore - min(min_values_right41);
%% ASSR powers separately
hFig = figure; % Create a figure
screenSize = get(0, 'ScreenSize'); % Get the screen size
set(hFig, 'Position', screenSize);
% Define the new x-values range
new_x_values = linspace(3045.2, 12180.8, length(left_assr39_noVR));
% Define the custom x-axis tick positions and labels
custom_xticks = [min(new_x_values), mean(new_x_values), max(new_x_values)];
custom_xticklabels = {'Curve Entry', 'Curve Apex', 'Curve Exit'};
% ASSR Powers left
% subplot(2, 2, 1)
figure;
x_values_left = 1:length(mean(left_assr39_noVR, 1));
y_values_left = left_assr39_noVR;
plot(new_x_values, y_values_left,'--', 'LineWidth', 1, 'Color', [0.4, 0.4, 1]);
hold on;
x_values_left = 1:length(mean(left_assr39_noVR , 1));
y_values_left = mean(left_assr39_noVR , 1);
plot(new_x_values, y_values_left, 'LineWidth', 2, 'Color', 'blue');
hold on;
x_values_left = 1:length(mean(left_assr39_noVR , 1));
y_values_left = -left_assr41_noVR ;
plot(new_x_values, y_values_left, '--', 'LineWidth', 1, 'Color', [1, 0.4, 0.4]);
hold on;
x_values_left = 1:length(mean(left_assr41_noVR , 1));
y_values_left = -mean(left_assr41_noVR , 1);
plot(new_x_values, y_values_left, 'LineWidth', 2, 'Color', 'red');
grid on;
title('ASSR powers turning left');
% Set custom x-axis tick labels
xticks(custom_xticks);
xticklabels(custom_xticklabels);
xlim([min(new_x_values), max(new_x_values)]);
ylim([-0.15 0.15]);
ylabel('µV²/Hz');
% ASSR Powers right
figure;
% subplot(2, 2, 2)
x_values_right = 1:length(mean(right_assr39_noVR, 1));
y_values_right = right_assr39_noVR;
plot(new_x_values, y_values_right, '--', 'LineWidth', 1, 'Color', [0.4, 0.4, 1]);
hold on;
x_values_right = 1:length(mean(right_assr39_noVR , 1));
y_values_right = mean(right_assr39_noVR , 1);
plot(new_x_values, y_values_right, 'LineWidth', 2, 'Color', 'blue');
hold on;
x_values_right = 1:length(mean(right_assr39_noVR , 1));
y_values_right = -right_assr41_noVR ;
plot(new_x_values, y_values_right, '--', 'LineWidth', 1, 'Color', [1, 0.4, 0.4]);
hold on;
x_values_right = 1:length(mean(right_assr41_noVR , 1));
y_values_right = -mean(right_assr41_noVR , 1);
plot(new_x_values, y_values_right, 'LineWidth', 2, 'Color', 'red');
grid on;
title('ASSR powers turning right');
% Set custom x-axis tick labels
xticks(custom_xticks);
xticklabels(custom_xticklabels);
xlim([min(new_x_values), max(new_x_values)]);
ylim([-0.05 0.05]);
ylabel('µV²/Hz');
% ASSR Powers left zscore
figure;
% subplot(2, 2, 3)
x_values_left = 1:length(mean(assrPOW39_left_zscore, 1));
y_values_left = assrPOW39_left_zscore;
plot(new_x_values, y_values_left, 'LineWidth', 1, 'Color', 'blue');
% xlim([min(new_x_values), max(new_x_values)]);
hold on;
x_values_left = 1:length(mean(assrPOW39_left_zscore, 1));
y_values_left = -assrPOW41_left_zscore;
plot(new_x_values, y_values_left, 'LineWidth', 1, 'Color', 'red');
hold on;
grid on;
title('z-scored ASSR powers turning left');
xlim([min(new_x_values), max(new_x_values)]);
xticks(custom_xticks);
xticklabels(custom_xticklabels);
hold off;
% ASSR Powers right zscore
figure;
% subplot(2, 2, 4)
x_values_right = 1:length(mean(assrPOW39_right_zscore, 1));
y_values_right = assrPOW39_right_zscore;
plot(new_x_values, y_values_right, 'LineWidth', 1, 'Color', 'blue');
% xlim([min(new_x_values), max(new_x_values)]);
hold on;
x_values_right = 1:length(mean(assrPOW39_right_zscore, 1));
y_values_right = -assrPOW41_right_zscore;
plot(new_x_values, y_values_right, 'LineWidth', 1, 'Color', 'red');
hold on;
grid on;
title('z-scored ASSR powers turning right');
xlim([min(new_x_values), max(new_x_values)]);
xticks(custom_xticks);
xticklabels(custom_xticklabels);
hold off;
tightfig;
% and save
output_file_path = 'C:\Users\ericw\Desktop\Master_Thesis\Data\CURRENT_DATA\4_FIGURES\new';
if ~exist(output_file_path, 'dir') % Check if the folder exists, and create it if not
mkdir(output_file_path);
end
savename = 'C:\Users\ericw\Desktop\Master_Thesis\Data\CURRENT_DATA\4_FIGURES\new\grand_mean_assrPOW_new.png';
saveas(hFig, savename);
%%
hFig = figure; % Create a figure
screenSize = get(0, 'ScreenSize'); % Get the screen size
set(hFig, 'Position', screenSize);
% ASSR Powers left
subplot(2, 2, 1)
x_values_left = 1:length(mean(left_assr39_noVR(:, index_of_20percent:index_of_80percent), 1));
y_values_left = mean(left_assr39_noVR(:, index_of_20percent:index_of_80percent), 1);
plot(x_values_left, y_values_left, 'LineWidth', 2, 'Color', 'red');
xlim([0 length(mean(left_assr39_noVR(:, index_of_20percent:index_of_80percent), 1))])
ylim([-0.06 0.06])
hold on;
x_values_left = 1:length(mean(left_assr41_noVR(:, index_of_20percent:index_of_80percent), 1));
y_values_left = -mean(left_assr41_noVR(:, index_of_20percent:index_of_80percent), 1);
plot(x_values_left, y_values_left, 'LineWidth', 2, 'Color', 'red');
hold on;
grid on;
title('ASSR powers turning left');
hold off;
% ASSR Powers right
subplot(2, 2, 2)
x_values_right = 1:length(mean(right_assr39_noVR(:, index_of_20percent:index_of_80percent), 1));
y_values_right = right_assr39_noVR(:, index_of_20percent:index_of_80percent);
plot(x_values_right, y_values_right, 'LineWidth', 1, 'Color', [0.7, 0.7, 0.7]);
xlim([0 length(mean(right_assr39_noVR(:, index_of_20percent:index_of_80percent), 1))])
ylim([-0.2 0.2])
hold on;
x_values_right = 1:length(mean(right_assr39_noVR(:, index_of_20percent:index_of_80percent), 1));
y_values_right = mean(right_assr39_noVR(:, index_of_20percent:index_of_80percent), 1);
plot(x_values_right, y_values_right, 'LineWidth', 2, 'Color', 'red');
hold on;
x_values_right = 1:length(mean(right_assr39_noVR(:, index_of_20percent:index_of_80percent), 1));
y_values_right = -right_assr41_noVR(:, index_of_20percent:index_of_80percent);
plot(x_values_right, y_values_right, 'LineWidth', 1, 'Color', [0.7, 0.7, 0.7]);
hold on;
x_values_right = 1:length(mean(right_assr41_noVR(:, index_of_20percent:index_of_80percent), 1));
y_values_right = -mean(right_assr41_noVR(:, index_of_20percent:index_of_80percent), 1);
plot(x_values_right, y_values_right, 'LineWidth', 2, 'Color', 'red');
grid on;
title('ASSR powers turning right');
hold off;