forked from nigelrogasch/TESA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtesa_edmpreprocess.m
More file actions
52 lines (47 loc) · 1.82 KB
/
tesa_edmpreprocess.m
File metadata and controls
52 lines (47 loc) · 1.82 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
% tesa_edmpreprocess( ) - This function is needed to run the function
% tesa_edm and to compute the
% preprocessing steps before running
% ICA as advocated in the following papers
%
% Korhonen, Hernandez-Pavon et al (2011)
% Removal of large muscle artifacts
% from transcranial magnetic stimulation-evoked EEG
% by independent component analysis. Med Biol Eng
% Compt, 49:397-407.
%
% Hernandez-Pavon et al (2012) Uncovering neural
% independent components from highly artifactual
% TMS-evoked EEG data. J Neurosci Meth,
% 209:144-57
%
% Usage:
% >> [EEGwhite, inMat, rankMat] = tesa_edmpreprocess( EEG , Nic);
%
% Inputs:
% EEG - EEGLAB EEG structure
% Nic - [Integer] Number of independent components to look for
%
% Outputs:
% EEGwhite - Whitened data matrix to be used by FastICA
% inMat - Centered matrix
% Mean - Mean over channels to be used in tesa_edm
%
% Copyright (C) 2016 Julio Cesar Hernandez Pavon, Aalto University,
% Finland, julio.hpavon@gmail.com
%
function [EEGwhite,inMat,Meanb] = tesa_edmpreprocess(EEG)
%Reshapes 3D matrix to 2D
EEG1=reshape(EEG.data,size(EEG.data,1),[],1);
% centering
Meanb=mean(EEG1,2)*ones(1,size(EEG1,2));
EEG1=EEG1-Meanb; %Centering
T=size(EEG1,2);
% Data to be Whitened
inMat=EEG1;
%Runs singular value decomposition
[U,S,V]=svd(inMat*inMat');
d=diag(sqrt(S));
m=rank(inMat);
% Whitening matrix
EEGwhite=sqrt(T)*diag(1./d(1:m))*U(:,1:m)'*inMat; %Whitening matrix
end