This repository has been archived on 2021-05-17. You can view files and clone it, but cannot push or open issues or pull requests.
scientificComputing/pointprocesses/code/poissonspikes.m

21 lines
654 B
Matlab

function spikes = poissonspikes( trials, rate, tmax )
% Generate spike times of a homogeneous poisson process
% trials: number of trials that should be generated
% rate: the rate of the Poisson process in Hertz
% tmax: the duration of each trial in seconds
% returns a cell array of vectors of spike times
dt = 3.33e-5;
p = rate*dt; % probability of event per bin of width dt
% make sure p is small enough:
if p > 0.1
p = 0.1
dt = p/rate;
end
spikes = cell(trials, 1);
for k=1:trials
x = rand(round(tmax/dt), 1); % uniform random numbers for each bin
spikes{k} = find(x < p) * dt;
end
end