# Phase locked loop

**URL:** <https://www.ruby-forum.com/t/phase-locked-loop/234599>\
**Category:** GNU Radio\
**Created:** [March 17, 2015, 2:31am UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599 "2015-03-17T02:31:02Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [March 17, 2015, 2:31am UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599/1 "2015-03-17T02:31:02Z")

</div>

Hi, Currently I am doing my Final Year Project to develop a phase  
measurement using Phase Locked Loop theory. I am using USRP N210 for the  
hardware and I have installed Gnuradio Companion in Ubuntu 12.04  
LTS (running in VMplayer). I have studied online that I can’t use  
companion to add and drop the current available blocks to construct a  
phase locked loop. I managed to locate gr\_pll\_carriertracking\_cc.cc and  
gr\_pll\_carriertracking\_cc.h file from gnuradio source archive. I also  
know that I can use gr\_modtool to construct my own OOT module. But I am  
having some difficulties in using gr\_modtool. There are many functions  
is the gr\_pll\_carriertracking\_cc.cc.

My question are

(a) What should I include for the valid argument list during the  
gr\_modtool add process?  
reference link  
: [http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorial\_GNU\_Radio\_in\_C++#432-Specific-block-categories](http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorial_GNU_Radio_in_C++#432-Specific-block-categories) (4.2.3  
Step 2)

(b) Am I putting the whole code (gr\_pll\_carriertracking\_cc.cc) and  
generate it as ONE OOT module with few functions inside or should I  
separate the functions to become more OOT module and connect them using  
wire in companion?

(c) How can I include all the header file into the make process?  
There are few header files being used in the code such as  
gr\_io\_signature.h , gr\_sincos.h….

I would really appreciate your help in guiding me.

Thank you very much.

Best regards,

Wai Yee.

---

<div class="post-metadata">

**Author:** ![yee\_yy1992](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f04885/32.png) [@yee\_yy1992](https://www.ruby-forum.com/u/yee_yy1992)\
**Post date:** [March 17, 2015, 4:20am UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599/2 "2015-03-17T04:20:09Z")

</div>

On 16.03.2015 18:05, yee\_yy1992 wrote:

> My question are
> 
> (a)What should I include for the valid argument list during the  
> gr\_modtool add process?  
> reference link :

[http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided\_Tutorial\_GNU\_Radio\_in\_C++#432-Specific-block-categories](http://gnuradio.org/redmine/projects/gnuradio/wiki/Guided_Tutorial_GNU_Radio_in_C++#432-Specific-block-categories)  
(4.2.3

> Step 2)

This depends what you want to achieve. Use gr\_modtool help add for more  
advice.

> (b)Am I putting the whole code (gr\_pll\_carriertracking\_cc.cc  
> [http://cc.cc/](http://cc.cc/)) and generate it as _ONE_ OOT module with few functions  
> inside or should I separate the functions to become more OOT module and  
> connect them using wire in companion?

More modular is usually better.

> (c)How can I include all the header file into the make process? There  
> are few header files being used in the code such as gr\_io\_signature.h ,  
> gr\_sincos.h.

How good is your C++? Maybe it’s worth brushing up the basics first, or  
perhaps you might consider writing the block in Python.  
Also, I recommend looking at some of the blocks in GNU Radio as  
examples. I didn’t fully understand what your objective is, but there  
are PLL blocks which you can have a look at for input.

Cheers,  
M

---

<div class="post-metadata">

**Author:** ![yee\_yy1992](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f04885/32.png) [@yee\_yy1992](https://www.ruby-forum.com/u/yee_yy1992)\
**Post date:** [March 17, 2015, 3:10pm UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599/3 "2015-03-17T15:10:55Z")

</div>

Hi Daniele,

> Also, I don’t see why you cannot combine other blocks to realize  
> your own PLL implementation. Where did you read that you “cant use  
> companion to add and drop the current available blocks to construct a  
> phase locked loop”?  
> Wai Yee has a point here – you can’t have a circle in your (sample  
> stream) flow graph – GNU Radio doesn’t allow that for reasons of  
> causality.

You can have a “loose” loop with feedback done with message ports, but  
that’s not the same as a control loop (since there’s no defined delay  
between the sample for which a error was estimated and the sample where  
the error correction is applied when using the asynchronous messages).

Thus, you can’t drag’n’drop together a “proper” control loop from  
discrete things like adders and integrators that you could design and  
analyze theoretically.

In effect, GNU Radio’s control loops are monolithic blocks – that’s  
somewhat sad from a modularity perspective, but then again, there’s the  
control loop base class that allows you to implement arbitrary control  
loops rather easily, so Wai Yee, I recommend looking at the  
documentation [1], the referenced paper and the source code[2] of the  
existing costas loop.

Best regards,  
Marcus M.

PS:

> I am using _USRP N210_ for the hardware and I have installed _Gnuradio  
> Companion_ in _Ubuntu 12.04 LTS_ (running in VMplayer).  
> as a side note, I don’t recommend running your digital signal processing  
> for a high-rate capable device inside a VM, unless you know what you’re  
> doing – the additional overhead in network packet handling might prove  
> to be a problem. At lower rates, it should work fine.  
> Also, why are you using a three years old Ubuntu? There’s a new LTS  
> release, almost a year old now, 14.04; I recommend using a modern  
> platform.

[1]

> **[GNU Radio Manual and C++ API Reference: gr::digital::costas\_loop\_cc Class...](https://www.gnuradio.org/doc/doxygen/classgr_1_1digital_1_1costas __loop__ cc.html)**

[2]

> <https://github.com/gnuradio/gnuradio/blob/master/gr-digital/lib/costas_loop_cc_impl.cc>

---

<div class="post-metadata">

**Author:** ![yee\_yy1992](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f04885/32.png) [@yee\_yy1992](https://www.ruby-forum.com/u/yee_yy1992)\
**Post date:** [March 17, 2015, 9:15am UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599/4 "2015-03-17T09:15:03Z")

</div>

On 17/03/15 02:05, yee\_yy1992 wrote:

> Hi, Currently I am doing my Final Year Project to develop a phase  
> measurement using Phase Locked Loop theory. I am using _USRP N210_ for  
> the hardware and I have installed _Gnuradio Companion_ in _Ubuntu 12.04  
> LTS_ (running in VMplayer). I have studied online that I cant use  
> companion to add and drop the current available blocks to construct a  
> phase locked loop.

Hello,

what to you mean by that last sentence? GNURadio comes with PLL blocks  
in a few different fashions that can be used from the companion just  
fine. Also, I don’t see why you cannot combine other blocks to realize  
your own PLL implementation. Where did you read that you “cant use  
companion to add and drop the current available blocks to construct a  
phase locked loop”?

Cheers,  
Daniele

---

<div class="post-metadata">

**Author:** ![yee\_yy1992](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f04885/32.png) [@yee\_yy1992](https://www.ruby-forum.com/u/yee_yy1992)\
**Post date:** [March 17, 2015, 4:30pm UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599/5 "2015-03-17T16:30:03Z")

</div>

Hi Daniele,

On 03/17/2015 03:38 PM, Daniele N. wrote:

> I realized this while having my coffee this morning. I should avoid to  
> reply to emails before assuming the right amount of caffeine 🙂  
> oh… I know that feeling!

> > In effect, GNU Radio’s control loops are monolithic blocks – that’s  
> > somewhat sad from a modularity perspective, but then again, there’s the  
> > control loop base class that allows you to implement arbitrary control  
> > loops rather easily  
> > Last time I looked into it, this base class is not that generic: it can  
> > be easily used to implement phase-lock loops, but it did not seem  
> > designed to control other quantities, like amplitude for example. But I  
> > may have had a too quick loot at it.  
> > I’d have to admit, you’re right. I’m not quite sure, but I think Wai Yee  
> > really just wants a PLL – so that would be fine.

Greetings,  
Marcus

---

<div class="post-metadata">

**Author:** ![yee\_yy1992](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f04885/32.png) [@yee\_yy1992](https://www.ruby-forum.com/u/yee_yy1992)\
**Post date:** [March 17, 2015, 3:39pm UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599/6 "2015-03-17T15:39:52Z")

</div>

On 17/03/15 15:08, Marcus M. wrote:

> You can have a “loose” loop with feedback done with message ports, but  
> that’s not the same as a control loop (since there’s no defined delay  
> between the sample for which a error was estimated and the sample where  
> the error correction is applied when using the asynchronous messages).
> 
> Thus, you can’t drag’n’drop together a “proper” control loop from  
> discrete things like adders and integrators that you could design and  
> analyze theoretically.

Hello Marcus,

I realized this while having my coffee this morning. I should avoid to  
reply to emails before assuming the right amount of caffeine 🙂

> In effect, GNU Radio’s control loops are monolithic blocks – that’s  
> somewhat sad from a modularity perspective, but then again, there’s the  
> control loop base class that allows you to implement arbitrary control  
> loops rather easily

Last time I looked into it, this base class is not that generic: it can  
be easily used to implement phase-lock loops, but it did not seem  
designed to control other quantities, like amplitude for example. But I  
may have had a too quick loot at it.

Cheers,  
Daniele

---

<div class="post-metadata">

**Author:** ![yee\_yy1992](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f04885/32.png) [@yee\_yy1992](https://www.ruby-forum.com/u/yee_yy1992)\
**Post date:** [March 18, 2015, 10:43pm UTC](https://www.ruby-forum.com/t/phase-locked-loop/234599/7 "2015-03-18T22:43:29Z")

</div>

Hi Yee,

Oh I did forget to put the link of the book, sorry!!! Here is the book:

> **[Digital Communications: A Discrete-Time Approach: Rice, Michael: 9780130304971:...](https://www.amazon.com/Digital-Communications-Discrete-Time-Michael-Rice/dp/0130304972)**
>
> Digital Communications: A Discrete-Time Approach \[Rice, Michael\] on Amazon.com. \*FREE\* shipping on qualifying offers. Digital Communications: A Discrete-Time Approach

If you want to implement a PLL by yourself, I prefer to see an example  
of  
QPSK Tx/Rx in Matlab:

[http://www.mathworks.com/help/comm/examples/qpsk-transmitter-and-receiver.html](http://www.mathworks.com/help/comm/examples/qpsk-transmitter-and-receiver.html)

However, it’s convenient to use available blocks in GNURadio.

Best,  
Mostafa

On Wed, Mar 18, 2015 at 4:11 AM, yee\_yy1992 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> If you want to have a loop within GNURadio, you must have a delay within
> 
> > gr\_pll\_carriertracking\_cc.h file from gnuradio source archive. I also know  
> > Step 2)
> > 
> > [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> > Amirkabir University Of Technology  
> > Tehran  
> > IRAN  
> > Tel: +98 (919) 158-7730  
> > LAB: [http://ele.aut.ac.ir/~mmwcl/?page\_id=411](http://ele.aut.ac.ir/~mmwcl/?page_id=411)  
> > Homepage: [http://ele.aut.ac.ir/~alizadeh/](http://ele.aut.ac.ir/~alizadeh/)
> 
> * * *

–

* * *

Department of Electrical Engineering  
Aboureyhan Building  
MMWCL LAB  
Amirkabir University Of Technology  
Tehran  
IRAN  
Tel: +98 (919) 158-7730  
LAB: [http://ele.aut.ac.ir/~mmwcl/?page\_id=411](http://ele.aut.ac.ir/~mmwcl/?page_id=411)  
Homepage: [http://ele.aut.ac.ir/~alizadeh/](http://ele.aut.ac.ir/~alizadeh/)

* * *
