[pointprocesses] improved chapter
This commit is contained in:
@@ -1,16 +1,11 @@
|
||||
function [counts, bins] = counthist(spikes, w)
|
||||
% Compute and plot histogram of spike counts.
|
||||
function counthist(spikes, w)
|
||||
% Plot histogram of spike counts.
|
||||
%
|
||||
% [counts, bins] = counthist(spikes, w)
|
||||
% counthist(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: the histogram of counts normalized to probabilities
|
||||
% bins: the bin centers for the histogram
|
||||
|
||||
% w: duration of window in seconds for computing the counts
|
||||
% collect spike counts:
|
||||
tmax = spikes{1}(end);
|
||||
n = [];
|
||||
@@ -21,12 +16,12 @@ function [counts, bins] = counthist(spikes, w)
|
||||
% for tk = 0:w:tmax-w
|
||||
% nn = sum((times >= tk) & (times < tk+w));
|
||||
% %nn = length(find((times >= tk) & (times < tk+w)));
|
||||
% n = [n nn];
|
||||
% 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];
|
||||
n = [n, nn];
|
||||
end
|
||||
|
||||
% histogram of spike counts:
|
||||
@@ -36,9 +31,7 @@ function [counts, bins] = counthist(spikes, w)
|
||||
counts = counts / sum(counts);
|
||||
|
||||
% plot:
|
||||
if nargout == 0
|
||||
bar(bins, counts);
|
||||
xlabel('counts k');
|
||||
ylabel('P(k)');
|
||||
end
|
||||
bar(bins, counts);
|
||||
xlabel('counts k');
|
||||
ylabel('P(k)');
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ function [pdf, centers] = isihist(isis, binwidth)
|
||||
% binwidth: optional width in seconds to be used for the isi bins
|
||||
%
|
||||
% Returns:
|
||||
% pdf: vector with probability density of interspike intervals in Hz
|
||||
% pdf: vector with pdf of interspike intervals in Hertz
|
||||
% centers: vector with centers of interspikeintervalls in seconds
|
||||
|
||||
if nargin < 2
|
||||
|
||||
@@ -5,11 +5,9 @@ function isivec = isis(spikes)
|
||||
%
|
||||
% Arguments:
|
||||
% spikes: a cell array of vectors of spike times in seconds
|
||||
% isivec: a column vector with all the interspike intervalls
|
||||
%
|
||||
% Returns:
|
||||
% isivec: a column vector with all the interspike intervalls
|
||||
|
||||
isivec = [];
|
||||
for k = 1:length(spikes)
|
||||
difftimes = diff(spikes{k});
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
function isicorr = isiserialcorr(isivec, maxlag)
|
||||
function [isicorr, lags] = isiserialcorr(isivec, maxlag)
|
||||
% serial correlation of interspike intervals
|
||||
%
|
||||
% isicorr = isiserialcorr(isivec, maxlag)
|
||||
%
|
||||
% Arguments:
|
||||
% isivec: vector of interspike intervals in seconds
|
||||
% maxlag: the maximum lag in seconds
|
||||
% maxlag: the maximum lag
|
||||
%
|
||||
% Returns:
|
||||
% isicorr: vector with the serial correlations for lag 0 to maxlag
|
||||
|
||||
% lags: vector with the lags corresponding to isicorr
|
||||
lags = 0:maxlag;
|
||||
isicorr = zeros(size(lags));
|
||||
for k = 1:length(lags)
|
||||
@@ -21,14 +21,4 @@ function isicorr = isiserialcorr(isivec, maxlag)
|
||||
isicorr(k) = corr(isivec(1:end-lag), isivec(lag+1:end));
|
||||
end
|
||||
end
|
||||
|
||||
if nargout == 0
|
||||
% plot:
|
||||
plot(lags, isicorr, '-b');
|
||||
hold on;
|
||||
scatter(lags, isicorr, 50.0, 'b', 'filled');
|
||||
hold off;
|
||||
xlabel('Lag k')
|
||||
ylabel('\rho_k')
|
||||
end
|
||||
end
|
||||
|
||||
16
pointprocesses/code/plotisiserialcorr.m
Normal file
16
pointprocesses/code/plotisiserialcorr.m
Normal file
@@ -0,0 +1,16 @@
|
||||
function isicorr = plotisiserialcorr(isivec, maxlag)
|
||||
% plot serial correlation of interspike intervals
|
||||
%
|
||||
% plotisiserialcorr(isivec, maxlag)
|
||||
%
|
||||
% Arguments:
|
||||
% isivec: vector of interspike intervals in seconds
|
||||
% maxlag: the maximum lag
|
||||
[isicorr, lags] = isiserialcorr(isivec, maxlag);
|
||||
plot(lags, isicorr, '-b');
|
||||
hold on;
|
||||
scatter(lags, isicorr, 20.0, 'b', 'filled');
|
||||
hold off;
|
||||
xlabel('Lag k')
|
||||
ylabel('\rho_k')
|
||||
end
|
||||
@@ -2,21 +2,35 @@ function rasterplot(spikes, tmax)
|
||||
% Display a spike raster of the spike times given in spikes.
|
||||
%
|
||||
% rasterplot(spikes, tmax)
|
||||
%
|
||||
% Arguments:
|
||||
% spikes: a cell array of vectors of spike times in seconds
|
||||
% tmax: plot spike raster upto tmax seconds
|
||||
|
||||
% tmax: plot spike raster up to tmax seconds
|
||||
in_msecs = tmax < 1.5
|
||||
spiketimes = [];
|
||||
trials = [];
|
||||
ntrials = length(spikes);
|
||||
for k = 1:ntrials
|
||||
times = spikes{k};
|
||||
times = times(times<tmax);
|
||||
if tmax < 1.5
|
||||
times = 1000.0*times; % conversion to ms
|
||||
end
|
||||
for i = 1:length( times )
|
||||
line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k');
|
||||
if in_msecs
|
||||
times = 1000.0*times; % conversion to ms
|
||||
end
|
||||
% (x,y) pairs for start and stop of stroke
|
||||
% plus nan separating strokes:
|
||||
spiketimes = [spiketimes, ...
|
||||
[times(:)'; times(:)'; times(:)'*nan]];
|
||||
trials = [trials, ...
|
||||
[ones(1, length(times)) * (k-0.4); ...
|
||||
ones(1, length(times)) * (k+0.4); ...
|
||||
ones(1, length(times)) * nan]];
|
||||
end
|
||||
if tmax < 1.5
|
||||
% convert matrices into simple vectors of (x,y) pairs:
|
||||
spiketimes = spiketimes(:);
|
||||
trials = trials(:);
|
||||
% plotting this is lightning fast:
|
||||
plot(spiketimes, trials, 'k')
|
||||
if in_msecs
|
||||
xlabel('Time [ms]');
|
||||
xlim([0.0 1000.0*tmax]);
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user