Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(pllph.m code) % model an analog pll (phase step error) fs = 1000; ts = 1/fs; ps

ID: 3736417 • Letter: #

Question

(pllph.m code)

% model an analog pll (phase step error)
fs = 1000;
ts = 1/fs;
pstep = 160*pi/180; % phase step
wn = 2*pi*10;  
zt = 0.707;
w0 = 2*pi*100; % quiescent frequency
filti_old = 0;
int2_old = 0;
vcoi_old = 0;
vcoo_old = 0;
mo = 0;
kp = 0.5; % this is actually intrinsic to mixer
% must be computed from signal amplitudes
% kp = AB/2, but our A and B are both 1
k0= 1; % radians/volt
% add octave statements to find k1, k2
k2 = XXX;
k1 = XXX;
% print k1 and k2 out on scren
% nset = 400; % number of points to settle
ntot = 2000; % total number of points -1
perror = zeros(1,ntot+1);
vcos = zeros(1,ntot+1);
filts = zeros(1,ntot+1);
inv = zeros(1,ntot+1);
outv = zeros(1,ntot+1);
for i=0:ntot
% first get input
if (i<=nset)
mi = sin(w0*ts*i);
else
mi = sin(w0*ts*i+pstep);
end
inv(i+1) = mi; % this is the input sinusoid
pe = mi * mo; % phase detection is the product of 2 sines
perror(i+1) = pe; % save the phase error term
filti = kp*pe; % include phase detector gain
out1 = filti * k1; % proportional
int2 = int2_old + (ts/2)*(filti_old + filti); %integral
out2 = int2 * k2;
filto = out1 + out2;
filti_old = filti;
int2_old = int2;
vcoi = k0*filto;
% add a line here to model the vco integrator
% XXX
vcoi_old = vcoi;
vcoo_old = vcoo;
filts(i+1) = filto;
vcos(i+1) = vcoo; % save to plot vco output
% this is filtered so easier to see transient
mo = cos(w0*ts*i+vcoo);
%
% locks at sin & cos, but to compare, put both phase into a sin
%
outv(i+2) = sin(w0*ts*i+vcoo); % 1 for matlab starts at 1 and
% since this is next sample vco out
end %for i
figure(1) % this is the error but hard to see
% since still has double freq term
clf
plot(perror)
title('Phase error with double freq term')
figure(2) % the two sinusoids, notice that they match over time
clf
plot(inv(nset:nset+300),'b');
hold on
plot(outv(nset:nset+300),'g');
hold off
title('Two sinusoids at beginning of step change')
figure(3) % a closeup of the two sinusoids
clf
plot(inv(1000:1050),'b');
hold on
plot(outv(1000:1050),'g');
hold off
title('Closeup of sinusoids after lock')
figure(4) % The loop filter output, shows most of the
% double freq term going away
clf
plot(filts);
title('Loop filter output')
figure(5) % The VCO output
clf
plot(vcos);
title('VCO output')

In this laboratory we will model the behavior of a continuous time PLL. The PLL behavior will be modeled for a step change in input phase, and also a step change in input frequency The PLL to be constructed uses the constants shown in Figure C.1.4 (kp and ko), with a PI loop filter of equation C.19 (ki and k2) 1) The file pllph.m has been uploaded to the class website. The desired loop properties, and wn, have been included at the beginning of the file. Two pieces of code have been removed from the file. The first is the computation of the parameters ki and k2 needed to get the desired loop properties. Add code to compute these, and hand in the actual computed values included in the body of your email message) The second piece of code missing is the integrator model of the VCO. You will need to write this missing code, which should only be one line of Matlab/Octave code. Notice that the variables are already defined and initialized for you: vcoi, vcoo VCO input and output, and vcoi.old, vcoo-old, which are the past VCO input and out put. The code for implementing the loop filter F(s) should be used as an example as to how to model the VCO (they both implement an integrator). The idea behind the integra tion code is to use the trapezoidal rule to approximate the continuous integration. Given a function f(t) and its integral F(t) , which are the current Ft)f(r)dr the trapezoidal rule states that (see the Figure 1 below or refer to your Calculus book). Get your code working, and print out a pdf copy of Matlab Figure 2 (the 2 sinusoids converging) to hand in. Notice that after an acquisition time, that the sinusoid of the VCO tracks that of the input (Matlab Figure4 shows a closeup of this) 2) Once you have your phase error code working, make a new routine called pllf.m. Modify your code so that instead of a phase error, you get an input step frequency change of 30 Hz. Run you PLL code un the PLL locks. Look at the variable outv and verify that after acquisition, it has a frequency of 130 Hz. Hand in your working program pllf.m, and Matlab Figure 2 (the 2 sinusoids converging)

Explanation / Answer

% model an analog pll (phase step error)
fs = 1000;
ts = 1/fs;
pstep = 160*pi/180; % phase step
wn = 2*pi*10;  
zt = 0.707;
w0 = 2*pi*100; % quiescent frequency
filti_old = 0;
int2_old = 0;
vcoi_old = 0;
vcoo_old = 0;
mo = 0;
kp = 0.5; % this is actually intrinsic to mixer
% must be computed from signal amplitudes
% kp = AB/2, but our A and B are both 1
k0= 1; % radians/volt
% add octave statements to find k1, k2
k2 = XXX;
k1 = XXX;
% print k1 and k2 out on scren
% nset = 400; % number of points to settle
ntot = 2000; % total number of points -1
perror = zeros(1,ntot+1);
vcos = zeros(1,ntot+1);
filts = zeros(1,ntot+1);
inv = zeros(1,ntot+1);
outv = zeros(1,ntot+1);
for i=0:ntot
% first get input
if (i<=nset)
mi = sin(w0*ts*i);
else
mi = sin(w0*ts*i+pstep);
end
inv(i+1) = mi; % this is the input sinusoid
pe = mi * mo; % phase detection is the product of 2 sines
perror(i+1) = pe; % save the phase error term
filti = kp*pe; % include phase detector gain
out1 = filti * k1; % proportional
int2 = int2_old + (ts/2)*(filti_old + filti); %integral
out2 = int2 * k2;
filto = out1 + out2;
filti_old = filti;
int2_old = int2;
vcoi = k0*filto;
% add a line here to model the vco integrator
% XXX
vcoi_old = vcoi;
vcoo_old = vcoo;
filts(i+1) = filto;
vcos(i+1) = vcoo; % save to plot vco output
% this is filtered so easier to see transient
mo = cos(w0*ts*i+vcoo);
%
% locks at sin & cos, but to compare, put both phase into a sin
%
outv(i+2) = sin(w0*ts*i+vcoo); % 1 for matlab starts at 1 and
% since this is next sample vco out
end %for i
figure(1) % this is the error but hard to see
% since still has double freq term
clf
plot(perror)
title('Phase error with double freq term')
figure(2) % the two sinusoids, notice that they match over time
clf
plot(inv(nset:nset+300),'b');
hold on
plot(outv(nset:nset+300),'g');
hold off
title('Two sinusoids at beginning of step change')
figure(3) % a closeup of the two sinusoids
clf
plot(inv(1000:1050),'b');
hold on
plot(outv(1000:1050),'g');
hold off
title('Closeup of sinusoids after lock')
figure(4) % The loop filter output, shows most of the
% double freq term going away
clf
plot(filts);
title('Loop filter output')
figure(5) % The VCO output
clf
plot(vcos);
title('VCO output')