Use of Message Sink in GNU Radio Companion

I've implemented a power spectrum display to demonstrate a way to postprocess the data gathered from GNU Radio in python.

Update (2014-04-03): An updated version of the software (now compatible with GNU Radio 3.7) is available from GitHub.

The software can use an RTL-SDR compatible DVB-T tuner as a signal source.
The signal is processed by GNU Radio, which performs FFT.
The FFT output is then sent to my python code using a Message Sink block.
The python program then plots the data using the python-matplotlib module.

The above plot shows the output when I transmit with my handheld radio on 2 meters band. Center is set to 145.000 MHz by default, but you can change it in the fft_test.grc file.

When I started out with Message Sink and Source blocks, this tutorial was quite useful. These blocks help you to communicate between your python code and GNU Radio block diagram. Basically, you can get the processed data from GNU Radio and use it in python, or do it in the other direction: you can generate some kind of data in python and send it to GNU Radio for processing.

I wouldn't suggest anyone to implement advanced DSP functionality in python, but it might be reasonable to:

  • implement a client application that displays the data,
  • implement a simple server that serves the data to clients,
  • implement "glue code" that serves the data to the next element of the processing chain (e.g. another shell program, a library function).

To run my example you would need:

  • Linux running GNU Radio (My GNU Radio version is exactly v3.6.2-227-gaeb7bbfd) - now compatible with GR 3.7.,
  • python-matplotlib installed.

You can edit the flowchart in GNU Radio Companion to suit your needs. Then you have to hit Generate (F5) in GRC, but note that when running my program, it will first change some lines in the the top_level.py before importing it (this is what grcconvert.py does). There are two problems with the code generated by GRC:

The first is, gr_message_sink_0_msgq_out is not a public member of the top_block class, nor it is initialized as it should be, so we have to add a line:
self.msgq_out = gr_message_sink_0_msgq_out = gr.msg_queue(2)
...to create a message queue that we can access from outside.

The second problem is the confusing grayed output of Message Sink. You have to connect it somewhere to have your top_block.py generated, but you don't need to use it for anything at all. You can't connect it to a Null Sink, as IO size does not match. At the end, I've connected it to a Pad block, but then I had to comment out the line corresponding to the Pad block in the top_block.

When executing fft_test.py, the grcconvert module solves both problems automatically by changing the corresponding lines, so you don't have to do it manually every time you generate a new flowgraph.

Download

The newest version of the project is available on GitHub.
However, you can also download the old version for GNU Radio 3.6.

You can start it by typing:
python fft_test.py

Comments

Üdv!
Telepítem a gnuradiot és arra panaszkodik, hogy nem jó a PYTHONPATH. Megtaláltam, hogy hol kell megadni, de egész pontosan mit kell neki megadni?
73&DX! HG8-654

Szia!

Alapvetően a build-gnuradio szkript használatát javaslom, akkor a legújabb verzió kerül fel mindenestül és valószínűleg nem lesznek vele ilyen problémáid. A fenti szkriptről itt találsz még tájékoztatást.

A fenti, $PYTHONPATH-tal kapcsolatos probléma állítólag az Ettus Research oldaláról letöltött binary-kkal fordul elő. (Te is onnan szerezted be?) Itt van némi segítség a környezeti változók helyes beállításához, de ehhez valószínű tudnod kell, hogy milyen könyvtár(ak)ban tárolja a Te disztribúciód a python modulokhoz tartozó fájlokat. A kérdésedre választ jelentő könyvtár útvonal megtalálásában lehet hogy segítene a locate dist-packages parancs, vagy esetleg cd /; find -name dist-packages. Ez nekem az alábbi eredményt adja:

---@---:/$ find -name dist-packages
./usr/lib/python2.7/dist-packages
./usr/lib/python2.6/dist-packages
./usr/lib/python3/dist-packages
./usr/lib/pypy/dist-packages
./usr/local/lib/python2.7/dist-packages
./usr/local/lib/python2.6/dist-packages
./usr/local/lib/python3.2/dist-packages (...)

Ezzel a problémával még nem találkoztam, remélem tudtam segíteni valamennyit.

Telepítés szempontjából amúgy a Debian/Ubuntu repository-kban lévő GNU Radio verziót sem javaslom, gyanús hogy nem fog menni azzal sem a fenti példaprogram, pl. az utolsó verzió amit onnan telepítettem Debian Testing alatt nem tartalmazta az RTL-SDR támogatást, igaz ez tavaly nyáron volt.

Summa summarum, én a build-gnuradio-t próbálnám ki először a helyedben.

Üdvözlettel:

Andris

Windows alatt vagyok. Sikerült megoldanom, csak fel kellett mindent rakni: http://code.ettus.com/redmine/ettus/projects/uhd/wiki/GNURadio_Windows
73&DX! HG8-654

Szia!

Hű, idáig nem is tudtam, hogy Windows alatt egyáltalán működik a cucc.
RTL-SDR blokkok is működnek Neked?

hi, i try to use msg sink but i have error " NameError: global name 'blocks_message_sink_0_msgq_out' is not defined ". i thing my problems is pad sink or version of my gnuradio (3.7.3). have you try this in gnuradio 3.7.3 ? how did you solve this problems. ( i follow the all step that's describe without succed ) can you help me please ?

I've updated the code for you to be compatible with GNU Radio 3.7. Hope that works now.

Also note that you have to run python fft_test.py rather than running the flowgraph from GNU Radio Companion.

thanks it's work with grc 3.7

Add new comment