% First 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

K = 1;
tau = 1;
wc = 1 / tau;
w = 0 : 0.05*wc : 1.5*wc;
n = 1.5/0.05;
i = 1 : n+1;

A(i) = K ./ sqrt(1 + (tau*w(i)).^2);
phi(i) = -atan(tau*w(i));

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

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

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