How to write Pythongnuradio applications

Source: Internet
Author: User

Three basic concepts:

Flow graph

A large part of the Gnuradio program is a flow graph. The flow graph includes several signal processing modules (blocks) and some edges that represent data flows.

BLock

All signal processing takes place in block. In the best case, each block contains only one function, which makes the Gnuradio program more flexible.

Block is written by C + + and is said to be difficult.

Data

The data passed between blocks can be any data in C + +, in fact, most data types are complex numbers, short real numbers, long integers, floating-point numbers, and so on. The data passed can be either a bit or a sample.

Summary of Flow graphs:

All signal processing in the Gnuradio is through the flow graph

A flow graph consists of several modules, each of which performs an operation such as filtering, signal stacking, changing, decoding, connecting to hardware, and so on.

Signals are passed between modules in a variety of ways, plural or real, floating-point numbers, or other data types that we define.

Python

Each flow graph requires at least one beacon and signal source.

Example of a flow graph in Python.

The location of the code is: gr-audio/examples/python/dial_tone.py.

1 #!/usr/bin/env python2 3  fromGnuradioImportGR4  fromGnuradioImportAudio, Analog5 6 classMy_top_block (gr.top_block):7     def __init__(self):8Gr.top_block.__init__(self)9 TenSample_rate = 32000 OneAmpl = 0.1 A  -SRC0 = Analog.sig_source_f (sample_rate, Analog. Gr_sin_wave, 350, Ampl) -Src1 = Analog.sig_source_f (sample_rate, Analog. Gr_sin_wave, 440, Ampl) theDST = Audio.sink (Sample_rate,"") - Self.connect (SRC0, (DST, 0)) -Self.connect (Src1, (DST, 1)) -  + if __name__=='__main__': -     Try: + My_top_block (). Run () A     except[[Keyboardinterrupt]]: at         Pass

Line 1: Tell the operating system this is a python file that needs to be run using the Python interpreter. This line is required if you want to run the program directly on the command line.

Line 3,LIN4: Import the required modules to run the Gnuradio. Its role and the #include很想 in C language.

The GR module is the most basic Gnuradio module. Each time you run the Gnuradio program, you need to import this module. Audio module, sound device module

Analog, functions and modules related to analog signals.

Line 6-17 defines a class that inherits from Gr.top_block, a class that can be thought of as a container for the flow graph. The methods that inherit from Gr.top_block can make it easy for us to add and link modules.

We notice that the class contains only an initialization function that is used to create the class. In the first line of the initialization function Line8, the parent class

The initialization function is called. Many of the similar operations in Python require a call to be displayed.

Next line10-11 defines two variables to control the sampling frequency and signal amplitude.

Line 13-15 defines 3 blocks, the source Src0,src1 and the heartbeat DST.

The floating-point number that was called when the signal source was created analog.sig_source_f(sample_rate, analog.GR_SIN_WAVE, frequency,ampl)函数,而创建信宿则调用了 audio.sink中的模块。 值得主要的是audio.sink 只接受幅度为-1到+1 , and we should pay attention to its range when writing the program. If the input signal is cosmetic, Gnuradio will error, but if the input amplitude is greater than 1, there will be no error, but we will get a wrong result.

Line 16-17 is responsible for connecting the various modules.

The last 5 lines are responsible for starting the module.

Python Build Flow Graph Summary:

1. At the very beginning, import some gnuradio modules, where GR is usually required.

2. The flow graph is stored in a class with Gr.top_block as the parent class.

3. When creating a module, a function is typically called

4. Block connects by calling Self.connect () inside the Flow graph class

How to write Pythongnuradio applications

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.