%
%  velox_correction_d.m  ver 1.1  April 19, 2012
%
%  by Tom Irvine
%
function[t,acc,velox,dispx]=velox_correction_d(t,acc,dt)
%
       n=length(acc);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%       y=acc;     
%
       y = detrend(acc,'linear');       
%       
       [v]=integrate_function(y,dt);
%
       velox = detrend(v,'linear');
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
       y=velox;     
%
       [u]=integrate_function(y,dt);
%
       dispx=detrend(u,'linear');
%
       disp(' ');
       disp(' Apply fade in & out ');
       disp(' 1=yes 2=no ');
       ifade=input(' ');      
%
       if(ifade==1)
%
         [dispx]=half_cosine_fade(dispx);
%          
       end
%
       disp(' ');
       disp(' Apply highpass filter ');
       disp(' 1=yes 2=no ');
       ihf=input(' ');
%
       if(ihf==1)
%
            [dispx]=Butterworth_filter_function(dispx,dt);
%
            disp(' ');
            disp(' Apply fade in & out ');
            disp(' 1=yes 2=no ');
            ifade=input(' ');      
%
            if(ifade==1)
%
                [dispx]=half_cosine_fade(dispx);
%
            end
%
       end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       
%
       disp(' ');
       disp(' Perform cubic spline interpolation ');
       disp(' 1=yes 2=no ');
       ics=input(' ');
%
       if(ics==1)
            [t,dispx,dt]=cubic_spline_function(t,dispx);
       end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%       
%
       [velox]=differentiate_function(dispx,dt);
%
       [acc]=differentiate_function(velox,dt);
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%