%Fitzhugh Nagumo simulation
%Single-cell simulation of a model neuron
%Sitabhra Sinha

%time increment
del_t=0.01;

%PARAMETERS
th=0.3; %threshold
k=1; %slope of v nullcline
silon=0.01;  %ratio of rates for v and u
I=0.05; %external current

%Initial conditions
u=0.0;v=0;

%How many iterations 
itr=50000; 

%Recording array initialization
urec=rand(itr,1);vrec=rand(itr,1);

%UPDATE LOOP
for i=1:itr,
    del_u=u*(1-u)*(u-th)-v+I;
    del_v=silon*(k*u-v);
    unew=u+del_t*del_u;
    vnew=v+del_t*del_v;
    
    urec(i)=u;vrec(i)=v;
    u=unew;v=vnew;
end;
figure, plot([1:itr]*del_t,urec), hold on, plot([1:itr]*del_t,vrec,'r')