function spikes = hompoissonspikes( 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;
    if p > 0.2
        p = 0.2
        dt = p/rate;
    end
    x = rand( trials, ceil(tmax/dt) );
    spikes = cell( trials, 1 );
    for k=1:trials
        spikes{k} = find( x(k,:) < p ) * dt;
    end
end
