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 𝑓𝑟! 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 τ_r is the refractory period.
𝑑𝑓𝑟/𝑑𝑡=(𝑓𝑟0−𝑓𝑟)/𝜏𝑟