[pointprocesses] improved code

This commit is contained in:
Jan Benda 2020-12-07 22:51:10 +01:00
parent 430bdfb7fd
commit e2f026c53f
7 changed files with 34 additions and 35 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -5,8 +5,8 @@ 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
ntrials = length(spikes);
for k = 1:ntrials
times = spikes{k};
times = times(times<tmax);
if tmax < 1.5
@ -15,15 +15,15 @@ for k = 1:ntrials
for i = 1:length( times )
line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k');
end
end
if tmax < 1.5
end
if tmax < 1.5
xlabel('Time [ms]');
xlim([0.0 1000.0*tmax]);
else
else
xlabel('Time [s]');
xlim([0.0 tmax]);
end
ylabel('Trials');
ylim([0.3 ntrials+0.7 ]);
end
ylabel('Trials');
ylim([0.3 ntrials+0.7]);
end

View File

@ -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}