# Help To Compute Average

**URL:** <https://www.ruby-forum.com/t/help-to-compute-average/231316>\
**Category:** GNU Radio\
**Created:** [August 2, 2014, 10:22pm UTC](https://www.ruby-forum.com/t/help-to-compute-average/231316 "2014-08-02T22:22:59Z")\
**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:** [August 2, 2014, 10:22pm UTC](https://www.ruby-forum.com/t/help-to-compute-average/231316/1 "2014-08-02T22:22:59Z")

</div>

Hello all

I am new to GNUradio software. I would like to compute the average  
energy and display it in the status message in real time.

To achieve this I tried to write a simple Python code attached  
(Simple2.pyw). However, I am not able to retrieve data from the

self.c2ms=gr.complex\_to\_mag\_squared(NFFT) block

1. Could you please help me what method should I use to retrieve the  
data contents of self.c2ms

2. And perform averaging (This could be performed easily using the  
function below)

3. Display the average in the right status message (i.e., in  
self.\_set\_status\_msg(“Put average here!!!”, 1)).

Finally for any given block, how can I see and modify the methods  
easily.

Note that I am using windows command line to run the python file.

A.

get average\_energy(data):  
avg1=0  
for i in data  
avg1=avg1+i  
return avg1/len(data)

---

<div class="post-metadata">

**Author:** ![Andr\_Jakob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ed655f/32.png) [@Andr\_Jakob](https://www.ruby-forum.com/u/Andr_Jakob)\
**Post date:** [August 3, 2014, 7:34pm UTC](https://www.ruby-forum.com/t/help-to-compute-average/231316/2 "2014-08-03T19:34:46Z")

</div>

I believe you need to use a probe. I’m doing something similar in the  
attached \*.grc. I use complex\_to\_mag\_squared then integrate with  
decimation  
down to 100 Hz. Take the Log10 and offset to get it in dBm, resulting  
in an  
RSSI (Received Strength Signal Indicator) The Probe Signal pulls the  
RSSI  
from the flow at 10 Hz and is displayed by a QT GUI label, but I suppose  
you  
could print it to the console too, or average it outside the flow per  
your  
pseudo-code. They key point though is getting that low rate data  
outside  
the GR flow so you can access it in python.

Note you must tweak both knobs to get the audio to work after you  
initially  
start it. This is used for direction finding of WBFM signals, as it  
computes the RSSI and generates a scaled audio tone that is useful when  
manipulating a directional antenna:  
[https://dl.dropboxusercontent.com/u/49570443/b200\_wbfm\_df.grc](https://dl.dropboxusercontent.com/u/49570443/b200_wbfm_df.grc)

You can also do it using message queues per this tutorial, but from what  
I  
have read this method is deprecated.

> **[Intro to GNURadio and the USRP (Part 4, message blocks)](https://pwnhome.wordpress.com/2011/04/19/intro-to-gnuradio-and-the-usrp-part-4/)**
>
> This week I started playing with the message source and sink blocks within GNURadio and found them quite useful. Especially for accessing (sending and receiving) data outside of the actual GNURadio…

I used the above to do a little performance testing, to pull FFTs out  
the  
flow and so see how fast the queue would fill up:  
[https://dl.dropboxusercontent.com/u/49570443/msgpass2.py](https://dl.dropboxusercontent.com/u/49570443/msgpass2.py)

Thanks,  
Lou  
KD4HSO

Andr Jakob wrote

> Note that I am using windows command line to run the python file.
> 
> get average\_energy(data):  
> avg1=0  
> for i in data  
> avg1=avg1+i  
> return avg1/len(data)

–  
View this message in context:  
[http://gnuradio.4.n7.nabble.com/Help-To-Compute-Average-tp49722p49732.html](http://gnuradio.4.n7.nabble.com/Help-To-Compute-Average-tp49722p49732.html)  
Sent from the GnuRadio mailing list archive at [Nabble.com](http://Nabble.com).
