clear

G0max = 7.7327
G0mean = 113.6853
G0halfwidth = 170.4372
G = load('twparams_Vmax.txt');

interval = -500:10:600;

for parami = 1:144
G_max(parami) = max(G(1:111,parami));
G_min(parami) = min(G(1:111,parami));
G_floor(1:111,parami) = G(1:111,parami) - G_min(parami);
G_area(parami) = sum(G_floor(1:111,parami));
G_norm(1:111,parami) = G_floor(1:111,parami) ./ G_area(parami);
sum(G_norm(1:111,parami))
end

for parami = 1:144
    G_mean(parami) = 0;
    for timing = 1:111
        G_mean(parami) = interval(timing) * G_norm(timing,parami) + G_mean(parami);
    end

    G_var(parami) = 0;
    for timing = 1:111
        G_var(parami) = (interval(timing) - G_mean(parami))*(interval(timing) - G_mean(parami)) * G_norm(timing,parami) + G_var(parami);
    end    
    G_halfwidth(parami) = sqrt(2 * log(2)) * sqrt(G_var(parami));
    G_max(parami) = G_area(parami) * 10 ./ sqrt(2 * pi * G_var(parami)) + G_min(parami);
end

colortype = [0,   0,   1;    %blue
             0,   1,   1;    %cyan
             1,   0,   0;    %red
             1, 0.5,   1];   %magenta
               
color = [3, 1,  3, 1, 1, 1, 1,  3, 1,  1, 1, 1]; %1;Known; 3:Unknown
 
 
subplot(3,1,1)
plot([0, 13], [G0mean, G0mean], 'k:')
hold on
for param = 1:12
    plot(param, G_mean((param-1)*12 +  1), 'Color', colortype(color(param)  , :), 'Marker', 'o', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  2), 'Color', colortype(color(param)  , :), 'Marker', '^', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  3), 'Color', colortype(color(param)  , :), 'Marker', 'v', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  4), 'Color', colortype(color(param)  , :), 'Marker', 's', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  5), 'Color', colortype(color(param)  , :), 'Marker', 'd', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  6), 'Color', colortype(color(param)  , :), 'Marker', 'p', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  7), 'Color', colortype(color(param)+1, :), 'Marker', 'o', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  8), 'Color', colortype(color(param)+1, :), 'Marker', '^', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 +  9), 'Color', colortype(color(param)+1, :), 'Marker', 'v', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 + 10), 'Color', colortype(color(param)+1, :), 'Marker', 's', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 + 11), 'Color', colortype(color(param)+1, :), 'Marker', 'd', 'LineStyle', 'none')
    hold on
    plot(param, G_mean((param-1)*12 + 12), 'Color', colortype(color(param)+1, :), 'Marker', 'p', 'LineStyle', 'none')
    hold on
end
axis([0 13 0 400])
set(gca,'xtick',[1 2 3 4 5 6 7 8 9 10 11 12])
set(gca,'XTickLabel','a5|a7|b6|b7|b10|b11|b12|c3|c5|e3|e6|e8')
set(gca,'ytick',[0 100 200 300 400])
title('Peak time of time window')
xlabel('Parameter ID for maximum enzyme velocities, Vmax')
ylabel('Time (ms)')


subplot(3,1,2)
plot([0, 13], [G0halfwidth, G0halfwidth], 'k:')
hold on
for param = 1:12
    plot(param, G_halfwidth((param-1)*12 +  1), 'Color', colortype(color(param)  , :), 'Marker', 'o', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  2), 'Color', colortype(color(param)  , :), 'Marker', '^', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  3), 'Color', colortype(color(param)  , :), 'Marker', 'v', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  4), 'Color', colortype(color(param)  , :), 'Marker', 's', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  5), 'Color', colortype(color(param)  , :), 'Marker', 'd', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  6), 'Color', colortype(color(param)  , :), 'Marker', 'p', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  7), 'Color', colortype(color(param)+1, :), 'Marker', 'o', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  8), 'Color', colortype(color(param)+1, :), 'Marker', '^', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 +  9), 'Color', colortype(color(param)+1, :), 'Marker', 'v', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 + 10), 'Color', colortype(color(param)+1, :), 'Marker', 's', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 + 11), 'Color', colortype(color(param)+1, :), 'Marker', 'd', 'LineStyle', 'none')
    hold on
    plot(param, G_halfwidth((param-1)*12 + 12), 'Color', colortype(color(param)+1, :), 'Marker', 'p', 'LineStyle', 'none')
    hold on
end
axis([0 13 0 400])
set(gca,'xtick',[1 2 3 4 5 6 7 8 9 10 11 12])
set(gca,'XTickLabel','a5|a7|b6|b7|b10|b11|b12|c3|c5|e3|e6|e8')
set(gca,'ytick',[0 100 200 300 400])
title('Half-width of time window')
xlabel('Parameter ID for maximum enzyme velocities, Vmax')
ylabel('Time (ms)')


subplot(3,1,3)
semilogy([0,13], [G0max, G0max], 'k:')
hold on
for param = 1:12
    semilogy(param, G_max((param-1)*12 +  1), 'Color', colortype(color(param)  , :), 'Marker', 'o', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  2), 'Color', colortype(color(param)  , :), 'Marker', '^', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  3), 'Color', colortype(color(param)  , :), 'Marker', 'v', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  4), 'Color', colortype(color(param)  , :), 'Marker', 's', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  5), 'Color', colortype(color(param)  , :), 'Marker', 'd', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  6), 'Color', colortype(color(param)  , :), 'Marker', 'p', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  7), 'Color', colortype(color(param)+1, :), 'Marker', 'o', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  8), 'Color', colortype(color(param)+1, :), 'Marker', '^', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 +  9), 'Color', colortype(color(param)+1, :), 'Marker', 'v', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 + 10), 'Color', colortype(color(param)+1, :), 'Marker', 's', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 + 11), 'Color', colortype(color(param)+1, :), 'Marker', 'd', 'LineStyle', 'none')
    hold on
    semilogy(param, G_max((param-1)*12 + 12), 'Color', colortype(color(param)+1, :), 'Marker', 'p', 'LineStyle', 'none')
    hold on
end
axis([0 13 0.01 100])
set(gca,'xtick',[1 2 3 4 5 6 7 8 9 10 11 12])
set(gca,'XTickLabel','a5|a7|b6|b7|b10|b11|b12|c3|c5|e3|e6|e8')
set(gca,'ytick',[0.01 0.1 1 10 100])
set(gca,'YTickLabel','0.01|0.1|1|10|100')
title('Peak amplitude of time window')
xlabel('Parameter ID for maximum enzyme velocities, Vmax')
ylabel('\DeltaF/F0 (%)')


Gmax = zeros(12, 12);
Gmean = zeros(12, 12);
Ghalfwidth = zeros(12, 12);
for param = 1:12
    for parami = 1:12
       Gmax(param, parami) = G_max((param-1)*12 + parami); 
       Gmean(param, parami) = G_mean((param-1)*12 + parami); 
       Ghalfwidth(param, parami) = G_halfwidth((param-1)*12 + parami); 
   end
end
save('peakamp_Vmax.txt', 'Gmax', '-ASCII')
save('peaktime_Vmax.txt', 'Gmean', '-ASCII')
save('halfwidth_Vmax.txt', 'Ghalfwidth', '-ASCII')
