function [w,wcf] = xscale_BaselineGrid(Focus,Ts)
% Baseline grid of test frequencies for XSCALE.
%    W       Baseline grid
%    WCF     Center of focus.

%   Copyright 1986-2020 The MathWorks, Inc.
nf = pi/Ts;
CONSTRAINED = (Focus>0 & Focus<nf);
if Ts==0
   if isempty(Focus) || ~any(CONSTRAINED)
      % Default "catch-all" grid
      w = logspace(-12,12,25);
      wcf = 1;
   elseif all(CONSTRAINED)
      % Note: min 5 points, to ensure at least 3 candidates for optim grid
      m = min(12,max(2,1+round(log10(Focus(2)/Focus(1))/2)));
      wcf = sqrt(Focus(1)*Focus(2));
      w = wcf * logspace(-m,m,2*m+1);
   elseif CONSTRAINED(1)
      % Grid anchored to the left
      w = Focus(1) * logspace(0,12,13);
      wcf = 1e3*Focus(1);
   elseif CONSTRAINED(2)
      % Grid anchored to the right
      w = logspace(-12,0,13) * Focus(2);
      wcf = 1e-3*Focus(2);
   end
else
   nfs = 0.8*nf;  % there is often a sensitivity spike at pi/Ts 
   if isempty(Focus) || ~any(CONSTRAINED)
      w = nfs * logspace(-9,0,10);
      wcf = 1e-2*nfs;
   elseif CONSTRAINED(1)
      if ~CONSTRAINED(2)
         Focus(2) = nfs;
      end
      m = min(8,1+round(log10(Focus(2)/Focus(1))/2));
      wcf = sqrt(Focus(1)*Focus(2));
      % Note: min 5 points taking NFS clipping into account
      m = max(m,4-ceil(log10(nfs/wcf)));
      w = wcf * logspace(-m,m,2*m+1);
      if any(w>nfs)
         w = [w(w<nfs) nfs];
      end
   else
      w = logspace(-8,0,9) * Focus(2);
      wcf = 1e-2*Focus(2);
   end
end
w = w.';