Skip to content

Instantly share code, notes, and snippets.

@tindzk
Created March 17, 2020 12:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tindzk/702317175da0ee1e7723b2f53982b38c to your computer and use it in GitHub Desktop.
Save tindzk/702317175da0ee1e7723b2f53982b38c to your computer and use it in GitHub Desktop.
%
% Generate Poission spike train using a uniform probability distribution
%
% Generates up to r * T spikes.
% None of the spike times will exceed T.
%
% @param r firing rate (Hz)
% @param T spike train duration (seconds)
% @param dt time resolution (seconds)
% @return V Spike times (seconds)
% @return B Binned spike train
function [V, B] = poisson(r, T, dt)
% Number of bins
b = T / dt;
% Threshold value
v = r * dt;
% Generate bins by drawing b random numbers
B = rand(1, b);
% No spike if random numbers exceed v
B(B >= v) = 0;
% All other values are spikes
B(B > 0) = 1;
% Determine spike times
V = find(B == 1) * dt;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment