function spikes = hompoissonspikes(rate, trials, tmax)
% Generate spike times of a homogeneous poisson process
% using the exponential interspike interval distribution.
%
% spikes = hompoissonspikes(rate, trials, tmax)
%
% 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', nintervals, 1);
        times = cumsum(intervals);
        spikes{k} = times(times<=tmax);
    end
end
