% Plot of the simple emitter follower transfer function equation 5.18

w=10^6:100000:1*10^11;
s=i*w;
gm=0.077;RL=1000; Cmu=2*10^-12; Cpi=38.8*10^-12; Gp=1/(1000+1950); g_pi=1/1950;
GL=1/RL;
d=-gm*RL * Gp/(Gp+g_pi);
e = 1-Cmu/gm*s;
a=(RL*Cmu*Cpi)/(Gp+g_pi);
b=(1/(Gp+g_pi))*( RL*(gm + g_pi + Gp)*Cmu + Cpi +Cmu);
c=1;
% Section for equation 5.20
b2 = (1/(Gp+g_pi))*((1 + RL*(gm + Gp))*Cmu + Cpi);
tfl = d * 1./(b2*s + c);
tfl_mag = 20*log10(abs(tfl));
tfl_ph = 180*angle(tfl)/(pi);
%End section on equation 5.20 

tf = d * e ./(a*s.^2 + b*s + c);
tf_mag = 20*log10(abs(tf));
tf_ph = 180*angle(tf)/(pi);
%tf_phrad = angle(tf);
figure(1);
subplot(2,1,1)
semilogx(w, tf_mag, w , tfl_mag); 
title('Transfer Function Common Emitter'); xlabel('frequency rad/s'); ylabel('Gain'); grid on;

subplot(2,1,2)
semilogx(w, tf_ph, w, tfl_ph); 
title('Transfer Function Common Emitter'); xlabel('frequency rad/s'); ylabel('Phase'); grid on;

f=[a, b, c];
g=[-Cmu/gm, 1];

B=[1, -Cmu/gm];
A=[c, b, a];
