clear

file_head = 'F_ratio1_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250;
plot_length = 2001;
data_number = 111;

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Calc total integrate Ca2+ response
for t = 0:(plot_length-1)    
    % Determine from_time
    if t < 500
        from_time(t+1) = t;
    else from_time(t+1) = 500;
    end
    
    % Determine to_time
    if t < 540
        to_time(t+1) = 540 + 500;
    else to_time(t+1) = t + 500;
    end
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

interval = -500:10:600;

plot(interval(1:111), G(1:111), 'k-', 'LineWidth',1)
axis([-500 1000 0 12.5])
set(gca,'xtick',[-400 -300 -200 -100 0 100 200 300 400 500 600])
set(gca,'XTickLabel','-400||-200||0||200||400||')
set(gca,'ytick',[0 2 4 6 8 10 12])
set(gca,'Tickdir','out')
box off
title('Time Window')
xlabel('PF -> CF interval (\Deltat ms)')
ylabel('Averaged Ca2+ response (% \DeltaF/F0)')
hold on


file_head = 'F_ratio2_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'r-', 'LineWidth',2)
hold on



file_head = 'F_ratio5_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'r-', 'LineWidth',1)
hold on



file_head = 'F_ratio10_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'r-', 'LineWidth',2)
hold on



file_head = 'F_ratio20_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'r-', 'LineWidth',1)
hold on



file_head = 'F_ratio50_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'r-', 'LineWidth',2)
hold on



file_head = 'F_ratio100_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'r-', 'LineWidth',1)
hold on



file_head = 'F_ratio0.5_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'm:', 'LineWidth',2)
hold on



file_head = 'F_ratio0.2_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'm:', 'LineWidth',1)
hold on



file_head = 'F_ratio10.1_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'm:', 'LineWidth',2)
hold on



file_head = 'F_ratio0.05_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'm:', 'LineWidth',1)
hold on



file_head = 'F_ratio0.02_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'm:', 'LineWidth',2)
hold on



file_head = 'F_ratio0.01_CFat'
file_tail = 'msec.plot'
MgGreenTotal = 250
plot_length = 2001
data_number =  111

% Including GENESIS plot files to MATLAB
MgGreen = zeros(plot_length, data_number);
for data_index = 0:(data_number-1)
filefullname = strcat(file_head, int2str(data_index * 10 - 500), file_tail);
transient = load(filefullname);
transient(:,1) = [];
MgGreen(:, data_index + 1)=transient; % put file into transients
end

% Convert [MgGreen] to dF/F0
    % Find F0
    F0 = min(min(MgGreen))/MgGreenTotal + 1
    F  = MgGreen/MgGreenTotal + 1;
    dF_rate = (F - F0) * 100;

% calc the time window function 'G'
G = zeros(data_number,1);
for data_index = 0:(data_number-1)
    duration = data_index * 10;
    for t=from_time(duration + 1):to_time(duration + 1)
        G(data_index + 1) = G(data_index + 1) + dF_rate(t+1, data_index + 1);
    end
    G(data_index + 1) = G(data_index + 1) / (to_time(duration + 1) - from_time(duration + 1) );
end

plot(interval(1:111), G(1:111), 'm:', 'LineWidth',1)
hold on