[pointprocesses] improved code
This commit is contained in:
parent
430bdfb7fd
commit
e2f026c53f
@ -18,7 +18,7 @@ function [time, rate] = binned_rate(spikes, bin_width, dt, t_max)
|
||||
rate = zeros(size(time));
|
||||
h = hist(spikes, bins) ./ bin_width;
|
||||
for i = 2:length(bins)
|
||||
rate(round(bins(i - 1) / dt) + 1:round(bins(i) / dt)) = h(i);
|
||||
rate(round(bins(i-1)/dt) + 1:round(bins(i)/dt)) = h(i);
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -10,19 +10,18 @@ function [time, rate] = convolution_rate(spikes, sigma, dt, t_max)
|
||||
% t_max : the trial duration in seconds.
|
||||
%
|
||||
% Returns:
|
||||
two vectors containing the time and the rate.
|
||||
% two vectors containing the time and the rate.
|
||||
|
||||
time = 0:dt:t_max - dt;
|
||||
rate = zeros(size(time));
|
||||
spike_indices = round(spikes / dt);
|
||||
rate(spike_indices) = 1;
|
||||
kernel = gaussKernel(sigma, dt);
|
||||
|
||||
rate = conv(rate, kernel, 'same');
|
||||
time = 0:dt:t_max - dt;
|
||||
rate = zeros(size(time));
|
||||
spike_indices = round(spikes / dt);
|
||||
rate(spike_indices) = 1;
|
||||
kernel = gaussKernel(sigma, dt);
|
||||
rate = conv(rate, kernel, 'same');
|
||||
end
|
||||
|
||||
|
||||
function y = gaussKernel(s, step)
|
||||
x = -4 * s:step:4 * s;
|
||||
y = exp(-0.5 .* (x ./ s) .^ 2) ./ sqrt(2 * pi) / s;
|
||||
y = exp(-0.5 .* (x ./ s).^ 2) ./ sqrt(2 * pi) / s;
|
||||
end
|
||||
|
@ -37,8 +37,8 @@ function [counts, bins] = counthist(spikes, w)
|
||||
|
||||
% plot:
|
||||
if nargout == 0
|
||||
bar( bins, counts );
|
||||
xlabel( 'counts k' );
|
||||
ylabel( 'P(k)' );
|
||||
bar(bins, counts);
|
||||
xlabel('counts k');
|
||||
ylabel('P(k)');
|
||||
end
|
||||
end
|
||||
|
@ -19,6 +19,6 @@ function [time, rate] = instantaneous_rate(spikes, dt, t_max)
|
||||
spike_indices = [1 round(spikes ./ dt)];
|
||||
|
||||
for i = 2:length(spike_indices)
|
||||
rate(spike_indices(i - 1):spike_indices(i)) = inst_rate(i - 1);
|
||||
rate(spike_indices(i-1):spike_indices(i)) = inst_rate(i-1);
|
||||
end
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ function [pdf, centers] = isihist(isis, binwidth)
|
||||
|
||||
if nargin < 2
|
||||
% compute good binwidth:
|
||||
nperbin = 200; % average number of data points per bin
|
||||
nperbin = 200; % average number of data points per bin
|
||||
bins = length(isis)/nperbin; % number of bins
|
||||
binwidth = max(isis)/bins;
|
||||
if binwidth < 5e-4 % half a millisecond
|
||||
|
@ -5,25 +5,25 @@ function rasterplot(spikes, tmax)
|
||||
% spikes: a cell array of vectors of spike times in seconds
|
||||
% tmax: plot spike raster upto tmax seconds
|
||||
|
||||
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
|
||||
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');
|
||||
end
|
||||
end
|
||||
for i = 1:length( times )
|
||||
line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k');
|
||||
if tmax < 1.5
|
||||
xlabel('Time [ms]');
|
||||
xlim([0.0 1000.0*tmax]);
|
||||
else
|
||||
xlabel('Time [s]');
|
||||
xlim([0.0 tmax]);
|
||||
end
|
||||
end
|
||||
if tmax < 1.5
|
||||
xlabel('Time [ms]');
|
||||
xlim([0.0 1000.0*tmax]);
|
||||
else
|
||||
xlabel('Time [s]');
|
||||
xlim([0.0 tmax]);
|
||||
end
|
||||
ylabel('Trials');
|
||||
ylim([0.3 ntrials+0.7 ]);
|
||||
ylabel('Trials');
|
||||
ylim([0.3 ntrials+0.7]);
|
||||
end
|
||||
|
||||
|
@ -25,9 +25,9 @@
|
||||
\item Multitrial firing rates
|
||||
\item Better explain difference between ISI method and PSTHes. The
|
||||
latter is dependent on precision of spike times the former not.
|
||||
\item Choice of bin width for PSTH, kernel width, also in relation sto
|
||||
\item Choice of bin width for PSTH, kernel width, also in relation to
|
||||
stimulus time scale
|
||||
\item Kernle firing rate: discuss different kernel shapes, in
|
||||
\item Kernel firing rate: discuss different kernel shapes, in
|
||||
particular causal kernels (gamma, exponential), relation to synaptic
|
||||
potentials
|
||||
\end{itemize}
|
||||
|
Reference in New Issue
Block a user