-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_ERP.m
More file actions
706 lines (679 loc) · 38.6 KB
/
Copy pathplot_ERP.m
File metadata and controls
706 lines (679 loc) · 38.6 KB
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
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
%% Name: plot_ERP.m
%% Description: a function for visualizing ERP
%% Author: Yao Yipeng
%% Contact: darianyao@gmail.com
%% Date: 2023,12,9
function plot_ERP()
try
%% initialization
eeglab;
clc;
clear all;
close all;
commandwindow;
%% load data
load('D:\ResearchProjects\Yaoyipeng\Pain_VisionInteg\program\supThreshold\Pain_heat\Pain_VisionInteg_heatV4_EEG\code\Process_EEGData\ERP_analysis\group_A_ERP\Group_level_ERP.mat');
%% combine all conditions
% ===================================ERP===================================
numSub = [1:20];
Cz = 12; % channel number
figure;
mean_data = squeeze(mean(EEG_avg(numSub,Cz,:),1));
plot(EEG.times, mean_data,'r','linewidth', 0.8); % 'r'=red
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -10 10]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(' ERP at Cz-reference','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
%% ================traverse all electrode channels=========================
Roi_condV = [1 2 3];
Roi_condP = [5 6];
Roi_condVP = [7 8 9 10 11 12];
Roi_condN = [4];
Roi_condAll = [1 2 3 4 5 6 7 8 9 10 11 12];
show_conds = 3; % 1 = V; 2 = P; 3 = VP; 4 = all
if show_conds == 1
Roi_condTemp = Roi_condV;
elseif show_conds == 2
Roi_condTemp = Roi_condP;
elseif show_conds == 3
Roi_condTemp = Roi_condVP;
elseif show_conds == 4
Roi_condTemp = Roi_condAll;
end
for iChan = 1: EEG.nbchan
data_conV = squeeze(mean(mean(EEG_avg_cond(:,Roi_condV,iChan,:),1),2));
data_conP = squeeze(mean(mean(EEG_avg_cond(:,Roi_condP ,iChan,:),1),2));
data_conVP = squeeze(mean(mean(EEG_avg_cond(:,Roi_condVP,iChan,:),1),2));
data_conN = squeeze(mean(mean(EEG_avg_cond(:,Roi_condN,iChan,:),1),2));
figure
hold on
plot(EEG.times, data_conV,'Color',[1 0 0],'linewidth', 1.2);
plot(EEG.times, data_conP,'Color',[0 1 0],'linewidth', 1.2);
plot(EEG.times, data_conVP,'Color',[0 0 1],'linewidth', 1.2);
plot(EEG.times, data_conN,'Color',[0.8 0.8 0.8],'linewidth', 1.2);
set(gca,'YDir','reverse');
axis([-1000 3000 -8 8]); %% define the region to display
%xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(['Group-level at ',EEG.chanlocs(iChan).labels],'fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Vision','Pain','Vision-Pain','Null')
hold off
end
%% test N1 component
Roi_condV = [1 2 3];
Roi_condP = [5 6];
Roi_condVP = [7 8 9 10 11 12];
% vision
figure;
hold on
data_Vcz = squeeze(mean(mean(EEG_avg_cond(:,Roi_condV,12,:),1),2));
data_Voz = squeeze(mean(mean(EEG_avg_cond(:,Roi_condV,30,:),1),2));
plot(EEG.times, data_Vcz, 'Color',[1 0 0],'linewidth', 1.2);
plot(EEG.times, data_Voz, 'Color',[0 1 0],'linewidth', 1.2);
set(gca,'YDir','reverse');
axis([-1000 3000 -8 8]); %% define the region to display
title(['Group-level ERP '],'fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('ERP under V at Cz','ERP under V at Oz'); % low pain
hold off
% pain
figure;
hold on
data_Pcz = squeeze(mean(mean(EEG_avg_cond(:,Roi_condP,12,:),1),2));
data_Poz = squeeze(mean(mean(EEG_avg_cond(:,Roi_condP,30,:),1),2));
plot(EEG.times, data_Pcz, 'Color',[1 0 0],'linewidth', 1.2);
plot(EEG.times, data_Poz, 'Color',[0 1 0],'linewidth', 1.2);
set(gca,'YDir','reverse');
axis([-1000 3000 -8 8]); %% define the region to display
title(['Group-level ERP '],'fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('ERP under P at Cz','ERP under P at Oz'); % low pain
hold off
% vision-pain
figure;
hold on
data_VPcz = squeeze(mean(mean(EEG_avg_cond(:,Roi_condVP,12,:),1),2));
data_VPoz = squeeze(mean(mean(EEG_avg_cond(:,Roi_condVP,30,:),1),2));
plot(EEG.times, data_VPcz, 'Color',[1 0 0],'linewidth', 1.2);
plot(EEG.times, data_VPoz, 'Color',[0 1 0],'linewidth', 1.2);
set(gca,'YDir','reverse');
axis([-1000 3000 -8 8]); %% define the region to display
title(['Group-level ERP '],'fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('ERP under VP at Cz','ERP under VP at Oz'); % low pain
hold off
%% ===================================scalp map across different conditions===================================
% search peak time point with group-level analysis results (dominant peaks on waveforms)
N1_peak = 115; N2_peak = 257; P2_peak = 395;
% define componets intervals [peak-15 peak+15]
N1_interval = find((EEG.times>=(N1_peak-25))&(EEG.times<=(N1_peak+25)));
N2_interval = find((EEG.times>=(N2_peak-25))&(EEG.times<=(N2_peak+25)));
P2_interval = find((EEG.times>=(P2_peak-25))&(EEG.times<=(P2_peak+25)));
% plot
show_conds = 3; % 1 for vision; 2 for pain; 3 for vision-pain
if show_conds == 1
figure;
% vision
subplot(1,3,1);
N1_Vamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[1 2 3],:,N1_interval),1),2),4));
topoplot(N1_Vamp,EEG.chanlocs,'maplimits',[-4 4]);
title('N1 Amplitude under Vision','fontsize',16); %% N1 scalp map (group-level)
colorbar;
% pain
subplot(1,3,2);
N1_Pamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[5 6],:,N1_interval),1),2),4));
topoplot(N1_Pamp,EEG.chanlocs,'maplimits',[-4 4]);
title('N1 Amplitude under Pain','fontsize',16); %% N1 scalp map (group-level)
colorbar;
% vision - pain
subplot(1,3,3);
N1_Pamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[7 8 9 10 11 12],:,N1_interval),1),2),4));
topoplot(N1_Pamp,EEG.chanlocs,'maplimits',[-4 4]);
title('N1 Amplitude under Vision-Pain','fontsize',16); %% N1 scalp map (group-level)
colorbar;
elseif show_conds == 2
figure
% vision
subplot(1,3,1);
N2_Vamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[1 2 3 4],:,N2_interval),1),2),4));
topoplot(N2_Vamp,EEG.chanlocs,'maplimits',[-4 4]);
title('N2 Amplitude under Vision','fontsize',16); %% N2 scalp map (group-level)
colorbar;
% pain
subplot(1,3,2);
N2_Pamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[5 6],:,N2_interval),1),2),4));
topoplot(N2_Pamp,EEG.chanlocs,'maplimits',[-4 4]);
title('N2 Amplitude under Pain','fontsize',16); %% N2 scalp map (group-level)
colorbar;
% vision-pain
subplot(1,3,3);
N2_VPamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[7 8 9 10 11 12],:,N2_interval),1),2),4));
topoplot(N2_VPamp,EEG.chanlocs,'maplimits',[-4 4]);
title('N2 Amplitude under Vision-Pain','fontsize',16); %% N2 scalp map (group-level)
colorbar;
elseif show_conds == 3
figure;
% vision
subplot(1,3,1);
P2_Vamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[1 2 3 4],:,P2_interval),1),2),4));
topoplot(P2_Vamp,EEG.chanlocs,'maplimits',[-4 4]);
title('P2 Amplitude under Vision','fontsize',16); %% P2 scalp map (group-level)
colorbar;
% pain
subplot(1,3,2);
P2_Pamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[5 6],:,P2_interval),1),2),4));
topoplot(P2_Pamp,EEG.chanlocs,'maplimits',[-4 4]);
title('P2 Amplitude under Pain','fontsize',16); %% P2 scalp map (group-level)
colorbar;
% vision-pain
subplot(1,3,3);
P2_VPamp = squeeze(mean(mean(mean(EEG_avg_cond(:,[7 8 9 10 11 12],:,P2_interval),1),2),4));
topoplot(P2_VPamp,EEG.chanlocs,'maplimits',[-4 4]);
title('P2 Amplitude under Vision-Pain','fontsize',16); %% P2 scalp map (group-level)
colorbar;
end
%% ===================================time series of scalp maps===================================
% 定义显示地形图的时间窗间隔
time_interval = [0:100:1000]; %% specify the time intervals to display (to be changed)
figure;
condVC = [1 2 3 4];
condPN = [5 6];
condVP = [7 8 9 10 11 12];
for iFig = 1:length(time_interval)
latency_range = [time_interval(iFig) time_interval(iFig)+50]; %% lower and upper limits
latency_idx = find((EEG.times>=latency_range(1))&(EEG.times<=latency_range(2))); %% interval of the specific regions
Amplitude_1 = squeeze(mean(mean(mean(EEG_avg_cond(:,condVC,:,latency_idx),3),2),1)); %% 1*channel (averaged across subjects and interval)
Amplitude_2 = squeeze(mean(mean(mean(EEG_avg_cond(:,condPN,:,latency_idx),3),2),1));
Amplitude_3 = squeeze(mean(mean(mean(EEG_avg_cond(:,condVP,:,latency_idx),3),2),1));
subplot(3,4,iFig);
topoplot(Amplitude_3,EEG.chanlocs,'maplimits',[-2 2]); %% topoplot(Amplitude,EEG.chanlocs);
fig_name = [num2str(latency_range(1)),'--',num2str(latency_range(2)),'ms']; %% specify the name of subplots
title(fig_name,'fontsize',16); %% display the names of subplots
colorbar;
end
%% ===================================ERP (split different conditions)===================================
numSub = [1:20];
Roi_chan = 12; % channel number
show_conds = 3; % 1 = modality; 2 = pain; 3 = color; 4 = colorLp; 5 = colorHp 6 = vision only
if show_conds == 1
% vision
dataV_temp = mean(mean(EEG_avg_cond(numSub, [1 2 3], Roi_chan, :), 1),2); % vision
mean_dataV_temp = squeeze(dataV_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% pain
dataP_temp = mean(mean(EEG_avg_cond(numSub, [5 6], Roi_chan, :), 1),2); % pain
mean_dataP_temp = squeeze(dataP_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% vision-pain
dataVP_temp = mean(mean(EEG_avg_cond(numSub, [7 8 9 10 11 12], Roi_chan, :), 1),2); % vision-pain
mean_dataVP_temp = squeeze(dataVP_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% null
dataNu_temp = mean(mean(EEG_avg_cond(numSub, [4], Roi_chan, :), 1),2); % vision-pain
mean_dataNu_temp = squeeze(dataNu_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% plot 3 modalities
figure;
hold on
plot(EEG.times, mean_dataV_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataP_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataVP_temp,'Color',[0 0 1],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataNu_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(' ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Vision','Pain','Vision-Pain','Null'); % low pain
hold off
elseif show_conds == 2
% low pain 5 7 9 11
dataLp_temp = mean(mean(EEG_avg_cond(numSub, [5], Roi_chan, :), 1),2); % vision
mean_dataLp_temp = squeeze(dataLp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% high pain 6 8 10 12
dataHp_temp = mean(mean(EEG_avg_cond(numSub, [6], Roi_chan, :), 1),2); % vision
mean_dataHp_temp = squeeze(dataHp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% plot 2 levels
figure;
hold on
plot(EEG.times, mean_dataLp_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataHp_temp,'Color',[0 0 1],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(' ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Low pain','High pain'); % low pain
hold off
elseif show_conds == 3
% red with pain 7 8
dataRp_temp = mean(mean(EEG_avg_cond(numSub, [7 8], Roi_chan, :), 1),2); % vision
mean_dataRp_temp = squeeze(dataRp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% green with pain 9 10
dataGp_temp = mean(mean(EEG_avg_cond(numSub, [9 10], Roi_chan, :), 1),2); % vision
mean_dataGp_temp = squeeze(dataGp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% gray with pain 11 12
dataGYp_temp = mean(mean(EEG_avg_cond(numSub, [11 12], Roi_chan, :), 1),2); % vision
mean_dataGYp_temp = squeeze(dataGYp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% black with pain 5 6
dataBp_temp = mean(mean(EEG_avg_cond(numSub, [5 6], Roi_chan, :), 1),2); % vision
mean_dataBp_temp = squeeze(dataBp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% plot 4 conditions
figure;
hold on
plot(EEG.times, mean_dataRp_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGp_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGYp_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataBp_temp,'Color',[0 0 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title('ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Red with pain','Green with pain','Gray with pain','Pain Only '); % low pain
hold off
elseif show_conds == 4
% red with low pain 7
dataRp_temp = mean(mean(EEG_avg_cond(numSub, [7], Roi_chan, :), 1),2); % vision
mean_dataRp_temp = squeeze(dataRp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% green with low pain 9
dataGp_temp = mean(mean(EEG_avg_cond(numSub, [9], Roi_chan, :), 1),2); % vision
mean_dataGp_temp = squeeze(dataGp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% gray with low pain 11
dataGYp_temp = mean(mean(EEG_avg_cond(numSub, [11], Roi_chan, :), 1),2); % vision
mean_dataGYp_temp = squeeze(dataGYp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% only low pain 5
dataBp_temp = mean(mean(EEG_avg_cond(numSub, [5], Roi_chan, :), 1),2); % vision
mean_dataBp_temp = squeeze(dataBp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% plot 4 conditions
figure;
hold on
plot(EEG.times, mean_dataRp_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGp_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGYp_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataBp_temp,'Color',[0 0 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title('ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Red with low pain','Green with low pain','Gray with low pain','Low pain Only '); % low pain
hold off
elseif show_conds == 5
% red with high pain 8
dataRp_temp = mean(mean(EEG_avg_cond(numSub, [8], Roi_chan, :), 1),2); % vision
mean_dataRp_temp = squeeze(dataRp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% green with high pain 10
dataGp_temp = mean(mean(EEG_avg_cond(numSub, [10], Roi_chan, :), 1),2); % vision
mean_dataGp_temp = squeeze(dataGp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% gray with high pain 12
dataGYp_temp = mean(mean(EEG_avg_cond(numSub, [12], Roi_chan, :), 1),2); % vision
mean_dataGYp_temp = squeeze(dataGYp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% only high pain 6
dataBp_temp = mean(mean(EEG_avg_cond(numSub, [6], Roi_chan, :), 1),2); % vision
mean_dataBp_temp = squeeze(dataBp_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% plot 4 conditions
figure;
hold on
plot(EEG.times, mean_dataRp_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGp_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGYp_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataBp_temp,'Color',[0 0 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title('ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Red with high pain','Green with high pain','Gray with high pain','High pain Only'); % low pain
hold off
elseif show_conds == 6
% red
dataR_temp = mean(mean(EEG_avg_cond(numSub, [1], Roi_chan, :), 1),2); % vision
mean_dataR_temp = squeeze(dataR_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% green
dataG_temp = mean(mean(EEG_avg_cond(numSub, [2], Roi_chan, :), 1),2); % vision
mean_dataG_temp = squeeze(dataG_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% gray
dataGY_temp = mean(mean(EEG_avg_cond(numSub, [3], Roi_chan, :), 1),2); % vision
mean_dataGY_temp = squeeze(dataGY_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% black
dataB_temp = mean(mean(EEG_avg_cond(numSub, [4], Roi_chan, :), 1),2); % vision
mean_dataB_temp = squeeze(dataB_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% plot 4 conditions
figure;
hold on
plot(EEG.times, mean_dataR_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataG_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGY_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataB_temp,'Color',[0 0 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title('ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Red','Green','Gray','null'); % low pain
hold off
end
% ================traverse all electrode channels=========================
% traverse all electrode channels
% for iChan = 1: EEG.nbchan
% figure;
% hold on
% plot(EEG.times, squeeze(mean(mean(EEG_avg_cond(:, 1, iChan, :), 1) ,3)),'r','linewidth', 0.8); % 'r'= red
% plot(EEG.times, squeeze(mean(mean(EEG_avg_cond(:, 2, iChan, :), 1) ,3)),'b','linewidth', 0.8); % 'b' = blue
% set(gca,'YDir','reverse'); % reverse y axis
% axis([-500 1000 -15 10]); %% define the region to display
% % xlim([-500 1000]); %% define the region of X axis
% % ylim([-15 10]); %% define the region of Y axis
% title(['Group-level at ',EEG.chanlocs(iChan).labels],'fontsize',16); %% specify the figure name%% specify the figure name
% xlabel('Latency (ms)','fontsize',16); %% name of X axis
% ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
% legend('low pain','high pain');
% hold off
% end
%% contrast ERP
numSub = [1:20];
Roi_chan = 12; % channel number
show_conds = 2; % 1 = pain - null; 2 = color with pain - color - null; 3 = color with low pain; 4 = color with high pain
if show_conds == 1
% black
dataB_temp = mean(mean(EEG_avg_cond(numSub, [4], Roi_chan, :), 1),2); % vision
%mean_dataB_temp = squeeze(dataB_temp);
% lp
dataV_temp = mean(mean(EEG_avg_cond(numSub, [5], Roi_chan, :), 1),2); % vision
mean_datalp_temp = squeeze(dataV_temp) - squeeze(dataB_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% hp
dataP_temp = mean(mean(EEG_avg_cond(numSub, [6], Roi_chan, :), 1),2); % pain
mean_dataHp_temp = squeeze(dataP_temp)- squeeze(dataB_temp);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
% plot
figure;
hold on
plot(EEG.times, mean_datalp_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataHp_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(' ERP at Cz (P - null)','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Low pain','High pain'); % low pain
hold off
elseif show_conds == 2
% null
dataB_temp = mean(mean(EEG_avg_cond(numSub, [4], Roi_chan, :), 1),2);
% red
dataR_temp = mean(mean(EEG_avg_cond(numSub, [1], Roi_chan, :), 1),2);
dataRP_temp = mean(mean(EEG_avg_cond(numSub, [7 8], Roi_chan, :), 1),2);
mean_dataRP_temp = squeeze(dataRP_temp) - squeeze(dataR_temp) ;
% green
dataG_temp = mean(mean(EEG_avg_cond(numSub, [2], Roi_chan, :), 1),2);
dataGP_temp = mean(mean(EEG_avg_cond(numSub, [9 10], Roi_chan, :), 1),2);
mean_dataGP_temp = squeeze(dataGP_temp)- squeeze(dataG_temp) ;
% gray
dataGy_temp = mean(mean(EEG_avg_cond(numSub, [3], Roi_chan, :), 1),2);
dataGyP_temp = mean(mean(EEG_avg_cond(numSub, [11 12], Roi_chan, :), 1),2);
mean_dataGyP_temp = squeeze(dataGyP_temp)- squeeze(dataGy_temp) ;
% pain
dataBP_temp = mean(mean(EEG_avg_cond(numSub, [5 6], Roi_chan, :), 1),2);
mean_dataBP_temp = squeeze(dataBP_temp) ;
% plot
figure;
hold on
plot(EEG.times, mean_dataRP_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGP_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGyP_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataBP_temp,'Color',[0 0 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(' ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('RP-null - R-null','GP-null - G-null','GyP-null - Gy-null','Pain only - null'); % low pain
hold off
elseif show_conds == 3
% red
dataR_temp = mean(mean(EEG_avg_cond(numSub, [1], Roi_chan, :), 1),2);
dataRLP_temp = mean(mean(EEG_avg_cond(numSub, [7], Roi_chan, :), 1),2);
mean_dataRLP_temp = squeeze(dataRLP_temp) - squeeze(dataR_temp);
% green
dataG_temp = mean(mean(EEG_avg_cond(numSub, [2], Roi_chan, :), 1),2);
dataGLP_temp = mean(mean(EEG_avg_cond(numSub, [9], Roi_chan, :), 1),2);
mean_dataGLP_temp = squeeze(dataGLP_temp)- squeeze(dataG_temp);
% gray
dataGy_temp = mean(mean(EEG_avg_cond(numSub, [3], Roi_chan, :), 1),2);
dataGyLP_temp = mean(mean(EEG_avg_cond(numSub, [11], Roi_chan, :), 1),2);
mean_dataGyLP_temp = squeeze(dataGyLP_temp)- squeeze(dataGy_temp);
% black
dataB_temp = mean(mean(EEG_avg_cond(numSub, [4], Roi_chan, :), 1),2);
dataBLP_temp = mean(mean(EEG_avg_cond(numSub, [5], Roi_chan, :), 1),2);
mean_dataBLP_temp = squeeze(dataBLP_temp)- squeeze(dataB_temp );
% plot
figure;
hold on
plot(EEG.times, mean_dataRLP_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGLP_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGyLP_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataBLP_temp,'Color',[0 0 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(' ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Red with low pain - Red','Green with low pain - Green','Gray with low pain - Gray','Low pain only - Null'); % low pain
hold off
elseif show_conds == 4
% red
dataR_temp = mean(mean(EEG_avg_cond(numSub, [1], Roi_chan, :), 1),2);
dataRHP_temp = mean(mean(EEG_avg_cond(numSub, [8], Roi_chan, :), 1),2);
mean_dataRHP_temp = squeeze(dataRHP_temp) - squeeze(dataR_temp);
% green
dataG_temp = mean(mean(EEG_avg_cond(numSub, [2], Roi_chan, :), 1),2);
dataGHP_temp = mean(mean(EEG_avg_cond(numSub, [10], Roi_chan, :), 1),2);
mean_dataGHP_temp = squeeze(dataGHP_temp)- squeeze(dataG_temp);
% gray
dataGy_temp = mean(mean(EEG_avg_cond(numSub, [3], Roi_chan, :), 1),2);
dataGyHP_temp = mean(mean(EEG_avg_cond(numSub, [12], Roi_chan, :), 1),2);
mean_dataGyHP_temp = squeeze(dataGyHP_temp)- squeeze(dataGy_temp);
% black
dataB_temp = mean(mean(EEG_avg_cond(numSub, [4], Roi_chan, :), 1),2);
dataBHP_temp = mean(mean(EEG_avg_cond(numSub, [6], Roi_chan, :), 1),2);
mean_dataBHP_temp = squeeze(dataBHP_temp)- squeeze(dataB_temp );
% plot
figure;
hold on
plot(EEG.times, mean_dataRHP_temp,'Color',[1 0 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGHP_temp,'Color',[0 1 0],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataGyHP_temp,'Color',[0.8 0.8 0.8],'linewidth', 1.2); % 'r'= red
plot(EEG.times, mean_dataBHP_temp,'Color',[0 0 0],'linewidth', 1.2); % 'r'= red
% set parameters
set(gca,'YDir','reverse'); % reverse y axis
axis([-1000 2000 -8 8]); %% define the region to display
% xlim([-500 1000]); %% define the region of X axis
% ylim([-15 10]); %% define the region of Y axis
title(' ERP at Cz','fontsize',16); %% specify the figure name
xlabel('Latency (ms)','fontsize',16); %% name of X axis
ylabel('Amplitude (uV)','fontsize',16); %% name of Y axis
legend('Red with high pain - Red','Green with high pain - Green','Gray with high pain - Gray','High pain only - Null'); % low pain
hold off
end
%% ===================================scalp map===================================
% find peak point trough axis
N2_peak = 248; P2_peak = 447; %% dominant peaks on waveforms
% define the N2 intervals [peak-10 peak+10]
N2_interval = find((EEG.times>=(N2_peak-30))&(EEG.times<=(N2_peak+30))); %%
%N2_interval = EEG.times((EEG.times>=(N2_peak-10))&(EEG.times<=(N2_peak+10)));
% define the P2 intervals [peak-10 peak+10]
P2_interval = find((EEG.times>=(P2_peak-30))&(EEG.times<=(P2_peak+30))); %%
%P2_interval = EEG.times((EEG.times>=(P2_peak-10))&(EEG.times<=(P2_peak+10)));
title_pool = {'red','green','blue','gray'};
show_conds = 4; % 1 = only lp; 2 = only hp; 3 = color; 4 = pain
for iCond = 1:2
if show_conds == 1
% N2 amplitude for each subject and each channel sub*chan*amplitude
N2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,iCond,:,N2_interval),4),2));
% P2 amplitude for each subject and each channel
P2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,iCond,:,P2_interval),4),2));
elseif show_conds == 2
N2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,iCond+4,:,N2_interval),4),2));
P2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,iCond+4,:,P2_interval),4),2));
elseif show_conds == 3
N2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,[iCond iCond+4],:,N2_interval),4),2));
P2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,[iCond iCond+4],:,P2_interval),4),2));
elseif show_conds == 4
if iCond == 1
N2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,[iCond iCond+1 iCond+2 iCond+3],:,N2_interval),4),2));
P2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,[iCond iCond+1 iCond+2 iCond+3],:,P2_interval),4),2));
elseif iCond == 2
N2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,[iCond+3 iCond+4 iCond+5 iCond+6],:,N2_interval),4),2));
P2_amplitude = squeeze(mean(mean(EEG_avg_cond(:,[iCond+3 iCond+4 iCond+5 iCond+6],:,P2_interval),4),2));
end
end
figure;
% subplot 1
subplot(1,2,1);
topoplot(mean(N2_amplitude,1),EEG.chanlocs,'maplimits',[-6 6]);
if show_conds == 1
title(['N2 Amplitude-lp ' title_pool{iCond}],'fontsize',16); %% N2 scalp map (group-level)
elseif show_conds == 2
title(['N2 Amplitude-hp ' title_pool{iCond}],'fontsize',16); %% N2 scalp map (group-level)
elseif show_conds == 3
title(['N2 Amplitude-' title_pool{iCond}],'fontsize',16); %% N2 scalp map (group-level)
elseif show_conds == 4
if iCond == 1
title(['N2 Amplitude-' 'lp'],'fontsize',16); %% N2 scalp map (group-level)
elseif iCond == 2
title(['N2 Amplitude-' 'hp'],'fontsize',16); %% N2 scalp map (group-level)
end
end
colorbar;
% subplot 2
subplot(1,2,2);
topoplot(mean(P2_amplitude,1),EEG.chanlocs,'maplimits',[-6 6]);
if show_conds == 1
title(['P2 Amplitude-lp ' title_pool{iCond}],'fontsize',16); %% P2 scalp map (group-level)
elseif show_conds == 2
title(['P2 Amplitude-hp ' title_pool{iCond}],'fontsize',16); %% P2 scalp map (group-level)
elseif show_conds == 3
title(['P2 Amplitude-' title_pool{iCond}],'fontsize',16);
elseif show_conds == 4
if iCond == 1
title(['P2 Amplitude-' 'lp'],'fontsize',16);
elseif iCond == 2
title(['P2 Amplitude-' 'hp'],'fontsize',16);
end
end
colorbar;
end
%% ===================================series of scalp mps===================================
% 定义显示地形图的时间窗间隔
time_interval = [100:100:500]; %% specify the time intervals to display (to be changed)
figure;
for iFig = 1:length(time_interval)
latency_range = [time_interval(iFig) time_interval(iFig)+50]; %% lower and upper limits
latency_idx = find((EEG.times>=latency_range(1))&(EEG.times<=latency_range(2))); %% interval of the specific regions
Amplitude = squeeze(mean(mean(EEG_avg_cond(:,:,:,latency_idx),4),2)); %% 1*channel (averaged across subjects and interval)
subplot(3,3,iFig);
topoplot(mean(Amplitude,1),EEG.chanlocs,'maplimits',[-6 6]); %% topoplot(Amplitude,EEG.chanlocs);
fig_name = [num2str(latency_range(1)),'--',num2str(latency_range(2)),'ms']; %% specify the name of subplots
title(fig_name,'fontsize',16); %% display the names of subplots
colorbar;
end
%% difference wave
% ===================================ERP===================================
Cz = 13;
dataCond_1 = mean(EEG_avg_cond(:, 1, Cz, :), 1);
dataCond_2 = mean(EEG_avg_cond(:, 2, Cz, :), 1);
mean_dataCond_1 = squeeze(dataCond_1);% squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3))
mean_dataCond_2 = squeeze(dataCond_2);% squeeze(mean(mean(EEG_avg_cond(:, 2, Cz, :), 1) ,3))
dif_21 = mean_dataCond_2 - mean_dataCond_1;
%dif_conds = squeeze(mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3) - mean(mean(EEG_avg_cond(:, 1, Cz, :), 1) ,3));
figure;
hold on;
plot(EEG.times, dif_21,'k','linewidth', 1); %% plot waveforms for different conditions
set(gca,'YDir','reverse'); %% reverse Y axis
axis([-1000 2000 -4 4]); %% define the region to display
title('Group level data at CZ','fontsize',16);
xlabel('Latency (ms)','fontsize',16);
ylabel('Amplitude (uV)','fontsize',16);
legend('low pain - high pain');
hold off;
% ================traverse all electrode channels=========================
% for iChan = 1 : EEG.nbchan
% dif_conds = EEG_avg_cond(:, 1, iChan, :) - EEG_avg_cond(:, 2, iChan, :);
% figure;
% plot(EEG.times, dif_conds,'k','linewidth', 1); %% plot waveforms for different conditions
% set(gca,'YDir','reverse'); %% reverse Y axis
% axis([-500 1000 -35 25]); %% define the region to display
% title('Group level data at CZ','fontsize',16);
% xlabel('Latency (ms)','fontsize',16);
% ylabel('Amplitude (uV)','fontsize',16);
% legend(Cond,'low pain - high pain');
% end
% ===================================scalp map===================================
% 通过在组水平图上用游标卡尺寻找峰值点
N2_peak = 207; P2_peak = 374; %% dominant peaks on waveforms
% define the N2 intervals [peak-10 peak+10]
N2_interval = find((EEG.times>=197)&(EEG.times<=217)); %%
% define the P2 intervals [peak-10 peak+10]
P2_interval = find((EEG.times>=364)&(EEG.times<=384)); %%
% N2 amplitude for each subject and each channel 被试*电极 的平均波幅
N2_amplitude = squeeze(mean(dif_12(:,:,:,N2_interval),3));
% P2 amplitude for each subject and each channel
P2_amplitude = squeeze(mean(dif_12(:,:,:,P2_interval),3));
figure;
subplot(1,2,1);
topoplot(mean(N2_amplitude,1),EEG.chanlocs,'maplimits',[-10 10]);
title('N2 Amplitude','fontsize',16); %% N2 scalp map (group-level)
colorbar;
subplot(1,2,2);
topoplot(mean(P2_amplitude,1),EEG.chanlocs,'maplimits',[-10 10]);
title('P2 Amplitude','fontsize',16); %% P2 scalp map (group-level)
colorbar;
% ===================================series of scalp mps===================================
% 定义显示地形图的时间窗间隔
time_interval = [100:50:500]; %% specify the time intervals to display (to be changed)
figure;
for iFig = 1:length(time_interval)
latency_range = [time_interval(iFig) time_interval(iFig)+50]; %% lower and upper limits
latency_idx = find((EEG.times>=latency_range(1))&(EEG.times<=latency_range(2))); %% interval of the specific regions
Amplitude = squeeze(mean(mean(dif_12(:,:,:,latency_idx),4),2)); %% 1*channel (averaged across subjects and interval)
subplot(3,3,iFig);
topoplot(mean(Amplitude,1),EEG.chanlocs,'maplimits',[-10 10]); %% topoplot(Amplitude,EEG.chanlocs);
fig_name = [num2str(latency_range(1)),'--',num2str(latency_range(2)),'ms']; %% specify the name of subplots
title(fig_name,'fontsize',16); %% display the names of subplots
colorbar;
end
catch Me
disp(Me.message)
end
return