%First run generate_spiketrain_from_linear_filter
%Then run compute_sta 

spike_indices = find(spike_train==1);
numspikes=length(spike_indices);

sta_length=250;  %choose a number less than or equal to filter_length so have enough of stim defined
sta=zeros(1,sta_length);

for j=1:numspikes
    sta=sta+stim_list(spike_indices(j)-sta_length: spike_indices(j)-1 );
end

sta = sta/numspikes;  %normalize

%plot vs. time before spike
timelist_sta=linspace(-sta_length*deltat,deltat, sta_length);

figure;
plot(timelist_sta,sta,'LineWidth',3)
xlabel('time (ms)','FontSize',18)
title('STA','FontSize',18)
set(gca,'FontSize',16)    
