SCILAB PLL EXAMPLE
fstart=10e3; //% starting at 10kHz
fstep=10e3; //% freq step is 10kHz
fstop=100e6; //% stop freq is 10MHz
f=fstart:fstep:fstop;
w=2*%pi*f;
s=poly(0,'s');
R=1.5e3; // resistor value
C=500e-12; // capacitor value
C_2=25e-12;
R_13=1e3;
C_13=1e-12;
F1 = R_13 + 1./(s*C_13);
F2= 1./(1./(R+1./(s*C))+(s*C_2)) ;
F3=F2.*F1;
F=F2;
B=C/C_2 // plot B Value
N=8; //% nominal division ratio
Kvco=2*%pi*800e6; //% VCO gain
Icp=50e-6; //% charge pump current = 100 uA
Kpd=Icp/(2*%pi); //% phase detector gain
A = Kpd*Kvco.*F./s; // forward gain
B_DIV = 1/N; // feedback gain
G=A.*B_DIV // loop-gain TF
H = A./(1+A*B_DIV) // closed-loop TF
E = H.*s./(Kpd*Kvco*F) // error TF
subplot(141);
Poly_G=freq(G("num"),G("den"),f);
[frq,rf]=repfreq(syslin('c',G),f);
[phi,Freq_G]=phasemag(rf,'c');
[db_G,phi_G] =dbphi(rf);
//plot2d("ln",f,Freq_G,rect=[10e4,-30,100e6,80],style=3);
plot2d("ln",f,db_G,rect=[10e4,-30,100e6,80],style=5);
xgrid(2);
xtitle('Open Loop Gain');
subplot(142)
plot2d("ln",f,phi_G,rect=[10e4,-180,100e6,-100],style=5);
xgrid(2);
xtitle('Open Loop Phase');
format('e',10);
cross=find(Freq_G<1);
BW_G=f(cross(1));
PH_G=phi(cross(1))+180;
str=sci2exp(B,string('B_cap'))+' GAIN='+string(Freq_G(1));
xstring(1e5,-90,sci2exp(B,string(' B_cap'))+' GAIN='+string(20*log10(Freq_G(1)))+' BandWidth='+string(BW_G)+' Phase='+string(PH_G))
subplot(143);
title='Open Loop BODE Plot';
bode(syslin('c',G),fstart,fstop,title);
subplot(144);
// phi=atan(imag(z),real(z))
plot2d("ln",f,Freq_G');
plot2d("ln",f,phi');
xgrid(2);
xtitle('Open Loop Plots');