How can ı do spike sorting to filtered EEG signal.

11 views (last 30 days)
I have this sample and ı need to do spike sorting. I start with finding thresholding value and want to see changes with this code. I have trouble with plotting in for loop and also further steps. I am very new in Matlab. If you can help it would be great thank you.
for k = 1:0.1:5
omg = median(abs(samp)/0.6745);
Thr =k * omg;
[pks, locs] = findpeaks(samp);
findpeaks(samp, 'Threshold', Thr);
[r,NumPeaks] = size(pks);
NumPeaks
end
hold on

Accepted Answer

Star Strider
Star Strider on 13 Dec 2018
Try this:
D = load('samp.mat');
samp = D.samp;
data = 1E-3; % What Are ‘data’?
omg = median(abs(data)/0.6745);
% th = 1:0.1:5;
th = 5 : -0.1 : 1; % Easier To Count Down Here
for k = 1:numel(th)
Thr = th(k) * omg;
[pks{k}, locs{k}] = findpeaks(samp, 'Threshold', Thr); % Peaks Above This ‘Thr’ Value
kprv = max(k-1,1); % Previous Index Value
lv = ~ismember(locs{k},locs{kprv}); % Spikes Above Current ‘Thr’ & Below Previous ‘Thr’
nspikes(k) = nnz(lv); % Number Of Spikes Above Current ‘Thr’ & Below Previous ‘Thr’
ThrPks{k} = pks{k}(lv); % Peak Amplitudes Above Current ‘Thr’ & Below Previous ‘Thr’
ThrLcs{k} = locs{k}(lv); % Locations Of Peak Amplitudes Above Current ‘Thr’ & Below Previous ‘Thr’
end
figure
bar(th, nspikes)
xlabel('Threshold')
ylabel('# Spikes')
I am not certain what you want, so I saved everything about your data in my code.
  2 Comments
kaan bakircioglu
kaan bakircioglu on 13 Dec 2018
Thank you very much for this code. I needed this because ı need to set an empirical rule for the ? parameter so that the number of spikes for each extracellular signal is close to the real number.
Star Strider
Star Strider on 13 Dec 2018
My pleasure.
If my Answer helps you solve your problem, please Accept it!

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 12 Dec 2018
Not sure what you want to do. Do you just want to order them based on height at the peaks? If so
[sortedPeakValues, sortOrder] = sort(pks);
sortedIndexes = loc(sortOrder);
  5 Comments
Image Analyst
Image Analyst on 14 Dec 2018
It's really the threshold that you want to set, not the k. I'm not sure which peaks in the data are desired one and which are noise ones. The data itself doesn't say - basically it's a judgment call. There is no one, true, God-given correct answer. So you have to specify the threshold using your expert knowledge. Whatever works best for you is the right answer.

Sign in to comment.

Categories

Find more on Electrophysiology in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!