function [t_vect, spk_vect,rho_vect] = inhom_pp2(rate1,rate2,freq) %this function simulates an inhomogeneous Poisson process %with time varying rate by the integrate method %described in the lecture notes %It returns a time vector, a spike vector and the rate vector dt = 0.05; t_vect = 0:dt:1000; v_vect = zeros(size(t_vect)); spk_vect = zeros(size(t_vect)); v_thres = exprnd(1); v(1) = 0; rho_vect = (rate1/1000) + (rate2/1000)*sin(2*pi*(freq/1000)*t_vect); %in spk/msec %save some time dtrho_vect = dt*rho_vect; for i = 2:length(t_vect) v(i) = v(i-1) + dtrho_vect(i); if (v(i) > v_thres) v(i) = 0; spk_vect(i) = 1; v_thres = exprnd(1); end; end;