function [irreg_pair_tally,output_trains]=irregularly_spaced_pairs_dwn(hy, samples_per_ms,pulse_duration,OVSF,irreg_pair_tally)

%find the available IPIs & choose among them
available=find(irreg_pair_tally==min(irreg_pair_tally));
chosen=ceil(rand*(length(available)));

%make the train
output_trains(:,1)=[zeros(samples_per_ms*3000,1);
    repmat(-1/(4*OVSF),samples_per_ms*100,1);
    zeros(samples_per_ms*2000,1);
    ones(samples_per_ms*pulse_duration,1);
    %zeros((hy(available(chosen))*samples_per_ms)-(samples_per_ms*pulse_duration),1);
    zeros(samples_per_ms*(50-pulse_duration),1);    %jan 2, 2007 switched this so the fixed 50 ms IPI is presented first and the variable IPI follows
    ones(samples_per_ms*pulse_duration,1);
    %zeros(samples_per_ms*(50-pulse_duration),1);
    zeros((hy(available(chosen))*samples_per_ms)-(samples_per_ms*pulse_duration),1);%the other line switched jan 2, 2007
	ones(samples_per_ms*pulse_duration,1);
        zeros(samples_per_ms*(50-pulse_duration),1);    %jan 2, 2007, added in a fourth pulse here, for history-dependence questions
        ones(samples_per_ms*pulse_duration,1);
    %zeros(samples_per_ms*5000,1)];
    zeros(samples_per_ms*(5000-hy(available(chosen))),1)];  %jan 2, 2007 added this in to make all sweeps equal duration (part of more precise ITI control)

output_trains(:,2)=zeros(length(output_trains(:,1)),1);
output_trains((3000*samples_per_ms)+1:(3100*samples_per_ms)+1,2)=(-1/(4*OVSF));

irreg_pair_tally(available(chosen))=irreg_pair_tally(available(chosen))+1;