function plotSpectrum(tfG)
% PLOTSPECTRUM plot the spectral densities of the process generated by
% filtering normal white noise by a rational causal transfer function tfG
% Input:    tfG: transfer function
% SEE ALSO
% MINREAL, TFDATA, POLYVAL

% computing coprime representation of tfG
tfGmin = minreal(tfG);
[rvN,rvD] = tfdata(tfGmin,'v');

% checking analiticity upon unit circle
if any(abs(roots(rvD))==1)
    error('tfG is not analytic upon the unit circle')
end

% computing spectral density
tfPhi = minreal(tfGmin*tfGmin');

[rvN,rvD] = tfdata(tfPhi,'v');

rvT = -pi:0.001:pi;
rvV = exp(1i.*rvT);

rvPhiN = polyval(rvN,rvV);
rvPhiD = polyval(rvD,rvV);

% plotting spectral density
plot(rvT,real(rvPhiN./rvPhiD),'LineWidth', 1.5);

% plot options
ax = gca;
ax.FontUnits = 'points';
ax.FontSize = 22;
ax.XLabel.Interpreter = 'latex';
ax.XLabel.String = '$\theta$';
ax.YLabel.Interpreter = 'latex';
ax.YLabel.String = '$\Phi(e^{j\theta})$';
ax.XLim = [-pi pi];
ax.XGrid = 'on';
ax.YGrid = 'on';
ax.GridLineStyle = ':';
ax.TickLabelInterpreter = 'latex';
ax.Units = 'normalized';
ax.TickLength = [0.02 0.02];
ax.LineWidth = 1.5;
ax.TickDir = 'in';

end