function fano_factors_andsuchlike
tic
close all

% a=poissrnd(20,10000,1);
% b=mean(a)
% c=var(a)
% fanofac=c/b
% hist(a)

%--
% a=10
% a_hx=[]
% for i=1:100
%     a=a*.9;
%     a_hx(i)=a;
%     if a<(10*exp(-1)),disp(i),break,end
% end
% plot(a_hx)
%--
%this patch of code is for making a train, by getting a new random value at each time step and if it suggested spikes should be happening more frequently than they were (judging by the elapsed time since the previous spike), generating a spike, 
% spike_times=[1]
% lambda=20
% for i=2:5000
%     if lambda
%         b=poissrnd(lambda);
%         if b<(i-spike_times(end))
%             spike_times=[spike_times;i];
%             lambda=0;
%             %i
%         elseif lambda>20 
%             lambda=((lambda-20)*.7)+20;
%         end
%     else
%         lambda=1000;
%     end
% end
% ISIs=diff(spike_times);
% meanISI=mean(ISIs);
% varISI=var(ISIs);
% stdISI=std(ISIs);
% fanofactor=varISI/meanISI
% CV=stdISI/meanISI
% plot(spike_times,ones(1,length(spike_times)),'o','markersize',8,'markerfacecolor','m')
%--
for j=.001:.001:30
    r(round(j*1000))=50+20*cos(10*pi*j);
end
plot(r)

for k=1:length(r)
    proc(k)=poissrnd(r(k));
end
figure
plot(proc)

spike_times=[1]
for i=2:length(proc)
    if proc(i)<(i-spike_times(end))
        spike_times=[spike_times;i];
    end
end 
% ISIs=diff(spike_times);
% meanISI=mean(ISIs);
% varISI=var(ISIs);
% stdISI=std(ISIs);
% fanofactor=varISI/meanISI
% CV=stdISI/meanISI
figure
plot(spike_times,ones(1,length(spike_times)),'o','markersize',8,'markerfacecolor','m')
figure
plot(xcorr(spike_times))

toc