echo off;
%----------------------------------------------------------------------
% Physiology 317 - Methods in Computational Neurobiology 
%
% hw4p1.m - Homework #4, Problem #1
%
% Simulate synaptic conductance changes to regular spike train inputs
%
% M. Nelson, 2004 
%----------------------------------------------------------------------

clear;
figure(1); clf;	
orient tall

NCASES = 4;			                % handle 4 cases
TAU =      [10, 50, 10, 50,];		% synaptic time constant (msec)
INTERVAL = [50, 50, 10, 10,];		% presynaptic interspike intervals

GPEAK = .1;				            % peak synaptic conductance (uS)
GNORM = GPEAK ./(TAU*exp(-1));		% normalization constant

TMAX = 500;				            % set up time vector (msec)
DT = 1;					            % integration time step (msec)
t=(DT:DT:TMAX)';

%%%%%%%%%%%%%%%%%%
% LOOP OVER CASES
%%%%%%%%%%%%%%%%%%

for icase=1:NCASES

    input = zeros(size(t));
    idx=INTERVAL(icase):INTERVAL(icase):length(t);
    input(idx) = (1/DT);

    z = zeros(size(t));
    g = zeros(size(t));

    for i=2:length(t)
       z(i) = z(i-1) + ...
	       (-z(i-1)/TAU(icase) + input(i)*GNORM(icase))*DT;
       g(i) = g(i-1) + ...
	       (-g(i-1)/TAU(icase) + z(i-1))*DT;
    end

    subplot(2,2,icase)
    plot(t,g);
    if(icase >= 3) xlabel('t (msec)'); end
    ylabel('g (\muS)')
    s = sprintf('interval=%2d msec   \\tau=%2d msec',INTERVAL(icase),TAU(icase));
    title(s,'fontsize',9);
    ax=axis;
    axis([ax(1) TMAX ax(3) ax(4)]);
end

