[pointprocesses] improved code

This commit is contained in:
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

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

View File

@@ -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);
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
if tmax < 1.5
times = 1000.0*times; % conversion to ms
xlabel('Time [ms]');
xlim([0.0 1000.0*tmax]);
else
xlabel('Time [s]');
xlim([0.0 tmax]);
end
for i = 1:length( times )
line([times(i) times(i)],[k-0.4 k+0.4], 'Color', 'k');
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