-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanalyzePEERforERP.m
128 lines (95 loc) · 3.91 KB
/
analyzePEERforERP.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
clear all;
close all;
clc;
% analyze a single PEER subject and generate peak data and single subject
% waveforms. Note, you have to select a PEER export file in csv format and
% not the full data export. This is specifically intended for the PEER
% oddball paradigm series. Note, this code also deletes channels AF7 and
% AF8 and combines TP9 and TP10
% VARIABLES
[fileName filePath] = uigetfile('*.csv');
% display channel variance
showChannelVariance = 0; % set to 0 for batch scripts
% remove channels
channelsToRemove = {'AF7','AF8'};
% reference paramters (0 = none, 1 = front to back, 2 = all to back)
referenceChannels = {'TP9','TP10'};
channelsRereferenced = {'ALL'};
% filter parameters
filterOrder = 2;
filterLow = 0.1; % always keep at 0.1
filterHigh = 30; % set to 15 for ERP analyses, set to 30 or higher for FFT
filterNotch = 60; % unless in Europe use 60
% epoch parameters
epochMarkers = {'S 5','S 6'}; % the markers 'S 5' is control 'S 6' is oddball
currentEpoch = [-200 798]; % the time window
% baseline window
baseline = [-200 0]; % the baseline, recommended -200 to 0
% artifact criteria
typeOfArtifactRejction = 'Difference'; % max - min difference
artifactCriteria = 50; % recommend maxmin of 75
individualChannelAveraging = 0; % set to one for individual channel averaging
% internal consistency
computeInternalConsistency = 0; % set to 1 to do odd even averaging to allow computation of internal consistency
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COMMANDS
% remove the .csv
fileName(end-3:end) = [];
EEG = doLoadMUSE(fileName);
% compute channel variances
EEG = doChannelVariance(EEG,showChannelVariance);
% option to remove front channels
EEG = doRemoveChannels(EEG,channelsToRemove,EEG.chanlocs);
% filter the data
EEG = doFilter(EEG,filterLow,filterHigh,filterOrder,filterNotch,EEG.srate);
% epoch data
EEG = doSegmentData(EEG,epochMarkers,currentEpoch);
% concatenate data to increase SNR
EEG = doIncreasePEERSNR(EEG,2);
% baseline correction
EEG = doBaseline(EEG,baseline);
% identify artifacts
EEG = doArtifactRejection(EEG,typeOfArtifactRejction,artifactCriteria);
% remove bad trials
EEG = doRemoveEpochs(EEG,EEG.artifact.badSegments,individualChannelAveraging);
% make ERPs
ERP = doERP(EEG,epochMarkers,computeInternalConsistency);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% PLOT THE OUTPUT
% plot the results
subplot(1,2,1);
plot(ERP.times,ERP.data(1,:,1),'LineWidth',3);
hold on;
plot(ERP.times,ERP.data(1,:,2),'LineWidth',3);
hold off;
title('Channel TP');
ylabel('Voltage (uV)');
xlabel('Time (ms)');
dw = squeeze(ERP.data(1,:,2) - ERP.data(1,:,1));
subplot(1,2,2);
plot(ERP.times,dw,'LineWidth',3);
title('TP Difference Wave');
ylabel('Voltage (uV)');
xlabel('Time (ms): Click on the N200 and P300');
[x y] = ginput(2);
for n200point = 1:size(ERP.times,2)
if ERP.times(n200point) >= x(1)
break
end
end
for p300point = 1:size(ERP.times,2)
if ERP.times(p300point) >= x(2)
break
end
end
n200peak = dw(n200point);
n200time = ERP.times(n200point);
p300peak = dw(p300point);
p300time = ERP.times(p300point);
disp(['The N200 amplitude is ' num2str(n200peak) 'uV and occured at ' num2str(round(n200time)) ' ms.']);
disp(['The P300 amplitude is ' num2str(p300peak) 'uV and occured at ' num2str(round(p300time)) ' ms.']);
disp(['The total artifact percentage is ' num2str(EEG.channelArtifactPercentages) '%.']);
conditionalWaveforms = squeeze(ERP.data);
differeneWaveform = dw;
timePoints = ERP.times*1000;
clear a* b* ch* cu* com* dw ERP EEG e* f* i* r* s* ty* x* y*