Created
June 9, 2021 05:54
-
-
Save rysk-t/207110fcc9331c0aa20e13abc24f998b to your computer and use it in GitHub Desktop.
practical poisson event generator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [spikes, tv] = generatePoissonSig(fs, prbprc_per_s, dur, refPeriod, n_ev) | |
% e.g. [spikes, tv] = generatePoissonSig(100, 5, 210, 5.5, [1 Inf]) | |
tv = linspace(0, dur, dur*(fs)); | |
spikes = logical(tv*0); | |
k=0; | |
evProb = prbprc_per_s/fs; | |
% evProb | |
lastSpikeSec = 0; | |
while 1 | |
for i = 1:length(tv) | |
pval = rand(1); | |
if (pval > (100-evProb)/100) && (tv(i)-lastSpikeSec > refPeriod) | |
spikes(i) = true; | |
lastSpikeSec = tv(i); | |
end | |
end | |
if (k > 100) | |
% to prevent the infinite loop by unreal parameters | |
disp('Unreal Params') | |
spikes = spikes*0; | |
return; | |
elseif ((sum(spikes) <= n_ev(2)) && (sum(spikes) >= n_ev(1))) | |
% to prevent the "no or quite a few MM event" imaging data. | |
break; | |
else | |
k = k+1; | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment