function r = spikerate(spikes, duration)
% returns the average spike rate of the spikes
% for the first duration seconds
% spikes: a cell array of vectors of spike times

    rates = zeros(length(spikes),1);
    for k = 1:length(spikes)
        times = spikes{k};
        rates(k) = sum(times<duration)/duration;
    end
    r = mean(rates);
end
