DS
d.schuecker@avm.de
Wed, Mar 17, 2021 4:20 PM
Hi time-nuts,
a PLL takes the phase difference of the incoming signal and the
synthesized signal and feeds that in a loop filter. The output of the loop
filter is used to steer the local oscillator.
In my setup I have an incoming complex signal and my local oscillator is
generating a complex signal as well. So calculation of the phase
difference is just the quotient of the incoming signal and the local
oscillator, it is a sampled system. I take the quotient, calculate the
angle using the atan function and then I feed it in the loop filter, a PI
controller. The output of the loop filter is converted to a complex phase
increment for the local oscillator with the sin and cos function.
Now I have to get rid of the atan, cos and sin functions.
I am looking for a loop filter which takes the quotient of the
incoming/synthesized signal as a complex value. The output of this loop
filter should be the phase increment for the local oscillator. It should
not use the angle of the complex value explicitly, as this will involve
the atan/cos/sin functions.
Is someone aware of such a loop filter? I surfed through Gardners'
'Phaselock Techniques' but did not find a hint.
Thank you
Detlef Schücker
DD4WV
Hi time-nuts,
a PLL takes the phase difference of the incoming signal and the
synthesized signal and feeds that in a loop filter. The output of the loop
filter is used to steer the local oscillator.
In my setup I have an incoming complex signal and my local oscillator is
generating a complex signal as well. So calculation of the phase
difference is just the quotient of the incoming signal and the local
oscillator, it is a sampled system. I take the quotient, calculate the
angle using the atan function and then I feed it in the loop filter, a PI
controller. The output of the loop filter is converted to a complex phase
increment for the local oscillator with the sin and cos function.
Now I have to get rid of the atan, cos and sin functions.
I am looking for a loop filter which takes the quotient of the
incoming/synthesized signal as a complex value. The output of this loop
filter should be the phase increment for the local oscillator. It should
not use the angle of the complex value explicitly, as this will involve
the atan/cos/sin functions.
Is someone aware of such a loop filter? I surfed through Gardners'
'Phaselock Techniques' but did not find a hint.
Thank you
Detlef Schücker
DD4WV
PK
Poul-Henning Kamp
Wed, Mar 17, 2021 5:34 PM
Detlef Schuecker via time-nuts writes:
Now I have to get rid of the atan, cos and sin functions.
Just because you have complex frequencies does not mean you have to
use both dimensions if you dont want to :-)
Here is how I did it when I worked on Dave Mills' LORAN-C receiver:
Step 1: Stop the rotation.
Calculate deltavector from previous sample, figure out direction
of rotation, output counteracting error signal roughly proportional
to the delta vector length.
Step 2: Bring angle < +/- PI/4
Look at the coordinates, output error signal to bring error signal "home".
if you are not in a hurry, simply output a constant error term and detect
when the vector rotate into +/- PI/4.
Step 3: Sin(x) ~= x
Use one of the coordinates as scalar input to the PI.
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
--------
Detlef Schuecker via time-nuts writes:
> Now I have to get rid of the atan, cos and sin functions.
Just because you have complex frequencies does not mean you have to
use both dimensions if you dont want to :-)
Here is how I did it when I worked on Dave Mills' LORAN-C receiver:
Step 1: Stop the rotation.
Calculate deltavector from previous sample, figure out direction
of rotation, output counteracting error signal roughly proportional
to the delta vector length.
Step 2: Bring angle < +/- PI/4
Look at the coordinates, output error signal to bring error signal "home".
if you are not in a hurry, simply output a constant error term and detect
when the vector rotate into +/- PI/4.
Step 3: Sin(x) ~= x
Use one of the coordinates as scalar input to the PI.
--
Poul-Henning Kamp | UNIX since Zilog Zeus 3.20
phk@FreeBSD.ORG | TCP/IP since RFC 956
FreeBSD committer | BSD since 4.3-tahoe
Never attribute to malice what can adequately be explained by incompetence.
MD
Magnus Danielson
Wed, Mar 17, 2021 6:20 PM
Hi,
On 2021-03-17 17:20, Detlef Schuecker via time-nuts wrote:
Hi time-nuts,
a PLL takes the phase difference of the incoming signal and the
synthesized signal and feeds that in a loop filter. The output of the loop
filter is used to steer the local oscillator.
In my setup I have an incoming complex signal and my local oscillator is
generating a complex signal as well. So calculation of the phase
difference is just the quotient of the incoming signal and the local
oscillator, it is a sampled system. I take the quotient, calculate the
angle using the atan function and then I feed it in the loop filter, a PI
controller. The output of the loop filter is converted to a complex phase
increment for the local oscillator with the sin and cos function.
Now I have to get rid of the atan, cos and sin functions.
I am looking for a loop filter which takes the quotient of the
incoming/synthesized signal as a complex value. The output of this loop
filter should be the phase increment for the local oscillator. It should
not use the angle of the complex value explicitly, as this will involve
the atan/cos/sin functions.
Is someone aware of such a loop filter? I surfed through Gardners'
'Phaselock Techniques' but did not find a hint.
That book is full of hints. Costas loop is one. Actually, you could just
do complex multiplication and only use the real output (and thus remove
half the complex multiplication) and use that output of the
multiplication as input to normal PI-regulator, that will lock up and
achieve everything you want. You can then also remove the sine with a
squarewave. There is some benefits and losses in doing that, which may
or may not be relevant.
There is a richness of complex detectors to be found in GPS literature,
such as that of "Understanding GPS principles and applications" of
Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
design" by Wolaver for additional inspiration. You end up finding that
Garners' book is actually very comprehensive if you only take time to
dwell into it.
Let me know if you need more hints.
Cheers and 73,
Magnus SA0MAD
Hi,
On 2021-03-17 17:20, Detlef Schuecker via time-nuts wrote:
> Hi time-nuts,
>
> a PLL takes the phase difference of the incoming signal and the
> synthesized signal and feeds that in a loop filter. The output of the loop
> filter is used to steer the local oscillator.
>
> In my setup I have an incoming complex signal and my local oscillator is
> generating a complex signal as well. So calculation of the phase
> difference is just the quotient of the incoming signal and the local
> oscillator, it is a sampled system. I take the quotient, calculate the
> angle using the atan function and then I feed it in the loop filter, a PI
> controller. The output of the loop filter is converted to a complex phase
> increment for the local oscillator with the sin and cos function.
>
> Now I have to get rid of the atan, cos and sin functions.
>
> I am looking for a loop filter which takes the quotient of the
> incoming/synthesized signal as a complex value. The output of this loop
> filter should be the phase increment for the local oscillator. It should
> not use the angle of the complex value explicitly, as this will involve
> the atan/cos/sin functions.
>
> Is someone aware of such a loop filter? I surfed through Gardners'
> 'Phaselock Techniques' but did not find a hint.
That book is full of hints. Costas loop is one. Actually, you could just
do complex multiplication and only use the real output (and thus remove
half the complex multiplication) and use that output of the
multiplication as input to normal PI-regulator, that will lock up and
achieve everything you want. You can then also remove the sine with a
squarewave. There is some benefits and losses in doing that, which may
or may not be relevant.
There is a richness of complex detectors to be found in GPS literature,
such as that of "Understanding GPS principles and applications" of
Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
design" by Wolaver for additional inspiration. You end up finding that
Garners' book is actually very comprehensive if you only take time to
dwell into it.
Let me know if you need more hints.
Cheers and 73,
Magnus SA0MAD
BB
Ben Bradley
Wed, Mar 17, 2021 6:26 PM
" I take the quotient, calculate the angle using the atan function ..."
This is mathematically correct, but programming-wise there's a
function atan2 that does both at once, and also doesn't return
infinity or give a divide-by-zero error if the denominator is zero.
atan2 also does something else, it returns the angle in the correct
quadrant for the signs of x and y. I don't know offhand if this is
your problem, but it can only help. Here's more info:
https://en.wikipedia.org/wiki/Atan2
https://www.johndcook.com/blog/2019/11/18/inverse-trig-functions/
On Wed, Mar 17, 2021 at 1:07 PM Detlef Schuecker via time-nuts
time-nuts@lists.febo.com wrote:
Hi time-nuts,
a PLL takes the phase difference of the incoming signal and the
synthesized signal and feeds that in a loop filter. The output of the loop
filter is used to steer the local oscillator.
In my setup I have an incoming complex signal and my local oscillator is
generating a complex signal as well. So calculation of the phase
difference is just the quotient of the incoming signal and the local
oscillator, it is a sampled system. I take the quotient, calculate the
angle using the atan function and then I feed it in the loop filter, a PI
controller. The output of the loop filter is converted to a complex phase
increment for the local oscillator with the sin and cos function.
Now I have to get rid of the atan, cos and sin functions.
I am looking for a loop filter which takes the quotient of the
incoming/synthesized signal as a complex value. The output of this loop
filter should be the phase increment for the local oscillator. It should
not use the angle of the complex value explicitly, as this will involve
the atan/cos/sin functions.
Is someone aware of such a loop filter? I surfed through Gardners'
'Phaselock Techniques' but did not find a hint.
Thank you
Detlef Schücker
DD4WV
time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe send an email to time-nuts-leave@lists.febo.com
To unsubscribe, go to and follow the instructions there.
" I take the quotient, calculate the angle using the atan function ..."
This is mathematically correct, but programming-wise there's a
function atan2 that does both at once, and also doesn't return
infinity or give a divide-by-zero error if the denominator is zero.
atan2 also does something else, it returns the angle in the correct
quadrant for the signs of x and y. I don't know offhand if this is
your problem, but it can only help. Here's more info:
https://en.wikipedia.org/wiki/Atan2
https://www.johndcook.com/blog/2019/11/18/inverse-trig-functions/
On Wed, Mar 17, 2021 at 1:07 PM Detlef Schuecker via time-nuts
<time-nuts@lists.febo.com> wrote:
>
> Hi time-nuts,
>
> a PLL takes the phase difference of the incoming signal and the
> synthesized signal and feeds that in a loop filter. The output of the loop
> filter is used to steer the local oscillator.
>
> In my setup I have an incoming complex signal and my local oscillator is
> generating a complex signal as well. So calculation of the phase
> difference is just the quotient of the incoming signal and the local
> oscillator, it is a sampled system. I take the quotient, calculate the
> angle using the atan function and then I feed it in the loop filter, a PI
> controller. The output of the loop filter is converted to a complex phase
> increment for the local oscillator with the sin and cos function.
>
> Now I have to get rid of the atan, cos and sin functions.
>
> I am looking for a loop filter which takes the quotient of the
> incoming/synthesized signal as a complex value. The output of this loop
> filter should be the phase increment for the local oscillator. It should
> not use the angle of the complex value explicitly, as this will involve
> the atan/cos/sin functions.
>
> Is someone aware of such a loop filter? I surfed through Gardners'
> 'Phaselock Techniques' but did not find a hint.
>
> Thank you
> Detlef Schücker
>
> DD4WV
>
> _______________________________________________
> time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe send an email to time-nuts-leave@lists.febo.com
> To unsubscribe, go to and follow the instructions there.
DS
d.schuecker@avm.de
Thu, Mar 18, 2021 12:59 PM
Hi,
yes, got it, I think, thanks.
I calculate the complex quotient of the incoming complex signal and the
local complex oscillator. I feed the imaginary part of the quotient to the
PI controller, thus forcing it to zero. The local oscillator is updated by
multiplying it with ( real(quotient)+j*PIOutput ). Forcing the imaginary
part of the quotient to zero means that incoming signal and local
oscillator are in phase.
See Matlab code and the image.
No atan/cos/sin, just mere multiplication :))
Thanks
Cheers
Detlef Schücker
DD4WV
clear
n=10000;
T1=0;
T2=0.01;
s0=exp(j2pi200(0:n-1)/n);
s1=zeros(1,n);
s2=zeros(1,n);
s3=zeros(1,n);
for(k=1:n)
s1(k)=(s0(k)/T2);
T1=T1+imag(s1(k))/4000;
s2(k)=0.03imag(s1(k))+T1;
s3(k)=T2;
T2=T2(real(s1(k))+j*s2(k));
end;
plot(1:n,real(s3),'b.-',1:n,real(s0),'r.-')
return
"Magnus Danielson" magnus@rubidium.se schrieb am 17.03.2021 19:20:49:
Hi time-nuts,
a PLL takes the phase difference of the incoming signal and the
synthesized signal and feeds that in a loop filter. The output of the
filter is used to steer the local oscillator.
In my setup I have an incoming complex signal and my local oscillator
generating a complex signal as well. So calculation of the phase
difference is just the quotient of the incoming signal and the local
oscillator, it is a sampled system. I take the quotient, calculate the
angle using the atan function and then I feed it in the loop filter, a
controller. The output of the loop filter is converted to a complex
increment for the local oscillator with the sin and cos function.
Now I have to get rid of the atan, cos and sin functions.
I am looking for a loop filter which takes the quotient of the
incoming/synthesized signal as a complex value. The output of this
filter should be the phase increment for the local oscillator. It
not use the angle of the complex value explicitly, as this will
the atan/cos/sin functions.
Is someone aware of such a loop filter? I surfed through Gardners'
'Phaselock Techniques' but did not find a hint.
That book is full of hints. Costas loop is one. Actually, you could just
do complex multiplication and only use the real output (and thus remove
half the complex multiplication) and use that output of the
multiplication as input to normal PI-regulator, that will lock up and
achieve everything you want. You can then also remove the sine with a
squarewave. There is some benefits and losses in doing that, which may
or may not be relevant.
There is a richness of complex detectors to be found in GPS literature,
such as that of "Understanding GPS principles and applications" of
Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
design" by Wolaver for additional inspiration. You end up finding that
Garners' book is actually very comprehensive if you only take time to
dwell into it.
Let me know if you need more hints.
Cheers and 73,
Magnus SA0MAD
time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe
send an email to time-nuts-leave@lists.febo.com
To unsubscribe, go to and follow the instructions there.
Hi,
yes, got it, I think, thanks.
I calculate the complex quotient of the incoming complex signal and the
local complex oscillator. I feed the imaginary part of the quotient to the
PI controller, thus forcing it to zero. The local oscillator is updated by
multiplying it with ( real(quotient)+j*PIOutput ). Forcing the imaginary
part of the quotient to zero means that incoming signal and local
oscillator are in phase.
See Matlab code and the image.
No atan/cos/sin, just mere multiplication :))
Thanks
Cheers
Detlef Schücker
DD4WV
clear
n=10000;
T1=0;
T2=0.01;
s0=exp(j*2*pi*200*(0:n-1)/n);
s1=zeros(1,n);
s2=zeros(1,n);
s3=zeros(1,n);
for(k=1:n)
s1(k)=(s0(k)/T2);
T1=T1+imag(s1(k))/4000;
s2(k)=0.03*imag(s1(k))+T1;
s3(k)=T2;
T2=T2*(real(s1(k))+j*s2(k));
end;
plot(1:n,real(s3),'b.-',1:n,real(s0),'r.-')
return
"Magnus Danielson" <magnus@rubidium.se> schrieb am 17.03.2021 19:20:49:
> Von: "Magnus Danielson" <magnus@rubidium.se>
> An: time-nuts@lists.febo.com
> Datum: 17.03.2021 19:59
> Betreff: [time-nuts] Re: Complex PLL
>
> Hi,
>
> On 2021-03-17 17:20, Detlef Schuecker via time-nuts wrote:
> > Hi time-nuts,
> >
> > a PLL takes the phase difference of the incoming signal and the
> > synthesized signal and feeds that in a loop filter. The output of the
loop
> > filter is used to steer the local oscillator.
> >
> > In my setup I have an incoming complex signal and my local oscillator
is
> > generating a complex signal as well. So calculation of the phase
> > difference is just the quotient of the incoming signal and the local
> > oscillator, it is a sampled system. I take the quotient, calculate the
> > angle using the atan function and then I feed it in the loop filter, a
PI
> > controller. The output of the loop filter is converted to a complex
phase
> > increment for the local oscillator with the sin and cos function.
> >
> > Now I have to get rid of the atan, cos and sin functions.
> >
> > I am looking for a loop filter which takes the quotient of the
> > incoming/synthesized signal as a complex value. The output of this
loop
> > filter should be the phase increment for the local oscillator. It
should
> > not use the angle of the complex value explicitly, as this will
involve
> > the atan/cos/sin functions.
> >
> > Is someone aware of such a loop filter? I surfed through Gardners'
> > 'Phaselock Techniques' but did not find a hint.
>
> That book is full of hints. Costas loop is one. Actually, you could just
> do complex multiplication and only use the real output (and thus remove
> half the complex multiplication) and use that output of the
> multiplication as input to normal PI-regulator, that will lock up and
> achieve everything you want. You can then also remove the sine with a
> squarewave. There is some benefits and losses in doing that, which may
> or may not be relevant.
>
> There is a richness of complex detectors to be found in GPS literature,
> such as that of "Understanding GPS principles and applications" of
> Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
> design" by Wolaver for additional inspiration. You end up finding that
> Garners' book is actually very comprehensive if you only take time to
> dwell into it.
>
> Let me know if you need more hints.
>
> Cheers and 73,
> Magnus SA0MAD
> _______________________________________________
> time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe
> send an email to time-nuts-leave@lists.febo.com
> To unsubscribe, go to and follow the instructions there.
MD
Magnus Danielson
Fri, Mar 19, 2021 12:23 PM
Hi,
On 2021-03-18 13:59, Detlef Schuecker via time-nuts wrote:
Hi,
yes, got it, I think, thanks.
I calculate the complex quotient of the incoming complex signal and the
local complex oscillator. I feed the imaginary part of the quotient to the
PI controller, thus forcing it to zero. The local oscillator is updated by
multiplying it with ( real(quotient)+j*PIOutput ). Forcing the imaginary
part of the quotient to zero means that incoming signal and local
oscillator are in phase.
See Matlab code and the image.
No atan/cos/sin, just mere multiplication :))
In the code you sent you used a division for phase detection as far as I
can tell.
The modeling approach you used is different enough that it took some
time to decode it, and maybe I would have used a different set of
variable names, but that's more me than the model.
I often use a phase-accumulator / integrator to model (and synthesize)
in PLL simulations.
Anyway, good that you are on track. Once you have that basic I think you
can quickly enough vary the theme.
You could move over from imag to real and it would only change subtly.
Cheers,
Magnus
Thanks
Cheers
Detlef Schücker
DD4WV
clear
n=10000;
T1=0;
T2=0.01;
s0=exp(j2pi200(0:n-1)/n);
s1=zeros(1,n);
s2=zeros(1,n);
s3=zeros(1,n);
for(k=1:n)
s1(k)=(s0(k)/T2);
T1=T1+imag(s1(k))/4000;
s2(k)=0.03imag(s1(k))+T1;
s3(k)=T2;
T2=T2(real(s1(k))+j*s2(k));
end;
plot(1:n,real(s3),'b.-',1:n,real(s0),'r.-')
return
"Magnus Danielson" magnus@rubidium.se schrieb am 17.03.2021 19:20:49:
Hi time-nuts,
a PLL takes the phase difference of the incoming signal and the
synthesized signal and feeds that in a loop filter. The output of the
filter is used to steer the local oscillator.
In my setup I have an incoming complex signal and my local oscillator
generating a complex signal as well. So calculation of the phase
difference is just the quotient of the incoming signal and the local
oscillator, it is a sampled system. I take the quotient, calculate the
angle using the atan function and then I feed it in the loop filter, a
controller. The output of the loop filter is converted to a complex
increment for the local oscillator with the sin and cos function.
Now I have to get rid of the atan, cos and sin functions.
I am looking for a loop filter which takes the quotient of the
incoming/synthesized signal as a complex value. The output of this
filter should be the phase increment for the local oscillator. It
not use the angle of the complex value explicitly, as this will
the atan/cos/sin functions.
Is someone aware of such a loop filter? I surfed through Gardners'
'Phaselock Techniques' but did not find a hint.
That book is full of hints. Costas loop is one. Actually, you could just
do complex multiplication and only use the real output (and thus remove
half the complex multiplication) and use that output of the
multiplication as input to normal PI-regulator, that will lock up and
achieve everything you want. You can then also remove the sine with a
squarewave. There is some benefits and losses in doing that, which may
or may not be relevant.
There is a richness of complex detectors to be found in GPS literature,
such as that of "Understanding GPS principles and applications" of
Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
design" by Wolaver for additional inspiration. You end up finding that
Garners' book is actually very comprehensive if you only take time to
dwell into it.
Let me know if you need more hints.
Cheers and 73,
Magnus SA0MAD
time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe
send an email to time-nuts-leave@lists.febo.com
To unsubscribe, go to and follow the instructions there.
Hi,
On 2021-03-18 13:59, Detlef Schuecker via time-nuts wrote:
> Hi,
>
> yes, got it, I think, thanks.
>
> I calculate the complex quotient of the incoming complex signal and the
> local complex oscillator. I feed the imaginary part of the quotient to the
> PI controller, thus forcing it to zero. The local oscillator is updated by
> multiplying it with ( real(quotient)+j*PIOutput ). Forcing the imaginary
> part of the quotient to zero means that incoming signal and local
> oscillator are in phase.
>
> See Matlab code and the image.
> No atan/cos/sin, just mere multiplication :))
In the code you sent you used a division for phase detection as far as I
can tell.
The modeling approach you used is different enough that it took some
time to decode it, and maybe I would have used a different set of
variable names, but that's more me than the model.
I often use a phase-accumulator / integrator to model (and synthesize)
in PLL simulations.
Anyway, good that you are on track. Once you have that basic I think you
can quickly enough vary the theme.
You could move over from imag to real and it would only change subtly.
Cheers,
Magnus
>
> Thanks
>
> Cheers
> Detlef Schücker
> DD4WV
>
> clear
> n=10000;
> T1=0;
> T2=0.01;
> s0=exp(j*2*pi*200*(0:n-1)/n);
> s1=zeros(1,n);
> s2=zeros(1,n);
> s3=zeros(1,n);
> for(k=1:n)
> s1(k)=(s0(k)/T2);
> T1=T1+imag(s1(k))/4000;
> s2(k)=0.03*imag(s1(k))+T1;
> s3(k)=T2;
> T2=T2*(real(s1(k))+j*s2(k));
>
> end;
> plot(1:n,real(s3),'b.-',1:n,real(s0),'r.-')
> return
>
>
>
>
>
> "Magnus Danielson" <magnus@rubidium.se> schrieb am 17.03.2021 19:20:49:
>
>> Von: "Magnus Danielson" <magnus@rubidium.se>
>> An: time-nuts@lists.febo.com
>> Datum: 17.03.2021 19:59
>> Betreff: [time-nuts] Re: Complex PLL
>>
>> Hi,
>>
>> On 2021-03-17 17:20, Detlef Schuecker via time-nuts wrote:
>>> Hi time-nuts,
>>>
>>> a PLL takes the phase difference of the incoming signal and the
>>> synthesized signal and feeds that in a loop filter. The output of the
> loop
>>> filter is used to steer the local oscillator.
>>>
>>> In my setup I have an incoming complex signal and my local oscillator
> is
>>> generating a complex signal as well. So calculation of the phase
>>> difference is just the quotient of the incoming signal and the local
>>> oscillator, it is a sampled system. I take the quotient, calculate the
>>> angle using the atan function and then I feed it in the loop filter, a
> PI
>>> controller. The output of the loop filter is converted to a complex
> phase
>>> increment for the local oscillator with the sin and cos function.
>>>
>>> Now I have to get rid of the atan, cos and sin functions.
>>>
>>> I am looking for a loop filter which takes the quotient of the
>>> incoming/synthesized signal as a complex value. The output of this
> loop
>>> filter should be the phase increment for the local oscillator. It
> should
>>> not use the angle of the complex value explicitly, as this will
> involve
>>> the atan/cos/sin functions.
>>>
>>> Is someone aware of such a loop filter? I surfed through Gardners'
>>> 'Phaselock Techniques' but did not find a hint.
>> That book is full of hints. Costas loop is one. Actually, you could just
>> do complex multiplication and only use the real output (and thus remove
>> half the complex multiplication) and use that output of the
>> multiplication as input to normal PI-regulator, that will lock up and
>> achieve everything you want. You can then also remove the sine with a
>> squarewave. There is some benefits and losses in doing that, which may
>> or may not be relevant.
>>
>> There is a richness of complex detectors to be found in GPS literature,
>> such as that of "Understanding GPS principles and applications" of
>> Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
>> design" by Wolaver for additional inspiration. You end up finding that
>> Garners' book is actually very comprehensive if you only take time to
>> dwell into it.
>>
>> Let me know if you need more hints.
>>
>> Cheers and 73,
>> Magnus SA0MAD
>> _______________________________________________
>> time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe
>> send an email to time-nuts-leave@lists.febo.com
>> To unsubscribe, go to and follow the instructions there.
>
> _______________________________________________
> time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe send an email to time-nuts-leave@lists.febo.com
> To unsubscribe, go to and follow the instructions there.
D
dschuecker
Mon, Mar 22, 2021 10:56 PM
In the code you sent you used a division for phase detection as far as I
can tell.
Yes, but it is the Matlab model code, so I dont care about division. In 'real life' I multiply with the conjugate complex value. It has the same angle and different length, but I normalize anyway.
And the 'atan' is always 'atan2', sure.
For a non-complex PLL I beat down to zero the angle of the phase discriminator.
In this complex PLL I beat down to zero the imaginary part of the quotient.
Another very interesting detail: The carrier I pll on is at 2400Hz, I have to demodulate with a synched 1800Hz. This means that I have to find the complex value which has 3/4 of the angle without atan/cos/sin, sqrt is ok.
This C-Code does the trick:
cpl4.re=sqrt((1.0+cpl3.re)/2.0f);
cpl4.im=sqrt((1.0-cpl3.re)/2.0f);
cpl5.re=sqrt((1.0+cpl4.re)/2.0f);
cpl5.im=sqrt((1.0-cpl4.re)/2.0f);
CMUL(cpl5,cpl5,cpl4);
CMUL(cpl4,cpl5,cpl3);
CROT(T3,cpl3);
much fun !
Math rulez !
Cheers
Detlef
Am 19.03.2021 um 13:23 schrieb Magnus Danielson:
Hi,
On 2021-03-18 13:59, Detlef Schuecker via time-nuts wrote:
Hi,
yes, got it, I think, thanks.
I calculate the complex quotient of the incoming complex signal and the
local complex oscillator. I feed the imaginary part of the quotient to the
PI controller, thus forcing it to zero. The local oscillator is updated by
multiplying it with ( real(quotient)+j*PIOutput ). Forcing the imaginary
part of the quotient to zero means that incoming signal and local
oscillator are in phase.
See Matlab code and the image.
No atan/cos/sin, just mere multiplication :))
In the code you sent you used a division for phase detection as far as I
can tell.
The modeling approach you used is different enough that it took some
time to decode it, and maybe I would have used a different set of
variable names, but that's more me than the model.
I often use a phase-accumulator / integrator to model (and synthesize)
in PLL simulations.
Anyway, good that you are on track. Once you have that basic I think you
can quickly enough vary the theme.
You could move over from imag to real and it would only change subtly.
Cheers,
Magnus
Thanks
Cheers
Detlef Schücker
DD4WV
clear
n=10000;
T1=0;
T2=0.01;
s0=exp(j2pi200(0:n-1)/n);
s1=zeros(1,n);
s2=zeros(1,n);
s3=zeros(1,n);
for(k=1:n)
s1(k)=(s0(k)/T2);
T1=T1+imag(s1(k))/4000;
s2(k)=0.03imag(s1(k))+T1;
s3(k)=T2;
T2=T2(real(s1(k))+j*s2(k));
end;
plot(1:n,real(s3),'b.-',1:n,real(s0),'r.-')
return
"Magnus Danielson" magnus@rubidium.se schrieb am 17.03.2021 19:20:49:
Von: "Magnus Danielson" magnus@rubidium.se
An: time-nuts@lists.febo.com
Datum: 17.03.2021 19:59
Betreff: [time-nuts] Re: Complex PLL
Hi,
On 2021-03-17 17:20, Detlef Schuecker via time-nuts wrote:
Hi time-nuts,
a PLL takes the phase difference of the incoming signal and the
synthesized signal and feeds that in a loop filter. The output of the
loop
filter is used to steer the local oscillator.
In my setup I have an incoming complex signal and my local oscillator
is
generating a complex signal as well. So calculation of the phase
difference is just the quotient of the incoming signal and the local
oscillator, it is a sampled system. I take the quotient, calculate the
angle using the atan function and then I feed it in the loop filter, a
PI
controller. The output of the loop filter is converted to a complex
phase
increment for the local oscillator with the sin and cos function.
Now I have to get rid of the atan, cos and sin functions.
I am looking for a loop filter which takes the quotient of the
incoming/synthesized signal as a complex value. The output of this
loop
filter should be the phase increment for the local oscillator. It
should
not use the angle of the complex value explicitly, as this will
involve
the atan/cos/sin functions.
Is someone aware of such a loop filter? I surfed through Gardners'
'Phaselock Techniques' but did not find a hint.
That book is full of hints. Costas loop is one. Actually, you could just
do complex multiplication and only use the real output (and thus remove
half the complex multiplication) and use that output of the
multiplication as input to normal PI-regulator, that will lock up and
achieve everything you want. You can then also remove the sine with a
squarewave. There is some benefits and losses in doing that, which may
or may not be relevant.
There is a richness of complex detectors to be found in GPS literature,
such as that of "Understanding GPS principles and applications" of
Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
design" by Wolaver for additional inspiration. You end up finding that
Garners' book is actually very comprehensive if you only take time to
dwell into it.
Let me know if you need more hints.
Cheers and 73,
Magnus SA0MAD
time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe
send an email to time-nuts-leave@lists.febo.com
To unsubscribe, go to and follow the instructions there.
time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe send an email to time-nuts-leave@lists.febo.com
To unsubscribe, go to and follow the instructions there.
time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe send an email to time-nuts-leave@lists.febo.com
To unsubscribe, go to and follow the instructions there.
Hi,
>>>>
In the code you sent you used a division for phase detection as far as I
can tell.
Yes, but it is the Matlab model code, so I dont care about division. In 'real life' I multiply with the conjugate complex value. It has the same angle and different length, but I normalize anyway.
And the 'atan' is always 'atan2', sure.
For a non-complex PLL I beat down to zero the angle of the phase discriminator.
In this complex PLL I beat down to zero the imaginary part of the quotient.
Another very interesting detail: The carrier I pll on is at 2400Hz, I have to demodulate with a synched 1800Hz. This means that I have to find the complex value which has 3/4 of the angle without atan/cos/sin, sqrt is ok.
This C-Code does the trick:
cpl4.re=sqrt((1.0+cpl3.re)/2.0f);
cpl4.im=sqrt((1.0-cpl3.re)/2.0f);
cpl5.re=sqrt((1.0+cpl4.re)/2.0f);
cpl5.im=sqrt((1.0-cpl4.re)/2.0f);
CMUL(cpl5,cpl5,cpl4);
CMUL(cpl4,cpl5,cpl3);
CROT(T3,cpl3);
much fun !
Math rulez !
Cheers
Detlef
Am 19.03.2021 um 13:23 schrieb Magnus Danielson:
> Hi,
>
> On 2021-03-18 13:59, Detlef Schuecker via time-nuts wrote:
>> Hi,
>>
>> yes, got it, I think, thanks.
>>
>> I calculate the complex quotient of the incoming complex signal and the
>> local complex oscillator. I feed the imaginary part of the quotient to the
>> PI controller, thus forcing it to zero. The local oscillator is updated by
>> multiplying it with ( real(quotient)+j*PIOutput ). Forcing the imaginary
>> part of the quotient to zero means that incoming signal and local
>> oscillator are in phase.
>>
>> See Matlab code and the image.
>> No atan/cos/sin, just mere multiplication :))
> In the code you sent you used a division for phase detection as far as I
> can tell.
>
> The modeling approach you used is different enough that it took some
> time to decode it, and maybe I would have used a different set of
> variable names, but that's more me than the model.
>
> I often use a phase-accumulator / integrator to model (and synthesize)
> in PLL simulations.
>
> Anyway, good that you are on track. Once you have that basic I think you
> can quickly enough vary the theme.
>
> You could move over from imag to real and it would only change subtly.
>
> Cheers,
> Magnus
>
>> Thanks
>>
>> Cheers
>> Detlef Schücker
>> DD4WV
>>
>> clear
>> n=10000;
>> T1=0;
>> T2=0.01;
>> s0=exp(j*2*pi*200*(0:n-1)/n);
>> s1=zeros(1,n);
>> s2=zeros(1,n);
>> s3=zeros(1,n);
>> for(k=1:n)
>> s1(k)=(s0(k)/T2);
>> T1=T1+imag(s1(k))/4000;
>> s2(k)=0.03*imag(s1(k))+T1;
>> s3(k)=T2;
>> T2=T2*(real(s1(k))+j*s2(k));
>>
>> end;
>> plot(1:n,real(s3),'b.-',1:n,real(s0),'r.-')
>> return
>>
>>
>>
>>
>>
>> "Magnus Danielson" <magnus@rubidium.se> schrieb am 17.03.2021 19:20:49:
>>
>>> Von: "Magnus Danielson" <magnus@rubidium.se>
>>> An: time-nuts@lists.febo.com
>>> Datum: 17.03.2021 19:59
>>> Betreff: [time-nuts] Re: Complex PLL
>>>
>>> Hi,
>>>
>>> On 2021-03-17 17:20, Detlef Schuecker via time-nuts wrote:
>>>> Hi time-nuts,
>>>>
>>>> a PLL takes the phase difference of the incoming signal and the
>>>> synthesized signal and feeds that in a loop filter. The output of the
>> loop
>>>> filter is used to steer the local oscillator.
>>>>
>>>> In my setup I have an incoming complex signal and my local oscillator
>> is
>>>> generating a complex signal as well. So calculation of the phase
>>>> difference is just the quotient of the incoming signal and the local
>>>> oscillator, it is a sampled system. I take the quotient, calculate the
>>>> angle using the atan function and then I feed it in the loop filter, a
>> PI
>>>> controller. The output of the loop filter is converted to a complex
>> phase
>>>> increment for the local oscillator with the sin and cos function.
>>>>
>>>> Now I have to get rid of the atan, cos and sin functions.
>>>>
>>>> I am looking for a loop filter which takes the quotient of the
>>>> incoming/synthesized signal as a complex value. The output of this
>> loop
>>>> filter should be the phase increment for the local oscillator. It
>> should
>>>> not use the angle of the complex value explicitly, as this will
>> involve
>>>> the atan/cos/sin functions.
>>>>
>>>> Is someone aware of such a loop filter? I surfed through Gardners'
>>>> 'Phaselock Techniques' but did not find a hint.
>>> That book is full of hints. Costas loop is one. Actually, you could just
>>> do complex multiplication and only use the real output (and thus remove
>>> half the complex multiplication) and use that output of the
>>> multiplication as input to normal PI-regulator, that will lock up and
>>> achieve everything you want. You can then also remove the sine with a
>>> squarewave. There is some benefits and losses in doing that, which may
>>> or may not be relevant.
>>>
>>> There is a richness of complex detectors to be found in GPS literature,
>>> such as that of "Understanding GPS principles and applications" of
>>> Kaplan and Hegarty. You can also look at "Phase-locked loop circuit
>>> design" by Wolaver for additional inspiration. You end up finding that
>>> Garners' book is actually very comprehensive if you only take time to
>>> dwell into it.
>>>
>>> Let me know if you need more hints.
>>>
>>> Cheers and 73,
>>> Magnus SA0MAD
>>> _______________________________________________
>>> time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe
>>> send an email to time-nuts-leave@lists.febo.com
>>> To unsubscribe, go to and follow the instructions there.
>> _______________________________________________
>> time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe send an email to time-nuts-leave@lists.febo.com
>> To unsubscribe, go to and follow the instructions there.
> _______________________________________________
> time-nuts mailing list -- time-nuts@lists.febo.com -- To unsubscribe send an email to time-nuts-leave@lists.febo.com
> To unsubscribe, go to and follow the instructions there.
>
MD
Magnus Danielson
Tue, Mar 23, 2021 12:36 PM
Hi
On 2021-03-22 23:56, dschuecker wrote:
In the code you sent you used a division for phase detection as far
as I can tell.
Yes, but it is the Matlab model code, so I dont care about division.
In 'real life' I multiply with the conjugate complex value. It has the
same angle and different length, but I normalize anyway.
In my experience I've found it useful to make the model for simulation
as close to the actual model as reasonable, and pure simulation model
tricks distinct from that of normal modeling. My note was only because I
found it a bit hard to separate it up, part due to fatigue issues, but
also because the modeling was not as distinct as I've grown used to, so
hence my comment.
And the 'atan' is always 'atan2', sure.
For a non-complex PLL I beat down to zero the angle of the phase
discriminator.
In this complex PLL I beat down to zero the imaginary part of the
quotient.
You can use real part just as well when you do multiplication. The
difference between complex division and complex multiplication isn't as
great if only amplitudes are fixed, because as the divisor is multiplied
to both sides with the complementary, what remains is a multiplication
with a fixed divisor, so sure, it's about the same but with the complex
inversed.
Another very interesting detail: The carrier I pll on is at 2400Hz, I
have to demodulate with a synched 1800Hz. This means that I have to
find the complex value which has 3/4 of the angle without
atan/cos/sin, sqrt is ok.
This C-Code does the trick:
cpl4.re=sqrt((1.0+cpl3.re)/2.0f);
cpl4.im=sqrt((1.0-cpl3.re)/2.0f);
cpl5.re=sqrt((1.0+cpl4.re)/2.0f);
cpl5.im=sqrt((1.0-cpl4.re)/2.0f);
CMUL(cpl5,cpl5,cpl4);
CMUL(cpl4,cpl5,cpl3);
CROT(T3,cpl3);
I've done similar stuff to produce 1544 kHz out of a 8 kHz DDS. You got
to live prime numbers like 193 when doing synthesis! I did a x193 on the
sawtooth, cut at the right point and I had a 1544 kHz sawtooth. No extra
oscillator, just a multiplicator block that I had spare anyway. :)
Cheers,
Magnus
Hi
On 2021-03-22 23:56, dschuecker wrote:
> Hi,
>> In the code you sent you used a division for phase detection as far
>> as I can tell.
>
> Yes, but it is the Matlab model code, so I dont care about division.
> In 'real life' I multiply with the conjugate complex value. It has the
> same angle and different length, but I normalize anyway.
In my experience I've found it useful to make the model for simulation
as close to the actual model as reasonable, and pure simulation model
tricks distinct from that of normal modeling. My note was only because I
found it a bit hard to separate it up, part due to fatigue issues, but
also because the modeling was not as distinct as I've grown used to, so
hence my comment.
>
> And the 'atan' is always 'atan2', sure.
>
> For a non-complex PLL I beat down to zero the angle of the phase
> discriminator.
> In this complex PLL I beat down to zero the imaginary part of the
> quotient.
You can use real part just as well when you do multiplication. The
difference between complex division and complex multiplication isn't as
great if only amplitudes are fixed, because as the divisor is multiplied
to both sides with the complementary, what remains is a multiplication
with a fixed divisor, so sure, it's about the same but with the complex
inversed.
>
> Another very interesting detail: The carrier I pll on is at 2400Hz, I
> have to demodulate with a synched 1800Hz. This means that I have to
> find the complex value which has 3/4 of the angle without
> atan/cos/sin, sqrt is ok.
So much fun.
>
> This C-Code does the trick:
> cpl4.re=sqrt((1.0+cpl3.re)/2.0f);
> cpl4.im=sqrt((1.0-cpl3.re)/2.0f);
> cpl5.re=sqrt((1.0+cpl4.re)/2.0f);
> cpl5.im=sqrt((1.0-cpl4.re)/2.0f);
> CMUL(cpl5,cpl5,cpl4);
> CMUL(cpl4,cpl5,cpl3);
> CROT(T3,cpl3);
I've done similar stuff to produce 1544 kHz out of a 8 kHz DDS. You got
to live prime numbers like 193 when doing synthesis! I did a x193 on the
sawtooth, cut at the right point and I had a 1544 kHz sawtooth. No extra
oscillator, just a multiplicator block that I had spare anyway. :)
Cheers,
Magnus