The solution to these problems is using pythons built

Info icon This preview shows pages 13–14. Sign up to view the full content.

View Full Document Right Arrow Icon
of the low-level C++ details are hidden at the Python level. The solution to these problems is using Python’s built-in documentation-browsing mechanisms. Read the “Browsing Documentation with Python” section of the Quick Reference sheet for more information on navigating the documentation from the Python interpreter shell. 3.3 Creating Custom Blocks in GRC This section explains how to create custom signal processing blocks using Python. Unlike the “custom” hierarchical blocks you created in the previous lab, which merely contained other GNU Radio blocks wired together, this section will explain how to process the actual data samples in Python code. We would ideally write custom signal processing blocks in C++ for fastest performance. However, writing blocks in C++ is somewhat complicated (involves writing C++ code, SWIG wrappers, modi- fying Makefiles, recompiling, etc.) and is beyond the scope of this course. Fortunately, writing custom blocks in Python is not too difficult and Python works fine for tasks that are not too computationally demanding. You should try to use the stock GNU Radio blocks wherever possible, but sometimes these blocks are not flexible enough to do what you want. For example, suppose that your task is to find the frequency of the peak in an FFT. At first, this sounds easy: simply direct the output of the FFT block into the “Argmax” block to find the index of the peak. However, the “Argmax” block finds the maximum across its input ports, not across the samples in an input vector; for a 1024-point FFT, you would need to multiplex the vector into 1024 signal lines and connect these to 1024 input ports on the “Argmax” block! Realizing that the “Argmax” block is not what we want, we next consider GNU Radio’s “Peak Detector” block. This block looks promising at first, until we realize that it is for detecting time-domain peaks in a stream of samples. Conclusion: we will need to write a custom block to achieve our goal. All you need to create a custom Python GNU Radio block is a single Python file. If you want to import your custom block into GRC, you will also need to create an XML file that specifies the ports and parameters of the block. In case you have never heard of XML before, it stands for “Extensible Markup Language.” It is a tag-based format for storing data in plain text and it looks a lot like HTML. GRC parses XML files in order to determine the ports and parameters for each block. Fortunately, XML files for GRC are fairly straightforward and you can use the XML files for the stock GNU Radio blocks as templates. The XML files for the stock GNU Radio blocks are located in the directory /opt/gnuradio/grc/blocks/ ; take a look at some of them to get a sense of the types of information they contain. To get you started with creating custom Python blocks, we have provided sample Python and XML code on the course website. The code demonstrates a custom block to solve the problem introduced above: finding the frequency of the peak in an FFT.
Image of page 13

Info icon This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 14
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern