function [S1,S2] = Projection_Vector(Sp_binary,V1,V2,Input_)
%L_v = length(V1);
LL_V = length(V1); length_sta = LL_V;
Trial_num = size(Sp_binary,2);
LL = zeros(Trial_num,1);
for i =1:Trial_num
    spike_indx = find(Sp_binary(:,i)>0);
    maxindx = spike_indx(end);
    LL(i) = length(find(spike_indx>length_sta & spike_indx<maxindx-length_sta));
end
LL_ = [0;LL];
Sig = zeros(length_sta,sum(LL));
for i =1:Trial_num
    ind_=[];
    spike_indx = find(Sp_binary(:,i)>0);
    maxindx = spike_indx(end);
    ind_ = find(spike_indx>length_sta & spike_indx<maxindx-length_sta);
    Sig_ = zeros(length_sta,length(ind_));
    for j = 1:length(ind_)
        Sig_(:,j) = Input_(spike_indx(ind_(j))-length_sta+1:spike_indx(ind_(j)));
    end
    ind1 = sum(LL_(1:i)) + 1; ind2 = sum(LL_(1:i+1));
    Sig (:,ind1:ind2) = Sig_;
end

%%
S1 = zeros(size(Sig,2),1);S2 = S1;
for j=1:length(S1)
S1(j) = Sig(:,j)'*V1/norm(Sig(:,j));
S2(j) = Sig(:,j)'*V2/norm(Sig(:,j));
end

% L_I = length(Input_);
% Inp_ = [zeros(L_F,1);Input_];%-mean(Input_)
% Sig = zeros(LL_V,length(find(SP_Time>0)));
% %length(SP_Time)
% j=0;
% for i = 1:round(length(SP_Time))
%     if SP_Time(i)~=0
%         j=j+1;
%     te = round(SP_Time(i)) + L_F;
%     Sig(:,j) = Inp_(te-L_F:te);
%     Sig(:,j) = Sig(:,j)/norm(Sig(:,j));
%     end
% end
% 
% s1 = Sig'*V1; %sqrt(s(1,1))*
% s2 = Sig'*V2; %sqrt(s(2,2))*
% s1 = Sig(1:L_V+1,:)'*V1(1:L_V+1);
% s2 = Sig(1:L_V+1,:)'*V2(1:L_V+1);
% % Sp_Time are the spiking time represented by samples (not m-sec) 
% % %% Compute the eigenvectors and eigenvalues
% % [u,s,v] = svd(STC_Matrix);
% % s_d = diag(sqrt(s/sum(diag(s))));
% % v1 = s_d(1)*u(:,1);
% % v2 = s_d(2)*u(:,2);
% L_v = (length(V1)-1)/2;
% % %% Resample to the originanl size
% % L_V = 10*L_v;
%  LL_V = 2*L_v+1;%2
% % uy = iddata([],v1,1);
% % ur = resample(uy,LL_V,length(v1));
% % V1 = ur.u;
% % uy = iddata([],v2,1);
% % ur = resample(uy,LL_V,length(v2));
% % V2 = ur.u;
% %%
% L_I = length(Input_);
% L_F = L_v;
% Inp_ = [zeros(L_F,1);Input_;zeros(L_F,1)];
% Sig = zeros(LL_V,length(Sp_Time));
% for i = 1:length(Sp_Time)
%     te = Sp_Time(i) + L_F;
%     Sig(:,i) = Inp_(te-L_F:te+L_F);
%     Sig(:,i) = Sig(:,i)/norm(Sig(:,i));
% end
% 
% s1 = Sig'*V1;
% s2 = Sig'*V2;
% % s1 = Sig(1:L_V+1,:)'*V1(1:L_V+1);
% % s2 = Sig(1:L_V+1,:)'*V2(1:L_V+1);