function plotSpectra( fa,Sa, fb,Sb, fc,Sc, FRF_PSD, figNo ) 
% plotSpectra( fa,Sa, fb,Sb, fc,Sc, FRF_PSD, figNo ) 
%
% plot a matrix of frequency response functions and/or power spectral densities
%
%  INPUT   
%   f    the frequency values  corresponding to the spectrum
%   S    the complex-valued spectral matrix                   (nf x m x r)
% FRF_PSD  'FRF' a frequency response fuction; 'PSD' a power spectral density
%

[nf,m,r] = size(Sb);

lw = 1.0;  % line width
fs =  7;   % font size

%% PLOTS  ==================================================================== 

  figure(figNo); 
   clf
 
   switch FRF_PSD

    case 'FRF'
     for k=1:r
      subplot(1,r,k)
        hold on
        if ~isempty(Sa), loglog( fa,abs(Sa(:,:,k)),'-k'); end
        if ~isempty(Sb), loglog( fb,abs(Sb(:,:,k)),'.k'); end
        if ~isempty(Sc), loglog( fc,abs(Sc(:,:,k)),'-b'); end
%       axis('tight')
        set(gca,'FontSize',fs)
        hold off 
       if k == 1, ylabel('magnitude','FontSize',fs); end
     end

    case 'PSD'

     for ii = 1:m
       for jj = 1:r
       subplot(m,r,(ii-1)*r+jj)
        if ii == jj 
          hold on 
          if ~isempty(Sa), plot(fa,Sa(:,ii,jj),'-k','LineWidth',lw); end
          if ~isempty(Sb), plot(fb,Sb(:,ii,jj),'-g','LineWidth',lw); end
          if ~isempty(Sc), plot(fc,Sc(:,ii,jj),'-r','LineWidth',lw); end
          axis('tight')
          hold off
        else
          hold on 
          if ~isempty(Sa), plot(fa,real(Sa(:,ii,jj)),'-k','LineWidth',lw); end 
          if ~isreal(Sa),  plot(fa,imag(Sa(:,ii,jj)),'-k','LineWidth',lw); end
          if ~isempty(Sb), plot(fb,real(Sb(:,ii,jj)),'-g','LineWidth',lw); end
          if ~isreal(Sb),  plot(fb,imag(Sb(:,ii,jj)),'-g','LineWidth',lw); end
          if ~isempty(Sc), plot(fc,real(Sc(:,ii,jj)),'-r','LineWidth',lw); end
          if ~isreal(Sc),  plot(fc,imag(Sc(:,ii,jj)),'.r','LineWidth',lw); end
          axis('tight')
          hold off
        end
        if ii == 1,  title(sprintf('y_%d',jj),'FontSize',fs); end
        if jj == 1,  ylabel(sprintf('y_%d',ii),'FontSize',fs); end
        if ii == r,  xlabel('freq (Hz)','FontSize',fs); end
        set(gca,'FontSize',fs)
       end
     end

   end  % switch

% ----------------------------------------------------------------- plotSpectra
% H.P. Gavin 2017-12-03
