% gbp.m  Gain Bandwidth product and multi-stage amplifiers
% Chuck DiMarzio, Northeastern University, 2016
gbp1=1e6;gbp2=1e6;
A01=1;A02=1;
fb1=gbp1/A01;fb2=gbp2/A02;
f=10.^[1:0.1:8];
A1=A01./(1+1i*f/fb1);
A2=A02./(1+1i*f/fb2);
A=A1.*A2;
figure;semilogx(f,20*log10(abs(A1)),'b-',...
	    f,20*log10(abs(A2)),'g--',...
	    f,20*log10(abs(A)),'r-.',...
	    f,20*log10(abs(1./(1+1i*f/(fb1/sqrt(2))))),'c',...
	    f,20*log10(abs(1./(1+1i*f/(fb1/2)))),'c--',...
	    f,20*log10(abs(1./(1+1i*f/(0.6436*fb1)))),'m-');
title('Two 1MHz Stages');
xlabel('f, frequency, Hz');ylabel('Gain, dB');
grid on;
legend('1st Stage','2nd Stage','Cascade','B/sqrt(2)',...
       'B/2','0.6436 B','Location','SouthWest');

figure;semilogx(f,20*log10(abs(A1)),'b-',...
	    f,20*log10(abs(A2)),'g--',...
	    f,20*log10(abs(A)),'r-.',...
	    f,20*log10(abs(1./(1+1i*f/(fb1/sqrt(2))))),'c',...
	    f,20*log10(abs(1./(1+1i*f/(fb1/2)))),'c--',...
	    f,20*log10(abs(1./(1+1i*f/(0.6436*fb1)))),'m-');
grid on;
title('Two 1MHz Stages');
xlabel('f, frequency, Hz');ylabel('Gain, dB');
axis([1e4,1e7,-6,1]);
legend('1st Stage','2nd Stage','Cascade','B/sqrt(2)',...
       'B/2','0.6436 B','Location','SouthWest');


gbp1=1e6;gbp2=1e4;
A01=1;A02=1;
fb1=gbp1/A01;fb2=gbp2/A02;
f=10.^[1:0.1:8];
A1=A01./(1+1i*f/fb1);
A2=A02./(1+1i*f/fb2);
A=A1.*A2;
figure;semilogx(f,20*log10(abs(A1)),'b-',...
	    f,20*log10(abs(A2)),'g--',...
	    f,20*log10(abs(A)),'r-.');
grid on;
xlabel('f, frequency, Hz');ylabel('Gain, dB');
title('1MHz and 10kHz Stages');
legend('1st Stage','2nd Stage','Combined','Location','SouthWest');