function [dataAccCut,dataAccCut_filt,StrideTimeSamples] = StepDetectionFunc(FS,ApplyRemoveSteps,dataAcc,dataAcc_filt,StrideTimeRange)
%% Step detecection
% Determines the number of steps in the signal so that the first 30 and last 30 steps in the signal can be removed

ResultStruct = struct();

if ApplyRemoveSteps
    
    % In order to run the step detection script we first need to run an autocorrelation function;
    [ResultStruct] = AutocorrStrides(dataAcc_filt,FS,StrideTimeRange,ResultStruct);
    
    % StrideTimeSamples is needed as an input for the stepcountFunc;
    StrideTimeSamples = ResultStruct.StrideTimeSamples;
    
    % Calculate the number of steps;
    [PksAndLocsCorrected] = StepcountFunc(dataAcc_filt,StrideTimeSamples,FS);
    % This function selects steps based on negative and positive values.
    % However to determine the steps correctly we only need one of these;
    LocsSteps = PksAndLocsCorrected(1:2:end,2);
    
    %% Cut data & remove currents results
    % Remove 20 steps in the beginning and end of data
    dataAccCut = dataAcc(LocsSteps(31):LocsSteps(end-30),:);
    dataAccCut_filt = dataAcc_filt(LocsSteps(31):LocsSteps(end-30),:);
    
    % Clear currently saved results from Autocorrelation Analysis
    
    clear ResultStruct;
    clear PksAndLocsCorrected;
    clear LocsSteps;
    
else;
    dataAccCut = dataAcc;
    dataAccCut_filt = dataAcc_filt;
end