function fc = freqconc(x)

%    FREQCONC(X) calculates the frequency concentration FC (between 0
%    and 15 Hz) in a smoothed spectrum of a signal vector X.  
%
%    The frequency concentration, FC, is measured as the combined width of
%    the narrowest set of frequency ranges between 0 and 15 Hz that
%    contains 68% of the energy of the signal.
%
%    The spectrum is estimated using the PSD (Power Spectral Density)
%    estimate: Welch's averaged, modified periodogram method.  
%
%   Copyright 2003
%   Centre for Nonlinear Dynamics in Physiology and Medicine

[xspec,f] = psd(x,512,200);
f15 = round(15/200*512)+1;
xsort = -sort(-xspec(1:f15));
total = sum(xsort);
fres = f(2)-f(1);
sofar = 0;
for (i = 1:f15)
  sofar = sofar+xsort(i);
  if (sofar>(0.68*total))
    fc = f(i) + (1 - (sofar - 0.68*total)/xsort(i)) * fres;
    break;
  end
end

return
