function [locsTurns,FilteredData] = DetermineLocationTurnsFunc(inputData,FS,ApplyRealignment,plotit,Distance) % Description: Determine the location of turns, plot for visual inspection % Input: Acc Data (not yet realigned) %Realign sensor data to VT-ML-AP frame if ApplyRealignment % apply relignment as described in Rispens S, Pijnappels M, van Schooten K, Beek PJ, Daffertshofer A, van Die?n JH (2014). data = inputData(:,[3,2,4]); % reorder data to 1 = V; 2 = ML; 3 = AP % Consistency of gait characteristics as determined from acceleration data collected at different trunk locations. Gait Posture 2014;40(1):187-92. [RealignedAcc, ~] = RealignSensorSignalHRAmp(data, FS); dataAcc = RealignedAcc; end % Filter data [B,A] = butter(2,3/(FS/2),'low'); % Filters data very strongly which is needed to determine turns correctly dataStepDetection = filtfilt(B,A,dataAcc); % Determine steps % Explanation of method: https://nl.mathworks.com/help/supportpkg/beagleboneblue/ref/counting-steps-using-beagleboneblue-hardware-example.html % From website: To convert the XYZ acceleration vectors at each point in time into scalar values, % calculate the magnitude of each vector. This way, you can detect large changes in overall acceleration, % such as steps taken while walking, regardless of device orientation. magfilt = sqrt(sum((dataStepDetection(:,1).^2) + (dataStepDetection(:,2).^2) + (dataStepDetection(:,3).^2), 2)); magNoGfilt = magfilt - mean(magfilt); minPeakHeight2 = 1.2*std(magNoGfilt); % based on visual inspection, parameter tuning was performed on standard deviation from MInPeak (used to be 1 SD) [pks, locs] = findpeaks(magNoGfilt, 'MINPEAKHEIGHT', minPeakHeight2); % for step detection numStepsOption2_filt = numel(pks); % counts number of steps; diffLocs = diff(locs); % calculates difference in step location avg_diffLocs = mean(diffLocs); % average distance between steps std_diffLocs = std(diffLocs); % standard deviation of distance between steps figure; findpeaks(diffLocs, 'MINPEAKHEIGHT', avg_diffLocs, 'MINPEAKDISTANCE',9); % these values have been chosen based on visual inspection of the signal line([1 length(diffLocs)],[avg_diffLocs avg_diffLocs]) [pks_diffLocs, locs_diffLocs] = findpeaks(diffLocs, 'MINPEAKHEIGHT', avg_diffLocs,'MINPEAKDISTANCE',10); % values were initially 5 locsTurns = [locs(locs_diffLocs), locs(locs_diffLocs+1)]; magNoGfilt_copy = magNoGfilt; for k = 1: size(locsTurns,1); magNoGfilt_copy(locsTurns(k,1):locsTurns(k,2)) = NaN; end % Visualising signal; if plotit figure; subplot(2,1,1) hold on; plot(magNoGfilt,'b') plot(magNoGfilt_copy, 'r'); title('Inside Straight: Filtered data with turns highlighted in blue') line([6000,12000,18000,24000,30000,36000;6000,12000,18000,24000,30000,36000],[-4,-4,-4,-4,-4,-4;4,4,4,4,4,4],'LineWidth',2,'Linestyle','--','color','k') % hold on; % for m = 1:size(locsTurns,1) % plot(locsTurns(m),DataStraight.([char(Participants(i))]).LyapunovPerStrideRosen_ML(:,m),'--gs',... % 'LineWidth',2,... % 'MarkerSize',10,... % 'MarkerEdgeColor','g',... % 'MarkerFaceColor',[0.5,0.5,0.5]) % end hold off; end % Check if number of turns * 20 m are making sense based on total % distance measured by researcher. disp(['Number of turns detected = ' num2str(size(locsTurns,1))]) disp(['Total distance measured by researcher was = ' num2str(Distance)]) FilteredData = dataAcc; end