%-------------------------------
% EXAMEN CCIAC, JUIN 2006, EX.I 
%-------------------------------
Eox = 34.5e-12;
tox = 9e-9;
Cox = Eox / tox;
Un  = 350e-4;Up  = 100e-4;
LDn = 0.08e-6;LDp = 0.09e-6;
LAMBDAn = 0.1;LAMBDAp = 0.2;
VTHn = 0.7;VTHp = 0.8;



%-------------------------------
% Biasing Current
%-------------------------------
VDD = 3;
Iss = 200e-6;
Cout = 3e-12;
VEG = 0.3;

%-------------------------------
% transistors output impedance
%-------------------------------
ron=1/(LAMBDAn*(Iss/2));
rop=1/(LAMBDAp*(Iss/2));

%-------------------------------
% transistors transconductance
%-------------------------------
gm = (2*(Iss/2))/VEG;

%-------------------------------
% EX I.(1) small signal gain
%-------------------------------
Routn = gm*ron*ron; 
Routp = gm*rop*rop;

Rout = (Routn*Routp)/(Routn+Routp);
Av = gm*Rout
% >> Av =  888.8889 << %

%-------------------------------
% EX I.(2)  pole
%-------------------------------
wpout = 1/(Rout*Cout)
% >> wpout = 250e3 rad/sec << %
fpout = wpout/(2*pi)
% >> fpout = 39.789 kHz << %


%-------------------------------
% EX I.(3) Unity Gain Frequency
%-------------------------------
w1 = Av *wpout
% >> w1 = 222.22e6 rad/sec << %
f1 = w1/(2*pi)
% >> f1 = 35.368 MHz << %

%-------------------------------
% EX I.(4) Phase Margin
%-------------------------------
phase_margin = (-atan(w1/wpout))*180/pi - (-180)
% >> phase_margin = 90 degrees << %

%-------------------------------
% EX I.(5) VEG for Av=2000
%-------------------------------
new_Av = 2000;
new_VEG = (2*(Iss/2)) / sqrt(new_Av * (ron^2+rop^2)/(ron^2*rop^2))
% >> new_VEG = 0.2 V << %

%-------------------------------
% EX I.(6) VEG for Av=2000
%-------------------------------
%-------------------------------
% NEW transconductance
%-------------------------------
new_gm = (2*(Iss/2))/new_VEG;

%-------------------------------
% NEW Output Resistance
%-------------------------------
new_Routn = new_gm*ron*ron; 
new_Routp = new_gm*rop*rop;

new_Rout = (new_Routn*new_Routp)/(new_Routn+new_Routp);

%-------------------------------
% EX I.(6) NEW pole position
%-------------------------------
new_wpout = 1/(new_Rout*Cout)
% >> new_wpout = 166e3 rad/sec << %
new_fpout = new_wpout/(2*pi)
% >> new_fpout = 26.526 kHz << %






%-------------------------------
% EX I.(6) NEW Unity Gain Frequency
%-------------------------------
new_w1 = new_Av * new_wpout
% >> new_w1 = 333.33e6 rad/sec << %

new_f1 = new_w1/(2*pi)
% >> new_f1 = 53.052 MHz << %