function T_ERP = erpc( T_ERP_MIN, T_ERP_MAX, state, C_RRP )
% Function computes the succesive values of ERP clocks
% T_ERP_MIN - min value of ERP clock
% T_ERP_MAX - max value of ERP clock
% state - the current state (REST=0, ERP=1, RRP=2)
% C_RRP - the ratio between current RRP clock value and its default value

C_EARLY=0;
T_ERP=0;

if C_RRP>1 || C_RRP <0,
    error('Error: C_RRP coefficient not between 0 and 1');
end

if state==0, % REST state
    C_EARLY=1;
elseif state==1, % ERP state
    C_EARLY=0;
elseif state==2, % RRP state
    C_EARLY=C_RRP;
else
    C_EARLY=0;
end

C_ERP=C_EARLY*C_EARLY*C_EARLY;

T_ERP=T_ERP_MIN+floor((1-C_ERP)*(T_ERP_MAX-T_ERP_MIN));


end

