% opamp_bandbode.m - generate the frequency response for an op amp circuit
% RMM, 1 Apr 07

aminit;					% initialize MATLAB

% Filter parameters
R1 = 100; R2 = 5000;
C1 = 100e-6; C2 = 100e-6;

% State space form of the solution
A = [-1/(R1*C1) 0; 1/(R1*C2) -1/(R2*C2)];
B = [1/(R1*C1); -1/(R1*C2)];
C = [0 1];
D = 0;

sys = ss(A,B,C,D);

figure(1); clf; subplot(221);

% Create the bode plot by hand to tweak the phase
[mag, phase, w] = bode(sys, logspace(-1, 3, 100));
mag = mag(:);
phase = (phase(:) - 360) * pi / 180;

clear i;
[magh, phaseh] = ambode(frd(mag.*cos(phase) + i*mag.*sin(phase), w));
axis(magh, [1e-1 1e3 0.05 2]);
set(magh, 'YTick', [0.1 1 10], 'YMinorTick', 'on');
axis(phaseh, [1e-1 1e3 -360 0]);
set(phaseh, 'YTick', [-360 -270 -180 -90 0]);

amprint('opamp-bandbode.eps');
