function [ErrorPercentage, PeakSqImpl, LocationImpl] = prm_uvmtb_checker(PeakSqRef, LocationRef, FilterOutRef, PeakSqImplIn, LocationImplIn, FilterOutImpl, FrameNum)

%#codegen

    ErrorPercentage=100;
    GoodDetection = false;
    
    % Find implementation peak
    if (length(PeakSqImplIn) == 1)
        PeakSqImpl = double(PeakSqImplIn);
    else
        PeakSqImpl = double(PeakSqImplIn(1));
    end
    if (length(LocationImplIn) == 1)
        LocationImpl = LocationImplIn;
    else
        [~, LocationImpl] = max(LocationImplIn);
    end
    
    if (PeakSqRef ~= 0)
        % Plot
        t = 1:length(FilterOutRef);
        subplot(413); plot(t,abs(FilterOutRef),LocationRef,PeakSqRef,'o'); 
        title('Reference Peak Detection');
        
        t = 1:length(FilterOutImpl);
        subplot(414); plot(t,abs(FilterOutImpl),LocationImpl,PeakSqImpl,'o'); 
        title('Implementation Peak Detection');
        
        fprintf('\n[FrameNum=%3u] Peak location=%f, mag-squared=%.3f using global max\n', FrameNum, LocationRef, PeakSqRef);
        
        if PeakSqImpl == 0
            ErrorPercentage = 100;
            fprintf('[FrameNum=%3u] No peak detected from impl error(pct)=%.3f\n', FrameNum, ErrorPercentage);
        else
            LocErr = abs(LocationImpl - LocationRef);
            fprintf('[FrameNum=%3u] Peak detected from impl=%g error(abs)=%g\n', FrameNum, LocationImpl, LocErr);
            
            ErrAbs = max(abs(PeakSqRef-PeakSqImpl));
            ErrorPercentage = max(abs(PeakSqRef-PeakSqImpl)/PeakSqRef)*100;
            fprintf('[FrameNum=%3u] Peak mag-squared from impl=%.3f, error(abs)=%.3f error(pct)=%.3f\n',...
                    FrameNum, PeakSqImpl, ErrAbs, ErrorPercentage);
        end
    else
        if PeakSqImpl ~= 0
            ErrorPercentage = 100;
            fprintf('\n[FrameNum=%3u] Peak found in Impl but not in Ref.\n', FrameNum);
        else
            ErrorPercentage = 0;
            fprintf('\n[FrameNum=%3u] No peak found in Ref or Impl.\n', FrameNum);
        end
    end

end
