|
@ -14,11 +14,10 @@ |
|
|
datasetMedians(8) = 0; |
|
|
datasetMedians(8) = 0; |
|
|
datasetFactors(8) = 0; |
|
|
datasetFactors(8) = 0; |
|
|
|
|
|
|
|
|
thresholdFactorInitValue = 3; % k starting value |
|
|
thresholdFactorInitValue = 1; % k starting value |
|
|
thresholdFactorEndValue = 12; % k ending value |
|
|
thresholdFactorEndValue = 7; % k ending value |
|
|
thresholdFactorStep = 0.01; % k jumping step |
|
|
thresholdFactorStep = 0.01; % k jumping step |
|
|
numberOfFactors = length(thresholdFactorInitValue:thresholdFactorStep:thresholdFactorEndValue); |
|
|
numberOfFactors = length(thresholdFactorInitValue:thresholdFactorStep:thresholdFactorEndValue); |
|
|
numberOfSpikesPerFactor(numberOfFactors) = 0; |
|
|
|
|
|
|
|
|
|
|
|
for fileIndex=1:8 |
|
|
for fileIndex=1:8 |
|
|
fprintf('Loading test dataset no. %d\n', fileIndex); |
|
|
fprintf('Loading test dataset no. %d\n', fileIndex); |
|
@ -38,6 +37,7 @@ for fileIndex=1:8 |
|
|
%% Q.1.2 |
|
|
%% Q.1.2 |
|
|
dataMedian = median(abs(data)/0.6745); |
|
|
dataMedian = median(abs(data)/0.6745); |
|
|
datasetMedians(fileIndex) = dataMedian; |
|
|
datasetMedians(fileIndex) = dataMedian; |
|
|
|
|
|
numberOfSpikesPerFactor(numberOfFactors) = 0; |
|
|
|
|
|
|
|
|
for factorIteration=1:numberOfFactors % runs for each k |
|
|
for factorIteration=1:numberOfFactors % runs for each k |
|
|
% builds threshold |
|
|
% builds threshold |
|
@ -84,6 +84,7 @@ for fileIndex=1:8 |
|
|
|
|
|
|
|
|
clear Dataset |
|
|
clear Dataset |
|
|
clear data |
|
|
clear data |
|
|
|
|
|
clear numberOfSpikesPerFactor |
|
|
end |
|
|
end |
|
|
fprintf('\n'); |
|
|
fprintf('\n'); |
|
|
|
|
|
|
|
@ -95,7 +96,7 @@ xlabel('Dataset median'); |
|
|
ylabel('Threshold factor'); |
|
|
ylabel('Threshold factor'); |
|
|
hold on; |
|
|
hold on; |
|
|
|
|
|
|
|
|
empiricalRule = polyfit(datasetMedians, datasetFactors, 8); |
|
|
empiricalRule = polyfit(datasetMedians, datasetFactors, 1); |
|
|
visualizationX = linspace(0, 0.5, 50); |
|
|
visualizationX = linspace(0, 0.5, 50); |
|
|
visualizationY = polyval(empiricalRule, visualizationX); |
|
|
visualizationY = polyval(empiricalRule, visualizationX); |
|
|
plot(visualizationX, visualizationY); |
|
|
plot(visualizationX, visualizationY); |
|
@ -118,8 +119,8 @@ for fileIndex=1:4 |
|
|
%% Q.2.1 and Q.2.2 |
|
|
%% Q.2.1 and Q.2.2 |
|
|
dataMedian = median(abs(data)/0.6745); |
|
|
dataMedian = median(abs(data)/0.6745); |
|
|
|
|
|
|
|
|
%factorEstimation = polyval(empiricalRule, dataMedian); |
|
|
factorEstimation = polyval(empiricalRule, dataMedian); |
|
|
factorEstimation = 4; |
|
|
%factorEstimation = 4; |
|
|
threshold = factorEstimation * dataMedian; |
|
|
threshold = factorEstimation * dataMedian; |
|
|
numberOfSpikes = 0; |
|
|
numberOfSpikes = 0; |
|
|
spikesTimesEst(2500) = 0; |
|
|
spikesTimesEst(2500) = 0; |
|
@ -144,7 +145,9 @@ for fileIndex=1:4 |
|
|
% spike found |
|
|
% spike found |
|
|
numberOfSpikes = numberOfSpikes + 1; |
|
|
numberOfSpikes = numberOfSpikes + 1; |
|
|
spikeStartIndex = sample; |
|
|
spikeStartIndex = sample; |
|
|
|
|
|
% Q.2.1 |
|
|
|
|
|
spikesTimesEst(numberOfSpikes) = spikeStartIndex; |
|
|
|
|
|
|
|
|
% skips cheking until values are below threshold again |
|
|
% skips cheking until values are below threshold again |
|
|
while sample <= length(data) |
|
|
while sample <= length(data) |
|
|
sample = sample + 1; |
|
|
sample = sample + 1; |
|
@ -163,8 +166,6 @@ for fileIndex=1:4 |
|
|
% occurs first |
|
|
% occurs first |
|
|
firstIndex = min([absoluteMaxIndex absoluteMinIndex]); |
|
|
firstIndex = min([absoluteMaxIndex absoluteMinIndex]); |
|
|
|
|
|
|
|
|
% Q.2.1 |
|
|
|
|
|
spikesTimesEst(numberOfSpikes) = firstIndex; |
|
|
|
|
|
% Q.2.2 |
|
|
% Q.2.2 |
|
|
spikesEst(numberOfSpikes, :) = data(firstIndex-34:firstIndex+29); |
|
|
spikesEst(numberOfSpikes, :) = data(firstIndex-34:firstIndex+29); |
|
|
break; |
|
|
break; |
|
|