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

23 lines
609 B
Matlab

function [time, rate] = instantaneous_rate(spike_times, dt, t_max)
% Funttion takes the spike times of a single trial, the temporal
% rersolution, dt, and the duration of the trial in seconds.
% Function calculates the firing rate as the inverse of the interspike
% interval.
%
% Returns the vector representing time and a vector containing the rate.
%
time = 0:dt:t_max-dt;
rate = zeros(size(time));
isis = diff([0 spike_times]);
inst_rate = 1./isis;
spike_indices = [1 round(spike_times ./ dt)];
for i = 2:length(spike_indices)
rate(spike_indices(i-1):spike_indices(i)) = inst_rate(i-1);
end