function F = getF2(T2mag,Tupp,Tlow,Tmax)
% GETF2 returns the merit value of a pid-2dof design. It is based on
% overshoot and bandwidth characteristics of a given closed loop frequency
% response

%  Copyright 2020 The MathWorks, Inc.

% Overshoot: measure of % overshoot bounded by the 1-dof overshoot
T2max = max(T2mag/T2mag(1));
OS = max(100*exp(-pi/(T2max+sqrt(T2max^2-1))),inf*max(T2mag/Tmax>1));
minOS = 100*exp(-pi);
% Bandwidth
BW = 500*log10(max([1 max(Tlow./T2mag) max(1,max(T2mag./Tupp))]));
% Merit value
F = max([OS 1]*([minOS 1;50 1]\[1;2]),[BW 1]*([0 1;1 1]\[1;2]));