function out=legTrackerPredFilt(data,windowSize)
%legTrackerPredFilt applies a low-pass filter to the output vector of KNN
%classification, by replacing each frame with the most abundant
%classification label in a sliding windowSize of +/- windowSize frames.
%Usage:
%out=legTrackerPredFilt(data,windowSize)
%data = vector of classification labels {0 ... 11}
%windowSize = half the size of the sliding windowSize used for filter. (5 in Kain
%et al.).

%initialize label variables
labelRange=0:11;
tempCounts=zeros(1,length(labelRange));

%allocate space for output in memory.
out=data;

%for all frames starting after the windowSize (frames within windowSizeSize of the
%start and end of the vector are retained as originally classified).
for i=1+windowSize:length(data)-windowSize;
    
    %isolate sliding windowSize
    temp=data(i-windowSize:i+windowSize);
    
    
    %for each classification label
    for j=labelRange
        %count the number of times it appears
        tempCounts(j+1)=sum(temp==j);
    end
    
    %find which labels appear the most
    temp=find(tempCounts==max(tempCounts));
    
    %shuffle them in case of a tie
    temp=temp(randperm(length(temp)));
    
    %replace label with most abundant label, indexed on {0 ... 11}
    temp=temp(1);
    out(i)=temp-1;
    
end