%
%  DSS_velocity_correction.m  ver 1.0  October 5, 2012
%
function[accel,velox,ddisp]=DSS_velocity_correction(dt,accel)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
       n=max(size(accel));
%
       for i=1:n
           if(abs(accel(i)>1.0e-05))
               n1=n;
               break;
           end
       end
%
       n2=round(n/4);
       n3=round(n/2);
       n4=round(3*n/4);
%       
       bpv=sort([ n1  n2  n3  n4  ]);
%
       y = detrend(accel,'linear');       
%       
       [v]=integrate_function(y,dt);
%
       velox = detrend(v,'linear',bpv);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%   fade in velocity
%
    fper=10/100;
%
     na=round(fper*n);
%
     for(i=1:na)
         arg=pi*(( (i-1)/(na-1) )+1); 
         velox(i)=velox(i)*0.5*(1+(cos(arg)));
     end
%
       y=velox;     
%
       [u]=integrate_function(y,dt);
%
%
       ddisp=u;
%
%
%   fade out displacement
%
        perc=10;
        nn=round(n*perc/100);
        ns=n-nn;
        j=0;
        for(i=ns:n)
            ddisp(i)=ddisp(i)*(1-(j/nn));
            j=j+1;
        end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       
%
       [velox]=differentiate_function(ddisp,dt);
%
       [acc]=differentiate_function(velox,dt);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%