function [InmdaT] = Inmda(T,PreTrain,deltaT,V,TauF,TauS,Vr,I_f,P0,Gnmda,BP,EPSP,lastone)
%This function is the equation that governs the behavior of NMDA-mediated
%EPSPs in the model.

%convert time units
T = T/10;
deltaT = deltaT/10;

%set required parameters
I_s = 1 - I_f;
Theta = 0;
InmdaT = 0;

%find all presynaptic events
indexs = find((PreTrain/10) <= (T+deltaT),1,'last');

%As long as there are presynaptic events calculate the decay.
if isempty(indexs) == false
Theta = Theta + ((I_f*exp((-((T+deltaT)-(PreTrain(indexs)/10)))/TauF))+ (I_s*exp(-((T+deltaT)-(PreTrain(indexs)/10))/TauS)));
end

%Calculate the effect of the presynaptics events
InmdaT = InmdaT + (P0 * Gnmda*Theta*BV(V)*(V-Vr));
if (PreTrain/10) == (T+deltaT)
    Inmda = Inmda + lastone;
end
