-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathRELAX_metrics_final_SER_and_ARR.m
67 lines (58 loc) · 3.3 KB
/
RELAX_metrics_final_SER_and_ARR.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
%% RELAX EEG CLEANING PIPELINE, Copyright (C) (2022) Neil Bailey
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see https://www.gnu.org/licenses/.
%% RELAX_metrics_final_SER_and_ARR:
function [continuousEEG, d] = RELAX_metrics_final_SER_and_ARR(rawEEG, continuousEEG)
%% This function uses all artifact templates from the MWF cleaning steps to compute the SER and ARR cleaning efficacy metrics
% Remove the same periods in the raw EEG as have been removed in the
% cleaned EEG:
rawEEG = eeg_eegrej( rawEEG, continuousEEG.RELAX.ExtremelyBadPeriodsForDeletion);
% And also from the masks, firstly by setting up a full EEG.data length
% template with 1's to denote periods that were excluded as extreme
% outliers:
reject = zeros(1,size(rawEEG.data,2));
for i=1:size(continuousEEG.RELAX.ExtremelyBadPeriodsForDeletion,1)
reject(continuousEEG.RELAX.ExtremelyBadPeriodsForDeletion(i,1):continuousEEG.RELAX.ExtremelyBadPeriodsForDeletion(i,2)) = 1;
end
% Then by using that template to remove periods from the masks, and
% combining the masks together so all artifacts from all masks are
% present in a single template:
if isfield(continuousEEG.RELAX,'NoiseMaskFullLengthR1')
NoiseMaskFullLengthR1 = continuousEEG.RELAX.NoiseMaskFullLengthR1;
NoiseMaskFullLengthR1(:,reject == 1) = [];
NoiseMaskFullLengthAll=NoiseMaskFullLengthR1;
end
if isfield(continuousEEG.RELAX,'NoiseMaskFullLengthR2')
NoiseMaskFullLengthR2 = continuousEEG.RELAX.NoiseMaskFullLengthR2;
NoiseMaskFullLengthR2(:,reject == 1) = [];
if isfield(continuousEEG.RELAX,'NoiseMaskFullLengthR1')==0
NoiseMaskFullLengthAll=NoiseMaskFullLengthR2;
end
NoiseMaskFullLengthAll(NoiseMaskFullLengthR2==1)=1;
end
if isfield(continuousEEG.RELAX,'NoiseMaskFullLengthR3')
NoiseMaskFullLengthR3 = continuousEEG.RELAX.NoiseMaskFullLengthR3;
NoiseMaskFullLengthR3(:,reject == 1) = [];
if exist('NoiseMaskFullLengthAll','var')==0
NoiseMaskFullLengthAll=NoiseMaskFullLengthR3;
end
NoiseMaskFullLengthAll(NoiseMaskFullLengthR3==1)=1;
end
% Average re-reference the raw data first so the SER and ARR are
% computed from average re-referenced raw and cleaned data:
[averageref_rawEEG] = RELAX_average_rereference(rawEEG);
% Calculate the artifact that has been removed:
d = averageref_rawEEG.data-continuousEEG.data;
% Calculate SER and ARR for each type of artifact in the MWF masks:
[continuousEEG.RELAX_Metrics.Cleaned.All_SER, continuousEEG.RELAX_Metrics.Cleaned.All_ARR] = mwf_performance(averageref_rawEEG.data, d, NoiseMaskFullLengthAll);
end