Authored by Olivier David

Correction of Stim Detect to avoid isolated stimulations at the end of runs

... ... @@ -504,6 +504,7 @@ for c = 1:length(KeepEvent) % Navigate all stim events
disp(KeepEvent(c)), disp(S.EvtName);
S.StimDetectVersion = StimDetectVersion ;
S.minStim= minStim;
[stimTime,~,~] = ImaGIN_StimDetect(S);
stimFq = StimFreq;
... ...
... ... @@ -229,7 +229,7 @@ end
Dfile = fullfile(D);
% Copy results of spike analysis in the file structure
Dmat.D.Firing.data = S;
D = Dmat;
D = Dmat.D;
% Save file
save(Dfile, 'D');
... ...
... ... @@ -36,6 +36,12 @@ catch
end
try
minStim=S.minStim;
catch
minStim=spm_input('Minimal number of stimulations', '+1', 'r');
end
try
FindBadChannels=S.FindBadChannels;
catch
FindBadChannels=1;
... ... @@ -235,7 +241,7 @@ if 1==1
% if length(stimulation)>1
% Stim=median(diff(stimulation)); %estimate actual stimulation frequency
% end
stimulation = removeOutliers( stimulation, Stim ) ;
stimulation = removeOutliers( stimulation, Stim , minStim) ;
stimulation = stimulation(find(stimulation>round( 0.95 * Stim/2 )&stimulation+round( 0.95 * Stim/2 )<=length(d)))
% end
... ... @@ -680,15 +686,15 @@ else
end
%Threshold cc
Threshold=0.5;
Threshold=0.4;
tmp=find(cc>Threshold);
stimulation=tmp;
end
%remove outliers close to other stims
stimulation = removeOutliers( stimulation, Stim ) ;
%remove outliers close to other stims or isolated clusters
stimulation = removeOutliers( stimulation, Stim , minStim) ;
if isempty(stimulation)
... ... @@ -774,8 +780,8 @@ fclose(fid);
end
%remove outliers close to other stims
function stimulation = removeOutliers( stimulation, Stim )
%remove outliers close to other stims or isolated
function stimulation = removeOutliers( stimulation, Stim , minStim)
if length(stimulation)>1
remove=[];
... ... @@ -789,4 +795,22 @@ if length(stimulation)>1
stimulation=stimulation(setdiff(1:length(stimulation),remove));
end
%remove isolated stimulations (short clusters)
dstimulation=diff(stimulation);
index = find(dstimulation>=1.1*Stim);
if ~isempty(index)
index = unique([1 index+1 length(stimulation)+1]);
dindex = diff(index);
remove=[];
for i1=2:length(dindex)
if dindex(i1)<minStim
remove=[remove sum(dindex(1:i1-1))+[1:dindex(i1)]];
end
end
% StimulationFreqU=D.fsample/median(diff(stimulation)); %uncorrected stim frequency
stimulation=stimulation(setdiff(1:length(stimulation),remove));
end
end
... ...
... ... @@ -198,6 +198,15 @@ for i1 = Bad
evt(n3).time = d(i2);
evt(n3).value=n4;
end
%for vero
if header.kind==2
n2=n2+1;
data.spike.timings{n2}=d;
data.spike.markers{n2}=[ones(length(d),1) zeros(length(d),3)];
data.spike.name{n2}=header.title;
data.spike.FileChannel(n2)=header.FileChannel;
end
%
elseif header.kind==5
n4=n4+1;
for i2=1:size(d.timings,1)
... ...
... ... @@ -104,6 +104,7 @@ for i1 = 1:Nfiles
BstFormat = [];
switch lower(fExt)
case '.smr'
S.channel = S.SelectChannels;
S2 = ImaGIN_copy_fields(S2, S, {'CreateTemplate', 'Fchannels', 'Bipolar', 'Montage', 'epochlength', 'coarse', 'channel'});
D{i1} = ImaGIN_spm_eeg_rdata_spike2_mono(S2);
... ...