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/hompoissonspikes.m

22 lines
702 B
Matlab

function spikes = hompoissonspikes(rate, trials, tmax)
% Generate spike times of a homogeneous poisson process
% using the exponential interspike interval distribution.
%
% Arguments:
% rate: the rate of the Poisson process in Hertz
% trials: number of trials that should be generated
% tmax: the duration of each trial in seconds
%
% Returns:
% spikes: a cell array of vectors of spike times in seconds
spikes = cell(trials, 1);
mu = 1.0/rate;
nintervals = 2*round(tmax/mu);
for k=1:trials
% exponential random numbers:
intervals = random('Exponential', mu, nintervals, 1);
times = cumsum(intervals);
spikes{k} = times(times<=tmax);
end
end