TEAP (Toolbox for Emotion Analysis using Physiological Signals) doc
regress_eog.m
Go to the documentation of this file.
1 function [R,S] = regress_eog(D,ny,nx)
2 % REGRESS_EOG yields the regression coefficients for
3 % correcting EOG artifacts in EEG recordings as described in [1].
4 % Typically, EOG correction is a two-step procedure. The first step
5 % estimates the correction coefficient, the second step uses them
6 % for data correction.
7 %
8 % Step 1: estimating the correction coefficients:
9 % R = regress_eog(D, EL, OL)
10 % R = regress_eog(filename, EL, OL)
11 % R = regress_eog(filename)
12 % R = regress_eog(covm(D,'E'), EL, OL)
13 % NOTE: it is recommended that this data segments (D, filename) contain
14 % segments with large eye movement artifacts only; other artifacts
15 % (e.g. saturation, electrode movement, muscle, etc) should be
16 % excluded.
17 %
18 % Step 2: Corrected data is obtained by
19 % S2 = S1 * R.r0; % without offset correction
20 % S2 = [ones(size(S1,1),1),S1] * R.r1; % with offset correction
21 %
22 % S1 recorded data
23 % EL list of eeg channels: those channels will be corrected
24 % OL eog/ecg channels.
25 % if OL is a vector, it represents the list of noise channels
26 % if OL is a matrix, OL derives the noise channels through rereferencing.
27 % This is useful if the EOG is recorded monopolar, but the bipolar EOG
28 % should be used for for artefact reduction (because the global EEG should remain),
29 % One can define OL = sparse([23,24,25,26],[1,1,2,2],[1,-1,1,-1])
30 % resulting in two noise channels defined as bipolar channels #23-#24 and #25-#26
31 % A heuristic to get the proper OL is provided by identify_eog_channels.m
32 % OL = IDENTIFY_EOG_CHANNELS(filename)
33 % R.r1, R.r0 rereferencing matrix for correcting artifacts with and without offset correction
34 % R.b0 coefficients of EOG influencing EEG channels
35 % S2 corrected EEG-signal
36 %
37 % see also: IDENTIFY_EOG_CHANNELS, SLOAD, GET_REGRESS_EOG
38 %
39 % Reference(s):
40 % [1] Schlogl A, Keinrath C, Zimmermann D, Scherer R, Leeb R, Pfurtscheller G.
41 % A fully automated correction method of EOG artifacts in EEG recordings.
42 % Clin Neurophysiol. 2007 Jan;118(1):98-104. Epub 2006 Nov 7.
43 % http://dx.doi.org/10.1016/j.clinph.2006.09.003
44 % http://pub.ist.ac.at/~schloegl/publications/schloegl2007eog.pdf
45 
46 % This program is free software; you can redistribute it and/or
47 % modify it under the terms of the GNU General Public License
48 % as published by the Free Software Foundation; either version 3
49 % of the License, or (at your option) any later version.
50 %
51 % This program is distributed in the hope that it will be useful,
52 % but WITHOUT ANY WARRANTY; without even the implied warranty of
53 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
54 % GNU General Public License for more details.
55 %
56 % You should have received a copy of the GNU General Public License
57 % along with this program; if not, write to the Free Software
58 % Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
59 
60 % $Id: regress_eog.m 2649 2011-03-09 09:52:44Z schloegl $
61 % (C) 1997-2007,2008,2009 by Alois Schloegl <a.schloegl@ieee.org>
62 % This is part of the BIOSIG-toolbox http://biosig.sf.net/
63 
64 if ischar(D),
65  [D,H] = sload(D);
66  C = covm(D,'E');
67  if (nargin<3)
68  nx = identify_eog_channels(H);
69  end;
70  if (nargin<2)
71  ny = find(~any(nx,2));
72  end;
73 
74 elseif size(D,1)==size(D,2)
75  C = D;
76  H.NS = size(C,2)-1;
77 
78 else
79  H.NS = size(D,2);
80  C = covm(D,'E');
81 end
82 
83 R.datatype = 'ArtifactCorrection_Regression';
84 R.signalchannel = ny;
85 R.noise_channel = nx;
86 R.Mode = 1; % correction of the mean
87 R.Mode = 0; % correction without mean
88 
89 a = speye(H.NS+1);
90 if size(nx,1)==1, % list of noise channel
91  nx = nx(:);
92 else % noise channels are defined through rereferencing (e.g. bipoloar channels)
93  tmp = H.NS+(1:size(nx,2));
94 % nx(isnan(nx)) = 0;
95  a(2:size(nx,1)+1,tmp+1) = nx;
96  if rank(full(nx)) < size(nx,2),
97  fprintf(2,'Warning REGRESS_EOG: referencing matrix is singular! \n');
98  end;
99  C = a'*C*a;
100  nx = tmp';
101 end;
102 ny = ny(:);
103 
104 r0 = speye(H.NS);
105 r1 = sparse(2:H.NS+1,1:H.NS,1);
106 
107 b0 = -inv(C([1; nx+1], [1; nx+1])) * C([1; nx+1], ny+1);
108 r0(nx,ny) = b0(2:end,:); % rearrange channel order
109 r1([1;1+nx], ny) = b0; % rearrange channel order
110 
111 R.b0 = b0; % correction coefficients, useful for visualization
112 R.r0 = a(2:end,2:end)*r0;
113 R.r1 = a*r1;
114 
115 if size(D,1)==size(D,2),
116  % R = R;
117 
118 elseif (nargout>1)
119  % S = D * R.r0; % without offset correction
120  S = [ones(size(D,1),1),D] * R.r1; % with offset correction
121 end
122 
sload
function sload(in FILENAME, in varargin)
identify_eog_channels
function identify_eog_channels(in fn, in x)
regress_eog
function regress_eog(in D, in ny, in nx)