[pointprocesses] moved exercise codes to exercise folder
This commit is contained in:
25
pointprocesses/code/counts.m
Normal file
25
pointprocesses/code/counts.m
Normal file
@@ -0,0 +1,25 @@
|
||||
function n = counts(spikes, w)
|
||||
% Count spikes in time windows.
|
||||
%
|
||||
% Arguments:
|
||||
% spikes: a cell array of vectors of spike times in seconds
|
||||
% w: duration of window in seconds for computing the counts
|
||||
%
|
||||
% Returns:
|
||||
% n: vector with spike counts
|
||||
tmax = spikes{1}(end);
|
||||
n = [];
|
||||
for k = 1:length(spikes)
|
||||
times = spikes{k};
|
||||
% alternative 1: count the number of spikes in each window:
|
||||
% for tk = 0:w:tmax-w
|
||||
% nn = sum((times >= tk) & (times < tk+w));
|
||||
% % nn = length(find((times >= tk) & (times < tk+w)));
|
||||
% n = [n, nn];
|
||||
% end
|
||||
% alternative 2: use the hist() function to do that!
|
||||
tbins = 0.5*w:w:tmax-0.5*w;
|
||||
nn = hist(times, tbins);
|
||||
n = [n, nn];
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
function counthist(spikes, w)
|
||||
function plotcounthist(spikes, w)
|
||||
% Plot histogram of spike counts.
|
||||
%
|
||||
% Arguments:
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
maxisi = 300.0;
|
||||
subplot(1, 3, 1);
|
||||
poissonisis = isis(poissonspikes);
|
||||
plotisihist(poissonisis, 0.001);
|
||||
xlim([0, maxisi])
|
||||
title('Poisson');
|
||||
|
||||
subplot(1, 3, 2);
|
||||
pifouisis = isis(pifouspikes);
|
||||
plotisihist(pifouisis, 0.001);
|
||||
xlim([0, maxisi])
|
||||
title('PIF OU');
|
||||
|
||||
subplot(1, 3, 3);
|
||||
lifadaptisis = isis(lifadaptspikes);
|
||||
plotisihist(lifadaptisis, 0.001);
|
||||
xlim([0, maxisi])
|
||||
title('LIF adapt');
|
||||
savefigpdf(gcf, 'isihist.pdf', 20, 7);
|
||||
@@ -1,17 +0,0 @@
|
||||
maxlag = 10;
|
||||
rrange = [-0.5, 1.05];
|
||||
subplot(1, 3, 1);
|
||||
isiserialcorr(poissonisis, maxlag);
|
||||
ylim(rrange)
|
||||
title('Poisson');
|
||||
|
||||
subplot(1, 3, 2);
|
||||
isiserialcorr(pifouisis, maxlag);
|
||||
ylim(rrange)
|
||||
title('PIF OU');
|
||||
|
||||
subplot(1, 3, 3);
|
||||
isiserialcorr(lifadaptisis, maxlag);
|
||||
ylim(rrange)
|
||||
title('LIF adapt');
|
||||
savefigpdf(gcf, 'serialcorr.pdf', 20, 7);
|
||||
@@ -1,13 +0,0 @@
|
||||
subplot(1, 3, 1);
|
||||
rasterplot(poissonspikes, 1.0);
|
||||
title('Poisson');
|
||||
|
||||
subplot(1, 3, 2);
|
||||
rasterplot(pifouspikes, 1.0);
|
||||
title('PIF OU');
|
||||
|
||||
subplot(1, 3, 3);
|
||||
rasterplot(lifadaptspikes, 1.0);
|
||||
title('LIF adapt');
|
||||
|
||||
savefigpdf(gcf, 'spikeraster.pdf', 15, 5);
|
||||
@@ -1,30 +0,0 @@
|
||||
function counts = spikecounts(spikes, w)
|
||||
% Compute vector of spike counts.
|
||||
%
|
||||
% counts = spikecounts(spikes, w)
|
||||
%
|
||||
% Arguments:
|
||||
% spikes: a cell array of vectors of spike times in seconds
|
||||
% w: observation window duration in seconds for computing the counts
|
||||
%
|
||||
% Returns:
|
||||
% counts: vector of spike counts
|
||||
|
||||
% collect spike counts:
|
||||
tmax = spikes{1}(end);
|
||||
counts = [];
|
||||
for k = 1:length(spikes)
|
||||
times = spikes{k};
|
||||
% method 1: count the number of spikes in each window:
|
||||
% for tk = 0:w:tmax-w
|
||||
% nn = sum((times >= tk) & (times < tk+w));
|
||||
% %nn = length(times((times >= tk) & (times < tk+w)));
|
||||
% %nn = length(find((times >= tk) & (times < tk+w)));
|
||||
% counts = [counts nn];
|
||||
% end
|
||||
% method 2: use the hist() function to do that!
|
||||
tbins = 0.5*w:w:tmax-0.5*w;
|
||||
nn = hist(times, tbins);
|
||||
counts = [counts nn];
|
||||
end
|
||||
end
|
||||
@@ -1,17 +0,0 @@
|
||||
w = 0.1;
|
||||
bins = 0.0:1.0:10.0;
|
||||
|
||||
counts{1} = spikecounts(poissonspikes, w);
|
||||
counts{2} = spikecounts(pifouspikes, w);
|
||||
counts{3} = spikecounts(lifadaptspikes, w);
|
||||
titles = {'Poisson', 'PIF OU', 'LIF adapt'};
|
||||
for k = 1:3
|
||||
subplot(1, 3, k);
|
||||
[h, b] = hist(counts{k}, bins);
|
||||
bar(b, h/sum(h));
|
||||
title(titles{k})
|
||||
xlabel('Spike count');
|
||||
xlim([-0.5, 8.5]);
|
||||
ylim([0.0 0.8]);
|
||||
end
|
||||
savefigpdf(gcf, 'spikecountshists.pdf', 20, 7);
|
||||
Reference in New Issue
Block a user