% opamp2fresp.m - generate the frequency response for an op amp circuit
% RMM, 14 Sep 05

aminit;					% initialize MATALB

% Filter parameters
Ra = 1000; Rb = 100000;
R1 = 100; R2 = 5000;
C1 = 100e-6; C2 = 100e-6;

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

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

[mag, phase, freq] = bode(sys);
figure(1); clf;

subplot(211); loglog(freq, squeeze(mag));
% set(gca, 'FontSize', 10);
ylabel('Gain');
axis([1e-1 1e4 1e-6 1e2]);
grid on;

subplot(212); semilogx(freq, squeeze(phase));
% set(gca, 'FontSize', 10);
ylabel('Phase (deg)');
xlabel('Frequency (rad/sec)');
axis([1e-1 1e4 -180 0]);
grid on;

amprint('opamp-fresp.eps');
