function out=legTrackerPrepLocalSTDs(data,windowSize)
%legTrackerPrepLocalSTDs takes the output of legTrackerErrorCheck.m and
%outputs a version where the frame-by-frame value of each vector has been
%replaced with the standard deviation of that vector within a +/-
%windowSize sliding window.
%Usage:
%out=legTrackerPrepLocalSTDs(data,windowSize)
%data = output from legTrackerErrorCheck.m
%windowSize = integer (5 in Kain et al.)

%allocate out variable in memory
numFrames=size(data,1);
temp=zeros(size(data));

%for all frames starting after the window (frames within windowSize of the
%start and end of the vector are retained as 0).
for i=windowSize+1:numFrames-windowSize
    %value at this frame equal standard deviation in +/- windowSize sliding window
    temp(i,:)=std(data(i-windowSize:i+windowSize,:));
end

% replace nans with 0s
temp(isnan(temp))=0;

out=temp;
