function spikes = lifouadaptspikes( trials, input, tmaxdt, D, Dou, outau, tauadapt, adaptincr )
% Generate spike times of a leaky integrate-and-fire neuron
% with colored noise and an adaptation current
% trials: the number of trials to be generated
% input: the stimulus either as a single value or as a vector
% tmaxdt: in case of a single value stimulus the duration of a trial
%         in case of a vector as a stimulus the time step
% D: the strength of additive noise
% Dou: the strength of additive colored noise
% outau: time constant of the colored noise
% tauadapt: adaptation time constant
% adaptincr: adaptation strength
    
    tau = 0.01;
    if nargin < 4
        D = 1e0;
    end
    if nargin < 5
        Dou = 1e0;
    end
    if nargin < 6
        outau = 1.0;
    end
    if nargin < 7
        tauadapt = 0.1;
    end
    if nargin < 8
        adaptincr = 1.0;
    end
    vreset = 0.0;
    vthresh = 10.0;
    dt = 1e-4;
    
    if max( size( input ) ) == 1
        input = input * ones( ceil( tmaxdt/dt ), 1 );
    else
        dt = tmaxdt;
    end
    spikes = cell( trials, 1 );
    for k=1:trials
        times = [];
        j = 1;
        v = vreset;
        n = 0.0;
        a = 0.0;
        noise = sqrt(2.0*D)*randn( length( input ), 1 )/sqrt(dt);
        noiseou = sqrt(2.0*Dou)*randn( length( input ), 1 )/sqrt(dt);
        for i=1:length( noise )
            n = n + ( - n + noiseou(i))*dt/outau;
            v = v + ( - v - a + noise(i) + n + input(i))*dt/tau;
            a = a + ( - a )*dt/tauadapt;
            if v >= vthresh
                v = vreset;
                a = a + adaptincr;
                spiketime = i*dt;
                if spiketime > 4.0*tauadapt
                    times(j) = spiketime - 4.0*tauadapt;
                    j = j + 1;
                end
            end
        end
        spikes{k} = times;
    end
end