f=@(t,y) [(20*(-y(1) + Heaviside(y(1)-a) -y(2))) ; (y(1) - 0.15*y(2))];
y=[0.25;0];
h=0.2;
t=0;
a=0.2;
for i=1:1000
if y(1)<a
Heaviside((y(1)-a)) =0;
else
Heaviside(y(1)-a) =1;
end
plot(t,y(1),'linewidth','b.',t,y(2),'linewidth','r.'); hold on
s=f(t,y);
y=y+h*s;
t=t+h;
end
hold off
title('ERP')
xlabel('Time')
ylabel('mV')