# Considerations when running a flowgraph manually from a loop

**URL:** <https://www.ruby-forum.com/t/considerations-when-running-a-flowgraph-manually-from-a-loop/233763>\
**Category:** GNU Radio\
**Created:** [January 9, 2015, 7:42pm UTC](https://www.ruby-forum.com/t/considerations-when-running-a-flowgraph-manually-from-a-loop/233763 "2015-01-09T19:42:56Z")\
**Posts on this page:** 2\
**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:** [January 9, 2015, 7:42pm UTC](https://www.ruby-forum.com/t/considerations-when-running-a-flowgraph-manually-from-a-loop/233763/1 "2015-01-09T19:42:56Z")

</div>

Hi all,

I’ve written a small program to capture and plot fft data from the USRP.  
Because it can also sweep and I have a limited knowledge (for now!) of  
writing GNURadio blocks, I decided to use a separate main loop to run  
the flowgraph and then handle the data. The flowgraph uses the head  
block to exit automatically when it has captured the necessary amount of  
samples. This setup really simplified handling retuning and plotting the  
data for me.

When sweeping, I expect there to be some junk samples acquired in the  
buffer while the LO retunes and I can handle that with the skip block,  
but when I set my program to only tune the USRP once and then plot the  
FFT constantly (basically emulating uhd\_fft), I’m still getting junk  
data. I’ve double checked that the LO remains locked after the initial  
tune, so I think this extra junk data is a result of running the  
flowgraph, letting it exit, processing the data, and then running it  
again. uhd\_fft, which is implemented as a block, does not have the same  
issues.

I’ve included 3 screenshots. 1 is uhd\_fft running on my USRP N210, the  
other two are data from from my program plotted in matplotlib. In 1, you  
can see noise plotted as you’d expect, except that the LO is MUCH more  
visible than in uhd\_fft. I confirmed that uhd\_fft is not offsetting the  
LO so I’m not sure if this is another side effect of how I’m handing the  
flowgraph. Another screenshot shows the junk data that occasionally pops  
in and ruins my day.

My basic flowgraph setup is:

```
    self.connect(self.usrp, self.skip) # USRP attached to skip 

```

block (modified to be resetable like head)  
self.connect(self.skip, s2v, self.head) # skip -\>  
stream\_to\_vector -\> head  
self.connect(self.head, fft) # head -\> fft\_vcc  
self.connect(fft, c2mag\_sq)  
self.connect(c2mag\_sq, stats, W2dBm, self.final\_vsink)

In the last line, stats is just a block that can handle averaging, W2dBm  
translates to dBm, and then all samples are dumped into a float vector  
sink

My program was set to skip 0 samples for these tests.

The main loop in pseudocode:

topblock.set\_usrp\_freq()  
while True:  
topblock.run()  
data = topblock.final\_vsink.data()  
process and plot data  
topblock.skip.reset()  
topblock.head.reset()

- Is there anything tricky I should know about running a flowgraph from  
a separate loop like I’m doing?
- What could cause the LO to be so much more pronounced in my plots as  
compared to uhd\_fft? For the screenshots I went to great lengths to  
ensure I was using the same tuning and plotting parameters. Also,  
although I can control the “junk” data by skipping samples with the  
“skip” block, it does not reduce the LO throughput.
- Any leads on what could be causing the junk data even when the USRP is  
not being retuned?

I’m at wits end, thanks in advance for any hints whatsoever.  
-Doug

---

<div class="post-metadata">

**Author:** ![AndersonS\_Douglas\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/53a042/32.png) [@AndersonS\_Douglas\_J](https://www.ruby-forum.com/u/AndersonS_Douglas_J)\
**Post date:** [January 20, 2015, 4:07pm UTC](https://www.ruby-forum.com/t/considerations-when-running-a-flowgraph-manually-from-a-loop/233763/2 "2015-01-20T16:07:59Z")

</div>

On Fri, Jan 9, 2015 at 1:41 PM, Anderson, Douglas J. \<  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)\> wrote:

> buffer while the LO retunes and I can handle that with the skip block, but  
> visible than in uhd\_fft. I confirmed that uhd\_fft is not offsetting the LO  
> self.connect(self.head, fft) # head → fft\_vcc  
> topblock.set\_usrp\_freq()
> 
> - What could cause the LO to be so much more pronounced in my plots as  
> compared to uhd\_fft? For the screenshots I went to great lengths to ensure  
> I was using the same tuning and plotting parameters. Also, although I can  
> control the “junk” data by skipping samples with the “skip” block, it does  
> not reduce the LO throughput.
> - Any leads on what could be causing the junk data even when the USRP is  
> not being retuned?
> 
> I’m at wits end, thanks in advance for any hints whatsoever.  
> -Doug

Doug,

In your stats block, is there any history? Are you keeping samples in  
there  
to do the averaging, and can you reset that as well? What it looks like  
in  
your last image is a sharp discontinuity between samples, so basically  
multiplying by a square wave in the time domain. If you are looking at  
two  
sets of data that are not continuous because of the restart of the  
flowgraph, that could show up here.

Tom
