Forums

Test PLL against step change in phase

Started by chess 7 years ago7 replieslatest reply 7 years ago112 views

I wrote a simulation for second order PLL and I would like to test it with a input to see whether my PLL can track the phase.  I would like to change 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 phase differ a lot. I am wondering can anyone tell me if there is any problem with above script to only create step change in the phase. Or I should ask is above script the correct way of testing second order PLL?

Thanks

[ - ]
Reply by Tim WescottJuly 14, 2016

Ask yourself what would happen if you had a step change of exactly \( 2\pi \) radians in phase -- what would happen to the signal?  What would your PLL do in response?  If you haven't twigged to it yet, please tell me what \( \sin \left ( x + 2 \pi \right ) \) is equal to.  Now ask what a change by 10 radians will look like.

Stop and ponder that before reading on.

Now, (spoiler alert!) ask yourself what the linear range of your phase detector might be.  Are you testing your PLL for real step changes that are that large?  Or are you testing your PLL for step changes to get an idea of how the loop performs when it is being linear.  If the latter, perhaps you want to use a step change magnitude that keeps things linear?

[ - ]
Reply by chessJuly 14, 2016

I know what step change would do to my signal or PLL but I was asking is above code reasonable to check whether PLL is working or not (close to zero phase error). I know magnitude of Step change should be small but what values is considered as small right now mine is like 0.1.

[ - ]
Reply by oliviertJuly 15, 2016

It all depends on the coefficients of your PLL. The code you give is just a way to create a sinusoid with a base frequency plus a frequency shift. In order to have a better representation of that I would write the frequency shift as a percentage of the original frequency and add a static phase offset (your method is better if you want to create some strange frequency shift evolution):

theta = offset;

in=sin(2*pi*F(1+0.05)*t+theta);  % for a 5% frequency shift

As said Tim, try first with a very small frequency shift and increase it, you will see what is the bandwidth of your 2nd order PLL.


[ - ]
Reply by chessJuly 15, 2016

I am looking for comparing the performance of system by comparing the reference phase and output phase to see whether they match eventually. In your case how may I plot the input phase ? Since I am changing frequency by 5% therefore the phase change will be 0.05*t, is that correct so this is like a ramp change in phase.

[ - ]
Reply by oliviertJuly 15, 2016

You're right. If you don't want a frequency offset you keep only:

theta = offset;

in=sin(2*pi*F*t+theta);

And then you'll have your phase offset of theta.

What is the point to have a second order PLL if you don't track a frequency offset? A first order is enough and more precise than a second order in that case.

[ - ]
Reply by chessJuly 17, 2016

Thanks Olivert, however I have a question regardless of value I use for theta or F, can you tell me what should be plotted against time, I mean what do you call as a input or reference phase ? is it like :


plot(t, theta)

or 

plot(t, 2*pi*F*t+theta)


Since 2*pi*F*t is also considered as part of sine.


[ - ]
Reply by pipifaxJuly 18, 2016

Sorry I do not know what language or system this code is for. I guess (and hope) that by functions "find" and "ones" (not shown or predefined?) "theta" is made to have a step at some appropriate time (0?). If this time is within (and not at the edge of) the plot interval, this step should show up.

Regarding "in=sin(2*pi*F*t+theta);" we can see that "theta" is defined in rad. However, if "ones" in "theta(idx)=pi/180*10*ones(1,length(idx));" provides a step of size 1, the resulting phase step would be pi/18 RAD = 10 DEGREES - not 10 rad as intended. This step may go unnoticed viewing the plots of "in" and "out" and even so the plot of "theta" if scaled to show a step of 10 rad.

Further, it seems to me that you did not understand Tim Wescott, that 10 rad is well beyond a full cycle und thus not quite meaningful. Otherwise, a 10 degrees step might well cope with his 2nd point

<A note to Stephane Boucher: Having changed some text, this editor will not allow me to insert a new line after this trailing period>.