Equations

Sunday 10 April 2011

Poisson Spike Train Simulation

Recently I had to simulate spike trains of neuron which fires as a Poisson processes. Since code in neuroscience is mostly written in Matlab, I will stick to this.

%rate of firing
rate = 50;

%dt in milliseconds
dt = 1;

%total time of simulation 60 seconds
totalTime = 60000;

%declaration of variables
spikeTimes = [];
spikeTrain = [];

%loop throough whole time
for t = 1 : dt : totalTime,
    %r*dt is the poisson distribution
    %of firing in dt. if the distribution is 
    %greater the uniform sampling,
    %a spike is fired and its time
    %is kept.
    if rate * dt / 1000 >= rand(1),
        spikeTimes(end + 1) = t;
    end
end

%convert the vector of spike times
%to vector of spike trains.
spikeTrain(spikeTimes) = 1;


now lets plot the interspike interval histogram and see
if the neuron is indeed poissonian.

isi = diff(sp_times);
maxi = ceil(max(isi) / 100) * 100;
bins = 0.5 : maxi - 0.5;
isiHist = hist(isi, bins);
bar(bins, isiHist / max(isiHist), 1);

we've got:

















as you can see, the TIH follows exponential distribution,
hence the neuron is indeed Poisonnian.

We can also calculate the coefficient of variation:
%for calculating the Cv we need the interspike intervals
cv = std(isi) / mean(isi);


No comments:

Post a Comment