% Low-pass Filter

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

R = 10000;
C = 0.01 * 10^-6;
wc = 1 / (R*C);
disp (['cutoff frequency: ' num2str(wc)]);
wr = 0.01 : 0.05 : 2.5;
n = (2.5 - 0.01) / 0.05;
i = 1 : n+1;

A(i) = 1 ./ sqrt(1 + (wr(i)).^2);
phi(i) = -atan(wr(i));

% Cutoff frequency amplitude ratio
disp (['A(1) = ' num2str(1 / sqrt(2))]);

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

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

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