input = 65.0;   % lifadapt 100Hz
%input = 8.0;   % lifadapt 10Hz
%input = 15.7;  % lif 100Hz
%input = 8.3;   % lif 10Hz
trials = 10;
tmax = 50.0;
Dnoise = 0.1;
Dounoise = 5e1;
outau = 10.0;
adapttau = 0.2;
adaptincr = 0.5;

windows = 0.05:0.05:1.0;
pmax = zeros( size( windows ) );
for j = 1:length( windows )
    w = windows( j );
    spikes = lifadaptspikes( trials, input, tmax, Dnoise, adapttau, adaptincr );
    %spikes = lifouspikes( trials, input, tmax, Dounoise, outau);
    [ n1, bins1 ] = counthist( spikes, w );

    spikes = lifadaptspikes( trials, input+10.0, tmax, Dnoise, adapttau, adaptincr );
    %spikes = lifouspikes( trials, input+10.0, tmax, Dounoise, outau );
    [ n2, bins2 ] = counthist( spikes, w );

    subplot( 2, 1, 1 );
    bar( bins1, n1, 'b' );
    hold on;
    bar( bins2, n2, 'r' );
    hold off;

    subplot( 2, 1, 2 );
    bmax = max( [ length( bins1 ), length( bins2 ) ] );
    decision1 = zeros( bmax, 1 );
    decision2 = zeros( bmax, 1 );
    cs1 = ones( bmax, 1 );
    cs1(1:length(n1)) = cumsum( n1 );
    cs2 = ones( bmax, 1 );
    cs2(1:length(n2)) = cumsum( n2 );
    cbins = 0:1:bmax-1;
    plot( cbins, cs1, 'b' );
    hold on;
    plot( cbins, cs2, 'r' );
    plot( cbins, cs1-cs2, 'g' );
    hold off;
    pause( 0.1 );
    pmax(j) = max( cs1-cs2 );
end

clf;
subplot( 1, 1, 1 );
plot( windows, pmax );