# How to test PLL for step input change in phase

I wrote a simulation for second-order PLL and I would like to test it with an input to see whether my PLL can track the phase. I would like to change the phase of my sinusoidal signal with step with magnitude 10 rad. Therefore that's what I did:

  F=60;
t=0:Ts:2-Ts;
idx=find(t>=0);
theta(idx)=pi/180*10*ones(1,length(idx));
in=sin(2*pi*F*t+theta);
out=pll(in);
plot(t,out,t,theta)


However, these two phases differ a lot. I am wondering can anyone tell me if there is any problem with the above script.

Here are the commands inside the for loop:

Error(ii)=Kd*in_norm(ii)*VCO_out(ii-1);     % Calculate the Error

prop_out(ii)=Kp*Error(ii);

integ_out(ii)=KI*Error(ii)*Ts+integ_out(ii-1);

lf_out(ii)=integ_out(ii)+prop_out(ii);

phi_out(ii)=lf_out(ii)*Ts*K0*2*pi+phi_out(ii-1);

VCO_out(ii)=sin(2*pi*Fout*(ii-2)*Ts+phi_out(ii));


• You should add a picture of the input/output plot, and give more details of your PLL implementation. Jul 14, 2016 at 21:01
• I implemented a PLL by using first order loop filter as one proportional and one integral term. My sole question is do you think above code is creating step change in phase correctly if it is correct I will suspect that my code is wrong. Jul 14, 2016 at 21:05
• It sure would be easy to determine this if you just showed the simulation results including the signals theta, in, out vs. t. Also, what sort of phase detector does this PLL use? Jul 14, 2016 at 21:09
• I get different graph for different parameters but this looks to be the best one, Jul 14, 2016 at 21:15
• The input is not even changing in the image you show Jul 14, 2016 at 21:17

I think you need to run the simulation longer, at a minimum (there could also be issues with the code). But take for example the image I attached below.

You can see the input (top signal) and output (bottom signal). The bottom signal does not even begin to lock on until the second period. Even then it takes some time for it to properly lock on (10+ cycles, not shown).

I would also just implement theta as a function of time, rather than mapping it to the linear indices of time (it's simpler to me):

F=60;
step=1/(f*4)
t=0:step:1; #240 datapoints, 60 cycles of runtime
theta(t)=t*720; #linear phase shift of 2 cycles over 60 cycles
in=sin(2*pi*F*t+theta);
out=pll(in);
plot(t,out,t,theta)


I don't have access to MATLAB so I can't check if this is correct. Simulation results would be nice to help debug as well.

• As I mentioned above there is labeling problem in the graph and the above graph represents output and input phase as a function of time. That's why input is not changing. Jul 14, 2016 at 22:15