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