function [MIF,APS,freq_range,delta_f] = genindi(nlines,nresp,G,cf,sp,nref)
%   Usage: function [MIF,APS,freq_range,delta_f] = genindi(nlines,nresp,G,cf,sp,nref)
%
%   Description: Calculates the Mode Indicator Function and the Average
%                Power Spectra from the FRF
%%
%  Version SWD961003
%
%  Author(s): Scott W. Doebling, doebling@lanl.gov
%             Erik G. Straser, estraser@lanl.gov
%
%  Institution: Los Alamos National Laboratory,
%		ESA-EA
%
%  Copyright (c) 1996, The Regents of the University
%     	of California. (See top level of code for
%		full copyright statement.)

fprintf(1,'Calculating Mode Indicator Function and Average Power Spectrum...');

% Initialize Variables
Hi_numerator = zeros(nlines,1);
Hi_denominator = zeros(nlines,1);
nfrf = nresp * nref;
APS = zeros(nlines,1);
G_mif = zeros(nlines,nfrf);
MIF = zeros(nlines,1);
delta_f = sp/(nlines-1);

freq_range = cf-(sp/2):delta_f:cf+(sp/2);

% Making G_mif Matrix from G matrix

nc = 1;

for k = 1:nref,

    for p = 1:nresp,

        G_mif(:,nc) = G( (p-1)*nlines + 1 : p*nlines ,k);

        nc = nc + 1;

    end

end



% Calculate APS(n) and MIF(n)
for n = 1:nlines,
  for i = 1:nfrf,
    Hi_numerator(n) = Hi_numerator(n)+(abs(real(G_mif(n,i)))*abs(G_mif(n,i)));
    Hi_denominator(n) = Hi_denominator(n)+(abs(G_mif(n,i))*abs(G_mif(n,i)));
    MIF(n) = (1-(Hi_numerator(n)/Hi_denominator(n)));
   end
end
APS = Hi_denominator;

fprintf(1,' done.\n');

return




