%
%  Second Order System Driver File
%
clear
% 
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%  In class Example
%
  y = @(t) 1.073*exp(-0.05*t).*sin(1.413*t+4.341)+1.5;
%
%  Estimated Parameters:
%
  t = linspace(0,80,1000);
  zeta = 0.0354;
  omega_n = sqrt(2);
  K = 1.5;
  y0 = 0.5;
  y0_dot = -0.5;
  Amp = 1;   % get the final x value (they should all be the same)
  Tf = t(end);    % get the final time for the measured data
%
%  run the simulation
%
  sim('Second_Order_System.slx');
%
%  Now plot the output
%
  td = downsample(t,20);
  hold on
  plot(td,y(td),'bo');
  plot(model_time,model_y,'r-','Linewidth',2);  % plot the model data
  hold off
  grid;
  legend('Analytical','Simulated');
  xlabel('Time (sec)'); ylabel('y(t)');
  title(['K = ',num2str(K,3),', \zeta = ',num2str(zeta,5),', \omega_n = ',num2str(omega_n,4)]);