added fano factor exercise
This commit is contained in:
37
pointprocesses/code/fanoplot.m
Normal file
37
pointprocesses/code/fanoplot.m
Normal file
@@ -0,0 +1,37 @@
|
||||
function fanoplot( spikes )
|
||||
% computes fano factor as a function of window size
|
||||
% spikes: a cell array of vectors of spike times
|
||||
|
||||
tmax = spikes{1}(end);
|
||||
windows = 0.01:0.05:0.01*tmax;
|
||||
mc = windows;
|
||||
vc = windows;
|
||||
ff = windows;
|
||||
for j = 1:length(windows)
|
||||
w = windows( j );
|
||||
% collect counts:
|
||||
n = [];
|
||||
for k = 1:length(spikes)
|
||||
for tk = 0:w:tmax-w
|
||||
nn = sum( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) );
|
||||
%nn = length( find( ( spikes{k} >= tk ) & ( spikes{k} < tk+w ) ) );
|
||||
n = [ n nn ];
|
||||
end
|
||||
end
|
||||
% statistics for current window:
|
||||
mc(j) = mean( n );
|
||||
vc(j) = var( n );
|
||||
ff(j) = vc( j )/mc( j );
|
||||
end
|
||||
|
||||
subplot( 1, 2, 1 );
|
||||
scatter( mc, vc, 'filled' );
|
||||
xlabel( 'Mean count' );
|
||||
ylabel( 'Count variance' );
|
||||
|
||||
subplot( 1, 2, 2 );
|
||||
scatter( 1000.0*windows, ff, 'filled' );
|
||||
xlabel( 'Window W [ms]' );
|
||||
ylabel( 'Fano factor' );
|
||||
end
|
||||
|
||||
29
pointprocesses/code/spikecounts.m
Normal file
29
pointprocesses/code/spikecounts.m
Normal file
@@ -0,0 +1,29 @@
|
||||
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};
|
||||
% 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)));
|
||||
% counts = [counts nn];
|
||||
% end
|
||||
% alternative 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
|
||||
Reference in New Issue
Block a user