%
%  partition_matrices_accel_frf.m  ver 1.5   October 1, 2012
%
function[acc_frf,fstart,fend,freq]=...
  partition_matrices_accel_frf(num,nff,nem,ngw,Mwd,Mww,fn,damp,omegan,...
                                            ModeShapes,MST,part,T1,T2)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  FRF
%
sz=size(ModeShapes);
ndof=sz(1);
nmodes=sz(2);
%
clear omegad;
omegad=zeros(nff,1);
%
for i=1:nmodes;
    omegad(i)=omegan(i)*sqrt(1-damp(i)^2);
end
%
clear Q;
Q=ModeShapes;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
disp(' ');
fstart=input(' Enter starting frequency(Hz) ');
fend=input(' Enter ending frequency(Hz) ');
%
freq(1)=fstart;
nfreq=1;
%
oct=2^(1/96);
%
while(1)
    nfreq=nfreq+1;
    freq(nfreq)=freq(nfreq-1)*oct;
    if(freq(nfreq)>fend)
        break;
    end
end
%
freq(nfreq)=[];
nfreq=nfreq-1;
%
clear Uw;
clear Ud;
clear Uf;
%
Uw=zeros(ndof,nfreq);
Ud= ones(nem,nfreq);
Uf=zeros(ndof,nfreq);
%
omega=2*pi*freq;
%
na=zeros(ndof,nfreq);
%
term=zeros(nmodes,1);
for i=1:nmodes
    term(i)=(1i)*2*damp(i)*omegan(i);
end
%
progressbar;
%
for ijk=1:nfreq
%
    progressbar(ijk/nfreq);
%
    om=omega(ijk);
    om2=om^2;
%    
    for i=1:nmodes
            a=om2*part(i);
            b=(omegan(i)^2-om2)+term(i)*om;
            na(i,ijk)=a/b;
    end    
%
end  
%
pause(0.5);
progressbar(1);
progressbar;
%
for ijk=1:nfreq
    progressbar(ijk/nfreq);
    for i=1:ndof
        for p=1:nmodes
            Uw(i,ijk)=Uw(i,ijk)+Q(i,p)*na(p,ijk);
        end
    end
end
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%    Transformation back to xd xf
%
pause(0.5);
progressbar(1);
progressbar;
%
for ijk=1:nfreq
%
    progressbar(ijk/nfreq);
%
    Uf(:,ijk)=T1*Ud(:,ijk) + T2*Uw(:,ijk);
%
end
pause(0.5);
progressbar(1);
clear progressbar;
%
%  Put in original order
%
clear ZaccT;
%
ZaccT=[ Ud'  Uf' ];
sz=size(ZaccT);
ndof=sz(2);
%
clear acc_frf;
acc_frf=zeros(nfreq,ndof);
%
for i=1:ndof
    acc_frf(1:nfreq,ngw(i))=ZaccT(1:nfreq,i);
end
%