% File name:  Lab06FrequencyResponsePlot.m
% EE212 Lab 6 Frequency Response Plot for Op-Amp Circuit

Rf = 1E5;   % set feedback resistor to 100 kOhm
Ri = 1E3;   % set input resistor to 1 kOhm
Cf = 1E-7;  % set feedback capacitor to 0.1 uF
Ci = 1E-7;  % set input capacitor to 0.1uF

f = logspace(-1,5,600); % set the frequency range

Zf = (Rf./(2*pi*f*Cf*j))./(Rf+1./(2*pi*f*Cf*j)); % Feedback Impedance
Zi = (1./(j*2*pi*f*Ci))+Ri; % Input Impedance

Vout = -(Zf./Zi); % For Vin = 1
%  The ./ operator divides the two functions for each value of f.

figure(1); % Open figure 1 for plot of magnitude versus frequency
loglog(f,abs(Vout))  % Magnitude of Vout is plotted
                     % versus f on log log scale

% The following comands make the plot much more meaningful!
title('Op-Amp band pass filter')
grid % Add grid lines to plot
xlabel('frequency in Hertz')
ylabel('Transfer function magnitude')

figure(2); % Open figure 2 for plot of angle versus frequency
semilogx(f,unwrap(angle(Vout))*180/pi)  % Angle of Vout is plotted
                                        % versus f on semilog scale
                                          
% The following comands make the plot much more meaningful!
title('Op-Amp band pass filter')
grid % Add grid lines to plot
xlabel('frequency in Hertz')
ylabel('Transfer function angle')
