function [RT,Resp] = DDM_sim(Ntr,maxrt,dt,a,v,s,nvar,z,tnd)

timeOut=[10^3,0];

T=ceil(maxrt/dt);

trajct = zeros(Ntr, T);
RT = zeros(Ntr, 1);
Resp = zeros(Ntr, 1);

%initliazing the starting point a bias
trajct(:, 1) = z;
    

for i = 1:Ntr
    
    for j = 2:T
        
        trajct(i, j) = trajct(i, j-1) + v*dt + sqrt(dt)*s*randn(1)*sqrt(nvar);
        
        if abs(trajct(i, j)) > a
            RT(i) = j;
            Resp(i) = sign(trajct(i, j));
            break;
        end
        
        if j == T
          % time out
          RT(i) = timeOut(1);
          Resp(i) = timeOut(2);
        end
        
    end
end

%calcualting rt in terms of seconds
RT=dt.*RT;
%adding the non-decision time
RT=RT+tnd;

%note that RT and RESP that for presenting the model responses the RT and
%RESP should be cleaned after calling the function
% For example:
% RT= RT(RT~=timeOut(1));
% Resp=Resp(Resp~=timeOut(2));

end

