% Lab 2 - Frequency Response Comparison
% This is for the comparison of theory and experiment
%
% This only compares the overall system frequency response, that is Vo1/Vi.
% Since you are asked to compare theory and experiment for Vo1/Vi and Vo2/Vi,
% you will have to modify the transfer function coefficients below to match
% the transfer function of interest.  
%
% MAKE SURE TO INSERT YOUR OWN DATA VALUES AND TO INCLUDE THIS CODE 
% IN YOUR REPORT

% Component Values
R1 = 2.2e3;
R2 = 4.7e3;
C = 0.47e-6;

% Insert your measured values
% f is in (Hz); m_in and m_out are in whatever units you used; phase is in degrees
f = [12 32 50 71 100 300 500 700 1000 200 220 250 270];
m_in = [768 760 760 760 760 760 752 760 760 760 760 760 760];
m_out = [780 780 820 860 980 500 180 80 0 1.34 1.08 780 680];
phase = [180 175 172 170 161 30 20 0 0 76 60 40 30];

W = logspace(1, 4, 100);
bode_d(-R2, [R1^2*R2*C^2 R1^2*C R2], W, 0);

subplot(2,1,1);
hold on;
h=semilogx(2*pi*f, 20*log10(m_out./m_in), 'rx');
set(h,'LineWidth',2);
hold off;

subplot(2,1,2);
hold on;
h=semilogx(2*pi*f, phase, 'rx');
set(h,'LineWidth',2);
hold off;