function [EPSC, IPSC, CPSC, t] = generate_current(G_max_chl, G_max_glu, EGlu, EChl, Vm, tau_rise_In, tau_decay_In, tau_rise_Ex, tau_decay_Ex,tmax)

dt = 0.1;

t = 0:dt:tmax-dt;

IPSC = ((G_max_chl) .* ((1 - exp(-t / tau_rise_In)) .* exp(-t / tau_decay_In)) * (Vm - EChl));

EPSC = ((G_max_glu) .* ((1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex)) * (Vm - EGlu));

CPSC = IPSC + EPSC;

end

[~,~,CPSC,t] = generate_current(60,40,0,-70,-30,0.44,15,0.73,3,120);

gmc = 90;

gmg = 90;

tde = 1;

tdi = 1;

tre = 1;

tri = 1;

y = awgn(CPSC,35,'measured');

[xData, yData] = prepareCurveData(t, y);

ft = fittype( '((G_max_chl) .* ((1 - exp(-t / tau_rise_In)) .* exp(-t / tau_decay_In)) * (Vm - EChl)) + ((G_max_glu) .* ((1 - exp(-t / tau_rise_Ex)) .* exp(-t / tau_decay_Ex)) * (Vm - EGlu))', 'independent', 't', 'dependent', 'y' );

opts = fitoptions( 'Method', 'NonlinearLeastSquares' );

opts.Display = 'Off';

opts.Lower = [-70 0 1 1 -30 0 0 0 0];

opts.StartPoint = [-70 0 gmc gmg -30 tde tdi tre tri];

opts.Upper = [-70 0 150 150 -30 20 20 5 5];

[fitresult1, gof1] = fit(xData, yData, ft, opts)

figure( 'Name', 'Fit' );

h = plot( fitresult1, xData, yData );

legend( h, 'CPSC at -30mV', 'Fit to CPSC', 'Location', 'NorthEast', 'Interpreter', 'none');

subtitle('Realistic values')

xlabel( 'time', 'Interpreter', 'none' );

ylabel( 'pA', 'Interpreter', 'none' );

grid on