function [Am,Bm,Cm,V] = mcmillan(A,B,C,dc);
%
%  mcmillan
%
%  Converts the state-space model A,B,C in damped
%   modal coordinates to Am,Bm,Cm in undamped modal
%   coordinates.
%
%  It is assumed that the states are in complex-conjugate
%  pairs, and that real poles have been removed
%  (e.g. using 'chkpoles')
%
%  'dc' is the vector of eigenvalues of A

%  Reference: Alvin, K.F., "Second-Order Structural 
%   Identification via State Space-Based System
%   Realizations," Ph. D. Dissertation, Dept. of 
%   Aerospace Engineering, Univ. of Colorado, April 1993.

%  Version SWD960205
%
%  Copyright (c) 1996 by Scott W. Doebling
%	Los Alamos National Laboratory
%	ESA-EA, doebling@lanl.gov
%

nx = size(A,1);

nm = nx/2;

V = zeros(size(A));

j = sqrt(-1);

%  Define the transformation

for i = 1:nm,

    V([((i-1)*2 + 1):(i*2)],[((i-1)*2 + 1):(i*2)]) = j/(2 * imag(dc(2*i-1))) *...
 		 [dc(2*i),-1;(-1)*dc(2*i-1),1];

end

%  Apply the transformation to the damped-modal model

Vi = inv(V);

Am = real(Vi * A * V);
Bm = real(Vi * B);
Cm = real(C * V);

return
