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/spike_trains/code/binned_rate.m
2015-10-30 19:16:36 +01:00

17 lines
585 B
Matlab

function [time, rate] = binned_rate(spike_times, bin_width, dt, t_max)
% Calculates the firing rate with the binning method. The hist funciton is
% used to count the number of spikes in each bin.
% Function takes the spike times, the width of the bins in seconds as well
% as the temporal resolution and the tiral duration.
%
% Returns two vectors containing the time and the rate.
time = 0:dt:t_max-dt;
bins = 0:bin_width:t_max;
rate = zeros(size(time));
h = hist(spike_times, bins) ./bin_width;
for i = 2:length(bins)
rate(round(bins(i-1)/dt)+1:round(bins(i)/dt)) = h(i);
end