# How do I add a refractory period in neuronal spikes generated via Poisson process?

Spikes can be generated via MATLAB code as below

function [spikeMat, tVec] = poissonSpikeGen(fr, tSim, nTrials) % https://praneethnamburi.com/2015/02/05/simulating-neural-spike-trains/ dt = 1/1000; % s nBins = floor(tSim/dt); spikeMat = rand(nTrials, nBins) < fr*dt; tVec = 0:dt:tSim-dt; 

But these spikes assume a constant firing rate $$fr$$! In real data, neuronal spikes are usually followed by a refractory period in which the probability of firing immediately after a spike is reduced significantly for that time period. One of the exercises from Dayan Abott's theoretical neuroscience book asks us to use time dependent firing rate following the equation below in which $$\tau_r$$ is the refractory period. $$\frac{dfr}{dt} = \frac{fr_0-fr}{\tau_r}$$