From 257c89d8adab4f8c6ce7be26a598a96b21b56921 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Sun, 30 Dec 2018 21:21:06 +0200 Subject: [PATCH] Critical fixes --- spike_sorting.m | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spike_sorting.m b/spike_sorting.m index 8ebd965..114764b 100644 --- a/spike_sorting.m +++ b/spike_sorting.m @@ -14,11 +14,10 @@ datasetMedians(8) = 0; datasetFactors(8) = 0; -thresholdFactorInitValue = 3; % k starting value -thresholdFactorEndValue = 12; % k ending value +thresholdFactorInitValue = 1; % k starting value +thresholdFactorEndValue = 7; % k ending value thresholdFactorStep = 0.01; % k jumping step numberOfFactors = length(thresholdFactorInitValue:thresholdFactorStep:thresholdFactorEndValue); -numberOfSpikesPerFactor(numberOfFactors) = 0; for fileIndex=1:8 fprintf('Loading test dataset no. %d\n', fileIndex); @@ -38,6 +37,7 @@ for fileIndex=1:8 %% Q.1.2 dataMedian = median(abs(data)/0.6745); datasetMedians(fileIndex) = dataMedian; + numberOfSpikesPerFactor(numberOfFactors) = 0; for factorIteration=1:numberOfFactors % runs for each k % builds threshold @@ -84,6 +84,7 @@ for fileIndex=1:8 clear Dataset clear data + clear numberOfSpikesPerFactor end fprintf('\n'); @@ -95,7 +96,7 @@ xlabel('Dataset median'); ylabel('Threshold factor'); hold on; -empiricalRule = polyfit(datasetMedians, datasetFactors, 8); +empiricalRule = polyfit(datasetMedians, datasetFactors, 1); visualizationX = linspace(0, 0.5, 50); visualizationY = polyval(empiricalRule, visualizationX); plot(visualizationX, visualizationY); @@ -118,8 +119,8 @@ for fileIndex=1:4 %% Q.2.1 and Q.2.2 dataMedian = median(abs(data)/0.6745); - %factorEstimation = polyval(empiricalRule, dataMedian); - factorEstimation = 4; + factorEstimation = polyval(empiricalRule, dataMedian); + %factorEstimation = 4; threshold = factorEstimation * dataMedian; numberOfSpikes = 0; spikesTimesEst(2500) = 0; @@ -144,7 +145,9 @@ for fileIndex=1:4 % spike found numberOfSpikes = numberOfSpikes + 1; spikeStartIndex = sample; - + % Q.2.1 + spikesTimesEst(numberOfSpikes) = spikeStartIndex; + % skips cheking until values are below threshold again while sample <= length(data) sample = sample + 1; @@ -163,8 +166,6 @@ for fileIndex=1:4 % occurs first firstIndex = min([absoluteMaxIndex absoluteMinIndex]); - % Q.2.1 - spikesTimesEst(numberOfSpikes) = firstIndex; % Q.2.2 spikesEst(numberOfSpikes, :) = data(firstIndex-34:firstIndex+29); break;