% Second Order System Frequency Response

clc             % clear the command window
clear           % clear all variables
close all       % close any existing windows
format compact	% prevent extra blank lines in the output

m = 15;
k = 500;
b = 20;
wn = sqrt(k/m)
zeta = b / (2*sqrt(k*m))

wr = 0.01 : 0.05 : 2;
n = (2 - 0.01)/0.05;
i = 1 : n+1;

A(i) = 1 ./ sqrt((1-wr(i).^2).^2 + 4*zeta^2*(wr(i).^2));
phi(i) = -atan2(2*zeta, 1./wr(i)-wr(i));

% Plot frequency response - amplitude plot
loglog(wr, A)
xlabel('w/wc');
ylabel('A(w)');

% Plot frequency response - phase plot
figure      % open new figure window (to prevent previous from being lost)
plot(wr, phi*180/pi)
xlabel('w/wc');
ylabel('phi(w) (deg)');

disp 'Hit Enter to close all windows and quit'
pause
close all