# How to align Tx/Rx timestamps

**URL:** <https://www.ruby-forum.com/t/how-to-align-tx-rx-timestamps/217755>\
**Category:** GNU Radio\
**Created:** [March 11, 2012, 5:35pm UTC](https://www.ruby-forum.com/t/how-to-align-tx-rx-timestamps/217755 "2012-03-11T17:35:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [March 11, 2012, 5:35pm UTC](https://www.ruby-forum.com/t/how-to-align-tx-rx-timestamps/217755/1 "2012-03-11T17:35:51Z")

</div>

Hi,

I want to implement a TDD system on Gnuradio using stream tags. The  
receiver first detects bursts from another transmitter and sets  
timestamps  
of its bursts accordingly. I have some experiece in writing custom  
blocks,  
but I have never touched the UHD api nor the gr\_uhd blocks. I want to  
know  
how to align timestamps of UHD source and sink blocks. Does it matter if  
I  
use the same or separate boxes? I guidline for general MIMO case would  
be  
appreciated.

Best regards!

---

<div class="post-metadata">

**Author:** ![qaz\_w](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/b5ac83/32.png) [@qaz\_w](https://www.ruby-forum.com/u/qaz_w)\
**Post date:** [March 12, 2012, 12:21am UTC](https://www.ruby-forum.com/t/how-to-align-tx-rx-timestamps/217755/2 "2012-03-12T00:21:20Z")

</div>

On 03/11/2012 09:35 AM, yend B. wrote:

> Hi,
> 
> I want to implement a TDD system on Gnuradio using stream tags. The  
> receiver first detects bursts from another transmitter and sets timestamps  
> of its bursts accordingly. I have some experiece in writing custom blocks,  
> but I have never touched the UHD api nor the gr\_uhd blocks. I want to know  
> how to align timestamps of UHD source and sink blocks. Does it matter if I  
> use the same or separate boxes? I guidline for general MIMO case would be  
> appreciated.

1. The simple option:

Multiple network devices like N210 can be grouped into one block with  
multiple channels. Example:  
[http://old.nabble.com/attachment/32790029/0/4Channel.png](http://old.nabble.com/attachment/32790029/0/4Channel.png)

In this situation, all channels are aligned in time. Similarly, with the  
usrp sink, all outputs channels are tagged with the same transmit time.  
For this option, there is an assumption that the channels are  
homogeneous (same sample rate).

1. A more complicated option:

More complication, but more control. You can 1 source and 1 sink block  
per USRP device. In this situation, to have transmit alignment, your  
producer blocks must tag each channel with a timestamp. Similarly, on  
receive, the consumer blocks must be aware of the timestamp on each  
channel.

A description of tags here:  
[http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr\_uhd\_usrp\_sink.h#n59](http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr_uhd_usrp_sink.h#n59)  
[http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr\_uhd\_usrp\_source.h#n59](http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr_uhd_usrp_source.h#n59)

A tags demonstration:  
[http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/examples/tags\_demo.cc](http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/examples/tags_demo.cc)

A guide to using stream tags:  
[http://gnuradio.org/redmine/projects/gnuradio/wiki/BlocksCodingGuide#Stream-Tags](http://gnuradio.org/redmine/projects/gnuradio/wiki/BlocksCodingGuide#Stream-Tags)

-josh

---

<div class="post-metadata">

**Author:** ![qaz\_w](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/b5ac83/32.png) [@qaz\_w](https://www.ruby-forum.com/u/qaz_w)\
**Post date:** [March 12, 2012, 10:10pm UTC](https://www.ruby-forum.com/t/how-to-align-tx-rx-timestamps/217755/3 "2012-03-12T22:10:49Z")

</div>

Josh B. wrote in post #1051099:

> On 03/11/2012 09:35 AM, yend B. wrote:
> 
> > Hi,
> > 
> > I want to implement a TDD system on Gnuradio using stream tags. The  
> > receiver first detects bursts from another transmitter and sets timestamps  
> > of its bursts accordingly. I have some experiece in writing custom blocks,  
> > but I have never touched the UHD api nor the gr\_uhd blocks. I want to know  
> > how to align timestamps of UHD source and sink blocks. Does it matter if I  
> > use the same or separate boxes? I guidline for general MIMO case would be  
> > appreciated.
> 
> 1. The simple option:
> 
> Multiple network devices like N210 can be grouped into one block with  
> multiple channels. Example:  
> [http://old.nabble.com/attachment/32790029/0/4Channel.png](http://old.nabble.com/attachment/32790029/0/4Channel.png)
> 
> In this situation, all channels are aligned in time. Similarly, with the  
> usrp sink, all outputs channels are tagged with the same transmit time.  
> For this option, there is an assumption that the channels are  
> homogeneous (same sample rate).
> 
> 1. A more complicated option:
> 
> More complication, but more control. You can 1 source and 1 sink block  
> per USRP device. In this situation, to have transmit alignment, your  
> producer blocks must tag each channel with a timestamp. Similarly, on  
> receive, the consumer blocks must be aware of the timestamp on each  
> channel.
> 
> A description of tags here:  
> [http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr\_uhd\_usrp\_sink.h#n59](http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr_uhd_usrp_sink.h#n59)

[http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr\_uhd\_usrp\_source.h#n59](http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/include/gr_uhd_usrp_source.h#n59)

> A tags demonstration:  
> [http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/examples/tags\_demo.cc](http://gnuradio.org/cgit/gnuradio.git/tree/gr-uhd/examples/tags_demo.cc)
> 
> A guide to using stream tags:  
> [http://gnuradio.org/redmine/projects/gnuradio/wiki/BlocksCodingGuide#Stream-Tags](http://gnuradio.org/redmine/projects/gnuradio/wiki/BlocksCodingGuide#Stream-Tags)
> 
> -josh

Using single UHD source/sink block with multiple channels could do time  
alignment of either tx or rx streams. I want to try the second option to  
synchronize tx and rx chains. As I understood, I get timestamp of the  
first sample received and I tag transmit bursts with tx\_time. But I have  
two questions:

1. Is timestamp from one sample enough? I thought that the uhd src block  
gives me timestamp of only the first sample assuming no underruns.
2. If I tag the i^th sample with tx\_time t1, does it mean that the  
transmission is suspended on the i^th sample until the time reaches t1,  
and then samples are transmitted continuously until new tag is detected?  
Yesterday I with my friend tried the sob and eob tag keys when streaming  
to the usrp, but we concluded that they can be used only to drop samples  
(instead of inserting sleep periods) which are not enclosed by sob-eob  
tag pairs.

Best Regards!

---

<div class="post-metadata">

**Author:** ![qaz\_w](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/q/b5ac83/32.png) [@qaz\_w](https://www.ruby-forum.com/u/qaz_w)\
**Post date:** [May 24, 2012, 10:16am UTC](https://www.ruby-forum.com/t/how-to-align-tx-rx-timestamps/217755/4 "2012-05-24T10:16:28Z")

</div>

> Using single UHD source/sink block with multiple channels could do time  
> alignment of either tx or rx streams. I want to try the second option to  
> synchronize tx and rx chains. As I understood, I get timestamp of the  
> first sample received and I tag transmit bursts with tx\_time. But I have  
> two questions:
> 
> 1. Is timestamp from one sample enough? I thought that the uhd src block  
> gives me timestamp of only the first sample assuming no underruns.
> 2. If I tag the i^th sample with tx\_time t1, does it mean that the  
> transmission is suspended on the i^th sample until the time reaches t1,  
> and then samples are transmitted continuously until new tag is detected?  
> Yesterday I with my friend tried the sob and eob tag keys when streaming  
> to the usrp, but we concluded that they can be used only to drop samples  
> (instead of inserting sleep periods) which are not enclosed by sob-eob  
> tag pairs.
> 
> Best Regards!

Hello,  
I am doing a similar project. And

1. Have you slved the problem of droping samples not enclosed in sob and  
eob? How to do it?
2. I want to know how to tell the USRP2 to RX for a desired length of  
time such as 5 secondss. the Only parameter is rx\_time, I donot know how  
to stop the RX.  
Thank you so much.
