Authored by JD

Merge branch 'artefact_correction_jd'

# Conflicts:
#	prepare_ImaGIN_ArtefactCorrection.m
#	prepare_ImaGIN_spm_eeg_converteeg2mat.m
... ... @@ -19,4 +19,6 @@ move( D, FileOut ) ;
set_final_status('OK')
close all
end
... ...
... ... @@ -72,4 +72,7 @@ S.FileOut=FileOut;
D=ImaGIN_ArtefactCorrectionModel(S);
set_final_status('OK')
close all
end
... ...
... ... @@ -9,3 +9,7 @@ fprintf('prepare_ImaGIN_BadChannel: S.dataset: %s \n', S.dataset)
fprintf('prepare_ImaGIN_BadChannel: S.FileOut: %s \n', S.FileOut)
fprintf('prepare_ImaGIN_BadChannel: S.trainBase: %s \n', S.trainBase)
D = ImaGIN_BadChannel(S);
close all
end
... ...
... ... @@ -3,3 +3,7 @@ function prepare_ImaGIN_BadChannelQualityControl(FileIn)
clear S;
S.dataset = fullfile(FileIn);
D = ImaGIN_BadChannelQualityControl(S);
close all
end
... ...
... ... @@ -20,4 +20,7 @@ S.SaveFile=deblank(file);
disp(S.SaveFile(1:end-length(ext)-1));
set_final_status('OK')
close all
end
... ...
... ... @@ -17,3 +17,6 @@ else
end
D = ImaGIN_CropAuto(S);
close all
end
... ...
... ... @@ -84,6 +84,9 @@ S.FileOut = FileOut;
D = ImaGIN_Electrode(S);
set_final_status('OK')
close all
end
... ...
... ... @@ -22,4 +22,6 @@ S.EventFileName{1}=FileEventIn;
S.FileOut=FileOut;
ImaGIN_Events(S);
close all
end
\ No newline at end of file
... ...
... ... @@ -4,4 +4,6 @@ P.fname = FileIn;
P.FileOut = FileOut;
ImaGIN_NotchFilter(P);
close all
end
\ No newline at end of file
... ...
... ... @@ -28,5 +28,6 @@ S.FileOut=FileOut;
S.Channels=[];
ImaGIN_StimDetect(S);
close all
end
\ No newline at end of file
... ...
... ... @@ -17,4 +17,6 @@ S.Offset=Offset;
S.FileOut=FileOut;
ImaGIN_TimeZero(S);
close all
end
\ No newline at end of file
... ...
... ... @@ -3,4 +3,8 @@ clear S;
S.dataset = fullfile(FileIn);
S.DirFileOut = FileOut;
S.defaultPulseDuration = defaultPulseDuration;
ImaGIN_Validate_StimNames(S);
\ No newline at end of file
ImaGIN_Validate_StimNames(S);
close all
end
... ...
function prepare_ImaGIN_spm_eeg_converteeg2mat(FileIn, FileOut)
% FileIn: path linking to the MEEG file to correct
% FileOut: output path
... ... @@ -71,4 +71,10 @@ end
D = ImaGIN_spm_eeg_converteeg2mat(S);
<<<<<<< HEAD
end
=======
close all
end
>>>>>>> artefact_correction_jd
... ...
... ... @@ -38,4 +38,8 @@ D = ImaGIN_spm_eeg_filter(S);
set_final_status('OK')
close all
end
... ...
... ... @@ -3,3 +3,8 @@ function prepare_ImaGIN_trainBaseUpdate(inDir)
clear S;
S.DirIn = inDir;
ImaGIN_trainBaseUpdate(S)
close all
end
... ...
... ... @@ -15,6 +15,7 @@ for i0=1:size(t,1)
D=spm_eeg_load(T);
Time=time(D);
F = spm_figure('GetWin','Interactive');
figure(F);clf
... ... @@ -47,110 +48,111 @@ for i0=1:size(t,1)
Data=D(:,:);
switch S.method
case 'linear'
for i1=1:length(ev)
if mod(i1,200)==0
disp([i1 length(ev)])
end
% if ~isempty(intersect(EventType,ev(i1).value))
if ~isempty(intersect(EventType,ev(i1).type))
ind=indsample(D,ev(i1).time);
tmp1=D(:,ind+[StartInterpolation EndInterpolation]);
tmp2=zeros(size(Data,1),length([StartInterpolation:EndInterpolation]));
for i2=1:size(Data,1)
tmp2(i2,:)=interp1([StartInterpolation EndInterpolation],tmp1(i2,:),[StartInterpolation:EndInterpolation]);
for i1=1:length(ev)
if mod(i1,200)==0
disp([i1 length(ev)])
end
% if ~isempty(intersect(EventType,ev(i1).value))
if ~isempty(intersect(EventType,ev(i1).type))
ind=indsample(D,ev(i1).time);
tmp1=D(:,ind+[StartInterpolation EndInterpolation]);
tmp2=zeros(size(Data,1),length([StartInterpolation:EndInterpolation]));
for i2=1:size(Data,1)
tmp2(i2,:)=interp1([StartInterpolation EndInterpolation],tmp1(i2,:),[StartInterpolation:EndInterpolation]);
end
Data(:,ind+[StartInterpolation:EndInterpolation])=tmp2;
end
end
Data(:,ind+[StartInterpolation:EndInterpolation])=tmp2;
end
end
case 'spline'
ind1=[];
ind2=[];
for i1=1:length(ev)
% if ~isempty(intersect(EventType,ev(i1).value))
if ~isempty(intersect(EventType,ev(i1).type))
ind=indsample(D,ev(i1).time);
ind1=[ind1 ind+StartInterpolation];
ind2=[ind2 ind+EndInterpolation];
end
end
ind1=sort(ind1);
ind2=sort(ind2);
Time=time(D);
Index=1:length(Time);
for i1=1:length(ind1)
Index=setdiff(Index,ind1(i1):ind2(i1));
end
Time2=Time(Index);
for i1=1:size(Data,1)
Data(i1,:) = spline(Time2,Data(i1,Index),Time);
end
case 'spline'
ind1=[];
ind2=[];
for i1=1:length(ev)
% if ~isempty(intersect(EventType,ev(i1).value))
if ~isempty(intersect(EventType,ev(i1).type))
ind=indsample(D,ev(i1).time);
ind1=[ind1 ind+StartInterpolation];
ind2=[ind2 ind+EndInterpolation];
end
end
ind1=sort(ind1);
ind2=sort(ind2);
Time=time(D);
Index=1:length(Time);
for i1=1:length(ind1)
Index=setdiff(Index,ind1(i1):ind2(i1));
end
Time2=Time(Index);
for i1=1:size(Data,1)
Data(i1,:) = spline(Time2,Data(i1,Index),Time);
end
case 'other'
NCompo=2;
CCthresh=0.5;
ind12=[];
ind22=[];
for i1=1:length(ev)
% if ~isempty(intersect(EventType,ev(i1).value))
if strcmp(EventType,strvcat(ev(i1).type))
ind=indsample(D,ev(i1).time);
ind12=[ind12 ind+StartInterpolation*3];
ind22=[ind22 ind+EndInterpolation*3];
end
end
ind12=sort(ind12);
ind22=sort(ind22);
Index2=[];
for i1=1:length(ind12)
Index2=[Index2 ind12(i1):ind22(i1)];
end
[u s v]=svd(Data(:,Index2)',0);
f=abs(fft(u));
CC=zeros(1,size(f,2));
for i1=1:size(f,2)
cc=corrcoef(f(:,1),f(:,i1));
CC(i1)=cc(2);
NCompo=2;
CCthresh=0.5;
ind12=[];
ind22=[];
for i1=1:length(ev)
% if ~isempty(intersect(EventType,ev(i1).value))
if strcmp(EventType,strvcat(ev(i1).type))
ind=indsample(D,ev(i1).time);
ind12=[ind12 ind+StartInterpolation*3];
ind22=[ind22 ind+EndInterpolation*3];
end
end
ind12=sort(ind12);
ind22=sort(ind22);
Index2=[];
for i1=1:length(ind12)
Index2=[Index2 ind12(i1):ind22(i1)];
end
[u s v]=svd(Data(:,Index2)',0);
f=abs(fft(u));
CC=zeros(1,size(f,2));
for i1=1:size(f,2)
cc=corrcoef(f(:,1),f(:,i1));
CC(i1)=cc(2);
end
CompoArtefact=find(CC>CCthresh);
% s=diag(s);
% s(CompoArtefact)=0;
% s=diag(s);
U=u(:,CompoArtefact);
windowSize = round(1*size(U,1)/length(ev));
for i1=1:length(CompoArtefact)
U2(:,i1)=2*U(:,i1)-filter(ones(1,windowSize)/windowSize,1,U(:,i1))-flipud(filter(ones(1,windowSize)/windowSize,1,flipud(U(:,i1))));
end
% Artefact=ImaGIN_Normalisation(sum(abs(U2),2),1);
Artefact=ImaGIN_normalisation(sum(abs(U2),2),1);
windowSize = round(1*length(Artefact)/length(ev));
Artefact=2*Artefact-filter(ones(1,windowSize)/windowSize,1,Artefact)-flipud(filter(ones(1,windowSize)/windowSize,1,flipud(Artefact)));
Index3=setdiff(1:length(Artefact),setdiff(find(Artefact>0.5),[1 length(Artefact)]));
Time3=Time(Index2);
Time4=Time3(Index3);
% for i1=1:NCompo
for i1=CompoArtefact
% u(:,i1) = spline(Time4,u(Index3,i1),Time3);
u(:,i1) = interp1(Time4,u(Index3,i1),Time3,'linear');
end
Data(:,Index2)=transpose(u*s*v');
end
CompoArtefact=find(CC>CCthresh);
% s=diag(s);
% s(CompoArtefact)=0;
% s=diag(s);
U=u(:,CompoArtefact);
windowSize = round(1*size(U,1)/length(ev));
for i1=1:length(CompoArtefact)
U2(:,i1)=2*U(:,i1)-filter(ones(1,windowSize)/windowSize,1,U(:,i1))-flipud(filter(ones(1,windowSize)/windowSize,1,flipud(U(:,i1))));
end
Artefact=ImaGIN_Normalisation(sum(abs(U2),2),1);
windowSize = round(1*length(Artefact)/length(ev));
Artefact=2*Artefact-filter(ones(1,windowSize)/windowSize,1,Artefact)-flipud(filter(ones(1,windowSize)/windowSize,1,flipud(Artefact)));
Index3=setdiff(1:length(Artefact),setdiff(find(Artefact>0.5),[1 length(Artefact)]));
Time3=Time(Index2);
Time4=Time3(Index3);
% for i1=1:NCompo
for i1=CompoArtefact
% u(:,i1) = spline(Time4,u(Index3,i1),Time3);
u(:,i1) = interp1(Time4,u(Index3,i1),Time3,'linear');
end
Data(:,Index2)=transpose(u*s*v');
end
%Save as a newfile
D=clone(D,['i' D.fname], [D.nchannels D.nsamples D.ntrials]);
D(:,:,:)=Data;
... ...