function makehank
%
%  Name: makehank
%
%  Usage: makehank
%
%  Description:
%   Forms and decomposes hankle matrix for Eigensystem Realization Algorithm (ERA)
%
%
%   Reference for ERA: "An Eigensystem Realization Algorithm for
%    Modal Parameter Identification and Model Reduction," 
%    Juang, J-N, and Pappa, R.S., Journal of Guidance, Control, and
%    Dynamics, Vol. 8, No. 5, pp. 620-627, 1985.
%

%   Version SWD970904
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This matlab source code was originally     %
% developed as part of "DIAMOND" at          %
% Los Alamos National Laboratory. It may     %
% be copied, modified, and distributed in    %
% any form, provided:                        %
%  a) This notice accompanies the files and  %
%     appears near the top of all source     %
%     code files.                            %
%  b) No payment or commercial services are  %
%     received in exchange for the code.     %
%                                            %
% Original copyright is reserved by the      %
% Regents of the University of California,   %
% in addition to Scott W. Doebling, Phillip  %
% J. Cornwell, Erik G. Straser, and Charles  %
% R. Farrar.                                 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

global MODES DATA

%  Define variables and allocate space for matrices

nresp = size(DATA{1}.respDOF,1);
nref = size(DATA{1}.refDOF,1);
nlines = DATA{1}.nlines;

padex =  ceil(log(nlines)/log(2));
npad = 2 * (2^padex - nlines ) + 1;
MODES.eraparam.nlines_out = 2^(padex+1);
MODES.eraparam.fs_out = 2*(DATA{1}.cf + DATA{1}.sp/2)/((nlines-1) * 2) * MODES.eraparam.nlines_out;

%  Convert G to Block form with Full Spectrum


switch MODES.ispecfunfit,
case 'FRF',
   fprintf(1,'Forming full FRF spectrum...')
   GBlk = cat(1,DATA{1}.G(:,:,:,1),zeros(npad,nresp,nref),conj(DATA{1}.G([nlines-1:-1:1],:,:,1)));
case 'CPS'
   fprintf(1,'Forming full CPS spectrum...')
   GBlk = cat(1,DATA{1}.Gxy(:,:,:,1),zeros(npad,nresp,nref),conj(DATA{1}.Gxy([nlines-1:-1:1],:,:,1)));
end

fprintf(1,' Done\n')
   
%  Convert GBlk to Block-Form Impulse Response 'Y'

fprintf(1,'Converting FRF/CPS to Impulse Response / Cross-Correlation Function...');

MODES.eraparam.Y = ifft(GBlk,[],1);

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


%  Form Hankel Matrix at k=0

fprintf(1,'Forming Hankel Matrix at k=0...')

MODES.eraparam.H0 = hankera(0);

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


%  Form Hankel Matrix at k=1

fprintf(1,'Forming Hankel Matrix at k=1...')

MODES.eraparam.H1 = hankera(1);

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

%  Decompose Hankel Matrix at k=0

fprintf(1,'Decomposing Hankel Matrix at k=0...');

[MODES.eraparam.U0,MODES.eraparam.S0,MODES.eraparam.V0] = svd(MODES.eraparam.H0);

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

return