function comspec(t,ts,tn)

% function comspec(t,ts,tn) : plots and compares spectra
%
% plots and compares spectra corresponding to the decomposition
% 
%      t = ts + tn  all must be Toeplitz matrices
% 
% tn : is treated as the Toeplitz covariance of MA-noise
% ts : is supposed to be singular and spectral lines are drawn accordingly
%      the maximum entropy spectrum is also shown
%      as well as a periodogram-based spectrum
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

N=length(t);
I=eye(N+1);
A=I(1:N,2:N+1); B=I(1:N,1);

th=0:2*pi/1023:2*pi;

% moving average
ma=tn(1:length(tn));
ma=ma+ma(1)*eye(size(ma));
ma=[fliplr(ma) ma(2:length(ma))]/2;
ma=[ma zeros(1,1024-length(ma))];
plot(th,abs(fft(ma)),'r'); hold on

% singular spectrum
m=rank(ts)-1;
[thetas,residues]=sm(ts,A,B,m);
arrow(thetas,residues)

% maximum entropy
specme=me(t,A,B,th);
plot(th,specme,'m')


% periodogram
coef=[N:-1:1]./N;
mp=tn(1:length(tn)).*coef;
mp=mp+mp(1)*eye(size(mp));
mp=[fliplr(mp) mp(2:length(mp))]/2;
mp=[mp zeros(1,1024-length(mp))];
plot(th,abs(fft(mp)),'b');

title('ME-magenta, MA-red, singular-red, perio-blue')