% evalueplot.m - generate step and frequency reponses for second order systesm
% RMM, 19 Jul 06

aminit;

% Set up the eigenvalues to plot over
reals = [3.5 2 0.5];
imags = [3.5 2 0.5];

% Set up variables that don't change
B = [0; 1]; C = [1, 0]; D = 0;

% Initialize the plots to look like we way
% axis('nolabel');

%
% Frequency responses
%
logWmin=-1; logWmax=3; Wrange = logspace(logWmin, logWmax, 50);

ploti = 0;
figure(2); subplot(111); clg;
% gset term postscript eps enhanced color solid;
% gset output "evfreq.eps"

for b = fliplr(imags)
  for a = reals
    % Increment the subplot index
    ploti = ploti+1;

    % Compute out the parameters for this plot
    omega0 = sqrt(a^2 + b^2); zeta = a/omega0;
    A = [0, 1; -omega0^2, -2*zeta*omega0];
    sys = ss(A, B*omega0^2, C, D);

    % Generate the frequency response
    subplot(3,3,ploti); 
    [mag, phase, w] = bode(sys, Wrange);
    logmag = log(reshape(mag, prod(size(mag)), 1));
    plot(log(w), logmag, 'b', 'LineWidth', AM_data_linewidth);

    % Generate some reference lines
    hold on;
    plot([logWmin logWmax], [0, 0], 'k', 'LineWidth', AM_ref_linewidth);
    % plot([1 1], [-8, 2], 'k--', 'LineWidth', AM_ref_linewidth);

    % Set the axes to be uniform
    axis([logWmin logWmax -8 2]); grid off;
    set(gca, 'Box', 'off');
    set(gca, 'XTickLabel', [], 'YTickLabel', []);
  end;
end;
amprint('evfreq.eps');

%
% Step responses
%
Tstop = 10;

ploti = 0;
figure(1); subplot(111); clg;
% gset terminal postscript eps enhanced color solid ;
% gset output "evstep.eps";

for b = imags
  for a = reals
    % Increment the subplot index
    ploti = ploti+1;

    % Compute out the parameters for this plot
    omega0 = sqrt(a^2 + b^2); zeta = a/omega0;
    A = [0, 1; -omega0^2, -2*zeta*omega0];
    sys = ss(A, B*omega0^2, C, D);

    % Generate the step response
    subplot(3,3,ploti); 
    [Y, T] =  step(sys, Tstop); 
    plot(T, Y, 'b', 'LineWidth', AM_data_linewidth); hold on;
    plot([0 Tstop], [1 1], 'k', 'LineWidth', AM_ref_linewidth); 

    axis([0 10 0 2]); grid off;
    set(gca, 'Box', 'off');
    set(gca, 'XTickLabel', [], 'YTickLabel', []);
  end;
end;

amprint('evstep.eps');
