Monday, 10 June 2013

Interspike intervals: The fast way?

A reminder for myself more than anything

For a set of spike data distributed across time, i.e., a N x T matrix, where N is number of cells, T is total time steps dt:

function [ints, spt] = isi(spikes, dt)

% Uses spike data to output interspike intervals and accompanying spike times.

[N, T] = size(spikes);

ints = []; % intervals
spt = []; % spiketimes

% Find isi for each cell

for n = 1:N
    spiketime = find(spikes(n,:) == 1);
    ints = [ints,spiketime(1),diff(spiketime)];
    spt = [spt,spiketime];
end

if isempty(ints)
    ints = inf;
end

ints = ints/(dt*T);

[spt col] = sort(spt, 'ascend'); spiketimes in ascending order
ints = ints(col); intervals sorted by spiketime

end

I would very much like to know if there is a faster way, particularly if it means I could find for all cells at once. Currently it isn't completely matlab efficient.

No comments:

Post a Comment