function spcpltjm(P,Fs)
%
%  jim manning's modification of MATLAB's specplot
%  (minor axis labeling additions)
%
%SPECPLOT Plot the output of the SPECTRUM function.
%       SPcpltjm(P,Fs), uses P, the output of SPECTRUM, and Fs, the
%       sample frequency, to successively plot:
%
%               Pxx - X Power Spectral Density & confidence.
%               Pyy - Y Power Spectral Density & confidence.
%               abs(Txy) - Transfer Function Magnitude.
%               angle(Txy) - Transfer Function Phase.
%               Cxy - Coherence Function.
%
%       The 95% confidence intervals are displayed on the power
%       spectral density curves.
%
%       SPECPLOT(P) uses normalized frequency, Fs = 2, so that 1.0 on
%       the frequency axis is half the sample rate (the Nyquist 
%       frequency).

%       J.N. Little 7-9-86
%       Revised 4-25-88 C.R. Denham.
%       Copyright (c) 1986 by the MathWorks, Inc.

[n,m] = size(P);
if nargin < 2
   Fs = 1;
end
f = (1:n-1)/n*Fs/2;

if m == 2
   c = [P(2:n,1)+P(2:n,2) P(2:n,1)-P(2:n,2)];
  else
   c = [P(2:n,1)+P(2:n,6) P(2:n,1)-P(2:n,6)];
end
c = c .* (c > 0);
loglog(f,P(2:n,1),f,c(:,1),'--',f,c(:,2),'--'), ...
 ylabel(' Power Spectral Density '), ...
 xlabel('cycles/day'), ... 
 text(.1,max(P(2:n,1)),'10'), ...
 text(.2,max(P(2:n,1)),'5'), ...
 text(1,max(P(2:n,1)),'1'), ...
 text(2,max(P(2:n,1)),'.5'), ...
 title('Period (days)')
if m == 2
   return
end


c = [P(2:n,2)+P(2:n,7) P(2:n,2)-P(2:n,7)];
c = c .* (c > 0);
semilogy(f,P(2:n,2),f,c(:,1),'--',f,c(:,2),'--'), ...
 title('Pyy - Y Power Spectral Density'), ...
 xlabel('cycles/day'), pause

semilogy(f,abs(P(2:n,4))), ...
 title('Txy - Transfer function magnitude'), ...
 xlabel('cycles/day'), pause

plot(f,180/pi*angle(P(2:n,4))), ...
 title('Txy - Transfer function phase'), ...
 xlabel('cycles/per day'), ...
 ylabel('Degrees'), pause

plot(f,abs(P(2:n,5))), ...
 title('Cxy - Coherence'), ...
 xlabel('cycles/day'), pause
