function [ STTC, red_A, red_B ] = STTC_AB( bin_A, bin_B, dt )
%STTC_AB: This function takes as input two spiketrains of neurons and the
% time window parameter and returns the directional STTC value.
% Inputs: 
%         bin_A, vector (1 x length of frames): Spiketrain of neuron A
%         bin_B, vector (1 x length of frames): Spiketrain of neuron B
%         dt, integer: time window in order to estimate directional STTC 
% Outputs: 
%         STTC, double (range: [-1,1]): STTC value for the spiketrains A & B, for the time window
%         dt
%         red_A, vector (1 x length of frames): Reduced spike train of neuron A, (0 -> no event, 
%         1-> event that occurs within a defined interval Ät prior to firing events of B)
%         red_B, vector (1 x length of frames): Reduced spike train of neuron B, (0 -> no event, 
%         1-> event that occurs within a defined interval Ät follownig to firing events of A)

% Calculate TA and TB
% TA: fraction of total recording time covered by the tiles Ät after each spike of A
% TB: fraction of total recording time covered by the tiles Ät before each spike of B

[T_A, tiles_A] = find_T_plus(bin_A, dt);
[T_B, tiles_B] = find_T_minus(bin_B, dt);


% Calculate PA and PB 
% PA: fraction of firing events of A occuring within a defined interval Ät prior to firing events of B
% PB: fraction of firing events of B occuring within a defined interval Ät
% following firing events of A
[P_A, red_A, spA] = find_P(bin_A, tiles_B);
[P_B, red_B, spB] = find_P(bin_B, tiles_A);


% Computation of STTC in two parts
if((1 - P_A*T_B) == 0)
    part_a = 0;
else
    part_a = (P_A-T_B)/(1- P_A*T_B);
end

if((1- P_B*T_A) == 0)
    part_b = 0;
else
    part_b = (P_B-T_A)/(1- P_B*T_A);
end

% Calculate STTC value
STTC = 1/2 * (part_a + part_b);



end

