%
%  Name:   RPsynthesize
%
%  Usage:  RPsynthesize
%
%  This m-file does a rational polynomial fit to FRF's 
%

%  Version SWD960719
%
%  Author(s): Phillip Cornwell, cornwell@lanl.gov
%	modified by Scott W. Doebling, doebling@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.)

j = sqrt(-1);
if exist('haxis1')~=1,haxis1=-1;end;
if ishandle(haxis1)==1,delete(haxis1);end;
if exist('haxis2')~=1,haxis2=-1;end;
if ishandle(haxis2)==1,delete(haxis2);end;

clear hbar

%
%  Overplot Results
%

wn = Freqnew * 2 * pi;

sig = -Dampnew .* wn;

wd = wn .* sqrt(1-Dampnew.^2);

rk = phic_resp_new(iresp,:)' .* phic_ref_new(iref,:)' ./ (2 * j * wd) * sign(respDOF(iresp,2)) * sign(refDOF(iref,2));

p = sig + j*wd;

hbar = zeros(length(wifit),1);

for i = 1:nmodfit,

        hbar = hbar + (rk(i)./(j.*wifit - p(i)) + conj(rk(i))./(j.*wifit - conj(p(i)))).*wifit.^2 / 9.81;

end


figure(hsynthfig);

set(hsynthfig,'visible','on');
haxis1=subplot(211);
semilogy(freq,abs(datai))
hold on
semilogy(wifit/2/pi,abs(hbar),'r--')

haxis2=subplot(212);
plot(freq,angle(datai)/pi*180)
hold on  
semilogy(wifit/2/pi,angle(hbar)/pi*180,'r--')



