Commit 213e23f5 authored by Andrew Matas's avatar Andrew Matas

added function to identify bad times where whitened data exceeds threshold and...

added function to identify bad times where whitened data exceeds threshold and cluster pionts within a given window
parent 12f2ade2
function bad_times=get_bad_times(timeseries,threshold,gating_duration)
% whiten time series
wts=whiten(timeseries);
% look for points above threshold
cut=abs(wts.data)>threshold;
%keyboard
idx_times=1:length(wts.data);
times=wts.tlow+wts.deltaT*(idx_times-1);
peaks.times=times(cut);
peaks.data=wts.data(cut);
% clustering
% loop over all points above threshold
% for each point, check if there are any other points withing gating_duration
% if there is, remove the smaller peak from the list of peaks
% iterate until no peaks are removed (then we have a stable, clustered list)
done=false;
while ~done
cut=logical(ones(1,length(peaks.times)));
for ii=1:length(peaks.times)
for jj=1:length(peaks.times)
if (ii~=jj) && (abs(peaks.times(ii)-peaks.times(jj)) < gating_duration/2)
if abs(peaks.data(ii)) < abs(peaks.data(jj))
cut(jj)=false;
else
cut(ii)=false;
end
end
end
end
peaks.times=peaks.times(cut);
peaks.data=peaks.data(cut);
if sum(cut)==length(cut) % no falses aka no peaks to remove
done=true;
end
end
bad_times=peaks.times;
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment