WINLAB GNUradio Python Programming KC Huang. WINLAB Outlines  Python Introduction  Understanding & Using GNU Radio What is GNU Radio architecture? How.

Slides:



Advertisements
Similar presentations
Chapter 17 GNU Radio for Cognitive Radio Experimentation 1 1
Advertisements

1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
Overview and Basics of Software Defined Radios INSTRUCTOR: Dr. George Collins By Praveen Kumar Chukka
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
The Web Warrior Guide to Web Design Technologies
Binding python to other languages (Fortran and C).
1 Programming for Engineers in Python Autumn Lecture 5: Object Oriented Programming.
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Component Description Alice 3d Graphics Software Human Computer Interaction Institute Carnegie Mellon University Prepared by: Randy Pausch,
 2008 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
 2006 Pearson Education, Inc. All rights reserved Introduction to Classes and Objects.
1 Outline 7.1 Introduction 7.2 Implementing a Time Abstract Data Type with a Class 7.3 Special Attributes 7.4Controlling Access to Attributes 7.4.1Get.
Fundamentals of Python: From First Programs Through Data Structures
The Project AH Computing. Functional Requirements  What the product must do!  Examples attractive welcome screen all options available as clickable.
Python 3 Some material adapted from Upenn cis391 slides and other sources.
Java Methods By J. W. Rider. Java Methods Modularity Declaring methods –Header, signature, prototype Static Void Local variables –this Return Reentrancy.
Using Ant to build J2EE Applications Kumar
GANGA Release Strategy Documentation Tools GANGA Workshop, April 2004, CERN Chun Lik Tan (Alvin) - Birmingham GANGA Workshop,
The 6713 DSP Starter Kit (DSK) is a low-cost platform which lets customers evaluate and develop applications for the Texas Instruments C67X DSP family.
Instructor: Dr.George Collins Satyakiran Anugu. Introduction Why Mathematics in GNU Radio Creating block Pyhthon Mathematical operators in Python Mathematical.
LabVIEW an Introduction
Wireless LAN Technology Lecture 32. Wireless LAN Introduction The proliferation of laptop computers and other mobile devices (PDAs and cell phones) created.
Builtins, namespaces, functions. There are objects that are predefined in Python Python built-ins When you use something without defining it, it means.
17. Python Exceptions Handling Python provides two very important features to handle any unexpected error in your Python programs and to add debugging.
SAN DIEGO SUPERCOMPUTER CENTER Working with Inca Reporters Jim Hayes Inca Workshop September 4-5, 2008.
FINAL MPX DELIVERABLE Due when you schedule your interview and presentation.
CMSC 202 Exceptions. Aug 7, Error Handling In the ideal world, all errors would occur when your code is compiled. That won’t happen. Errors which.
Introduction to Python 2 Dr. Bernard Chen University of Central Arkansas PyArkansas 2011.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Chapter 06 (Part I) Functions and an Introduction to Recursion.
Python – Part 1 Python Programming Language 1. What is Python? High-level language Interpreted – easy to test and use interactively Object-oriented Open-source.
Garrett Vanhoy, MaryPat Beaufait, Duyun Chen Advisor: Dr. Carl Dietrich.
An Introduction to Python Blake Brogdon. What is Python?  Python is an interpreted, interactive, object-oriented programming language. (from python.org)
PC204 Lecture 9 Conrad Huang Genentech Hall, N453A x
Cohesion and Coupling CS 4311
FIRST JAVA PROGRAM. JAVA PROGRAMS Every program may consist of 1 or more classes. Syntax of a class: Each class can contain 1 or more methods. public.
Chapter 3 Functions, Events, and Control Structures JavaScript, Third Edition.
Object-Oriented Software Engineering Practical Software Development using UML and Java Chapter 8: Modelling Interactions and Behaviour UML Sequence Diagram.
C463 / B551 Artificial Intelligence Dana Vrajitoru Python.
Guide to Linux Installation and Administration, 2e1 Chapter 11 Using Advanced Administration Techniques.
CSCI/CMPE 4341 Topic: Programming in Python Review: Exam I Xiang Lian The University of Texas – Pan American Edinburg, TX 78539
CSC 110 Using Python [Reading: chapter 1] CSC 110 B 1.
Introduction to VHDL Simulation … Synthesis …. The digital design process… Initial specification Block diagram Final product Circuit equations Logic design.
CS105 Computer Programming PYTHON (based on CS 11 Python track: lecture 1, CALTECH)
Wireless Communications with GNU SDR. Writing a signal processing block As mentioned earlier, the signal.
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
DSP Techniques for Software Radio A System Example Dr. Jamil Ahmad.
Java 3: Odds & Ends Advanced Programming Techniques.
Introduction into JavaScript Java 1 JavaScript JavaScript programs run from within an HTML document The statements that make up a program in an HTML.
Jim Havrilla. Invoking Python Just type “python –m script.py [arg]” or “python –c command [arg]” To exit, quit() or Control-D is used To just use the.
Computer Simulation of Networks ECE/CSC 777: Telecommunications Network Design Fall, 2013, Rudra Dutta.
GNU Radio Jiewen Huang 1/31/ Outline  What is GNU Radio?  Basic Concepts  Developing Applications  HW2 Introduction.
LECTURE 2 Python Basics. MODULES So, we just put together our first real Python program. Let’s say we store this program in a file called fib.py. We have.
PROGRAMMING USING PYTHON LANGUAGE ASSIGNMENT 1. INSTALLATION OF RASPBERRY NOOB First prepare the SD card provided in the kit by loading an Operating System.
Bash Jerome Lewis Kelly Benson Andrew Kimble. Overview  Shell Language (UNIX based)  Paradigms – Command, Scripting  Has ability to read straight from.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Functions. What is a Function?  We have already used a few functions. Can you give some examples?  Some functions take a comma-separated list of arguments.
Introduction to Python for System Administrators Toshio Kuratomi May 2011.
Topics Introduction to Repetition Structures
Statement atoms The 'atomic' components of a statement are: delimiters (indents, semicolons, etc.); keywords (built into the language); identifiers (names.
Functions CIS 40 – Introduction to Programming in Python
CSCI 161: Introduction to Programming Function
Selection CIS 40 – Introduction to Programming in Python
Python Primer 2: Functions and Control Flow
Topics Introduction to File Input and Output
An Introduction to JavaScript
Topics Introduction to File Input and Output
CMSC 202 Exceptions.
Functions, Procedures, and Abstraction
Presentation transcript:

WINLAB GNUradio Python Programming KC Huang

WINLAB Outlines  Python Introduction  Understanding & Using GNU Radio What is GNU Radio architecture? How to program in GNUradio? (Python and C++) ‏  An example: dial-tone  Useful Resources

WINLAB Python - running  Why Python? Object-oriented Free Mixable (python/c++) ‏  Python scripts can be written in text files with the suffix.py Example:  $ python script.py  This will simply execute the script and return to the terminal afterwards

WINLAB Python - format  Module: a python file containing definitions and statements from pick_bitrate import pick_tx_bitrate (from file import function) ‏ from gnuradio import gr, (or *) (from package import subpackage or all) ‏ Some modules are built-in e.g. sys (import sys)  Indentation: it is Python’s way of grouping statements Example:  while b < 10: print b return  Body of loop has to be indented by the same amount to indicate statements of the loop

WINLAB Python – function & class (1) ‏  Function definitions have the following basic structure: def func(args): return values Regardless of the arguments, (including the case of no arguments) a function call must end with parentheses Example: def f1(x): return x*(x-1) f1(3) = 6

WINLAB Python – function & class (2) ‏  Classes class ClassName:...  Objects x = ClassName() creates a new instance of this class and assigns the object to the variable x Initial state: for instantiation and parameter pass def __init__(self):

WINLAB Python – function & class (3) ‏ class cs_mac(object): def __init__(self, tun_fd, verbose=False): self.tun_fd = tun_fd self.verbose = verbose self.fg = None def main_loop(self): min_delay = # seconds while 1: payload = os.read(self.tun_fd, 10*1024) if not payload: self.fg.send_pkt(eof=True) break if self.verbose: print "Tx: len(payload) = %4d" % (len(payload),) delay = min_delay while self.fg.carrier_sensed(): sys.stderr.write('B') time.sleep(delay) if delay < 0.050: delay = delay * 2 # exponential back-off self.fg.send_pkt(payload)

WINLAB GNUradio Architecture User-defined Code RF Front end Sender DACUSBFPGA mother board PC USRP daughter board  GNU radio has provided some useful APIs  What we are interested in at this time is how to use the existing modules that has been provided in GNU radio project to communicate between two end systems

WINLAB GNUradio Architecture - software  How these modules co-work?  Signal processing block and flow-graph  C++: Extensive library of signal processing blocks  Performance-critical modules  Python: Environment for composing blocks  Glue to connect modules  Non performance-critical modules  Signal Processing Block  Source: No input  noise_source, signal_source, usrp_source  Sink: No outputs  audio_alsa_sink,usrp_sink  Processing blocks: one or more inputs/outputs

WINLAB GNUradio Architecture – software(2) ‏ C++ V1 V2 V3 V1 V2 V3 Source Sink At python level, what we need to do is always just to draw a diagram showing the signal flow from the source to the sink in our mind.

WINLAB GNUradio Architecture – software(3) ‏ Python Application development Flow graph construction C++ Signal processing blocks  Python scripting language used for creating "signal flow graphs“  C++ used for creating signal processing blocks An already existing library of signaling blocks  The scheduler is using Python’s built-in module threading, to control the ‘starting’, ‘stopping’ or ‘waiting’ operations of the signal flow graph. Scheduler Control flow graph

WINLAB Dial Tone Example (1) ‏ from gnuradio import gr from gnuradio import audio from gnuradio.eng_option import eng_option from optparse import OptionParser Import modules from GNU Radio library 1. The import command is similar to the #include directive in C/C gr is the basic GNU Radio module #!/usr/bin/env python It tells the shell that this file is a Python file and to use the Python interpreter to run this file. Sine Generator (350Hz) ‏ Sine Generator (440Hz) ‏ Audio Sink

WINLAB Dial Tone Example (2) ‏ class my_top_block(gr.top_block): def __init__(self): gr.top_block.__init__(self)‏ The class called my_top_block is derived from another class, gr.top_block gr.top_block class maintains the graph and also provides all the functions to build and connect blocks Instantiating a flow graph object and the parent constructor is called

WINLAB Dial Tone Example (3) ‏ parser = OptionParser(option_class=eng_option)‏ parser.add_option("-O", "--audio-output", type="string", default="", help="pcm output device name. E.g., hw:0,0")‏ parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, help="set sample rate to RATE (48000)")‏ (options, args) = parser.parse_args ()‏ if len(args) != 0: parser.print_help()‏ raise SystemExit, 1 sample_rate = int(options.sample_rate)‏ ampl = 0.1 Define and parse command-line options Python dial_tone.py –r 50000

WINLAB Dial Tone Example (4) ‏ src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl)‏ src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl)‏ dst = audio.sink (sample_rate, options.audio_output)‏ self.connect (src0, (dst, 0))‏ self.connect (src1, (dst, 1))‏ Setting up sinewaves at 350 and 440 Hz and sampling rate by command-line Create signal generating blocks defining destination connecting source and destinations, left and right channel (it specifically connects src0 to port 0 of dst ) ‏

WINLAB Dial Tone Example (5) ‏ if __name__ == '__main__': try: my_top_block().run()‏ except KeyboardInterrupt: pass Run the flow graph when the program is executed

WINLAB GNUradio modules  from gnuradio import MODULENAME Miscellaneous utilities, mathematical and others.gru Use from gnuradio.eng_options import eng_options to import this feature. This module extends Pythons optparse module to understand engineering notation (see above). eng_opt ion s Adds some functions to deals with numbers in engineering notation such as `100M' for 100 * 10 6'. eng_not ati on This module contains additional blocks written in Python which include often-used tasks like modulators and demodulators, some extra filter code, resamplers, squelch and so on. blks2 Soundcard controls (sources, sinks). You can use this to send or receive audio to the sound cards, but you can also use your sound card as a narrow band receiver with an external RF frontend. audio USRP sources and sinks and controls.usrp The main GNU Radio library. You will nearly always need this.gr

WINLAB GNUradio scheduler Unlock a flow graph in preparation for reconfiguration. When an equal number of calls to lock() and unlock() have occurred, the flow graph will be restarted automatically. unlock () Lock a flow graph in preparation for reconfiguration. lock() Wait for a flow graph to complete. Flowgraphs complete when either (1) all blocks indicate that they are done, or (2) after stop has been called to request shutdown. wait() Stop the running flow graph. Notifies each thread created by the scheduler to shutdown, then returns to caller. stop() Start the contained flow graph. Returns to the caller once the threads are created. start() The simplest way to run a flow graph. Calls start(), then wait(). Used to run a flow graph that will stop on its own, or to run a flow graph indefinitely until SIGINT is received. run()

WINLAB Creating Your Own Signal Block  Basics  A block is a C++ class  Typically derived from gr_block or gr_sync_block class  Three components  my_block_xx.h : Block definition  my_block_xx.cc : Block implementation  my_block_xx.i : Python bindings (SWIG interface) (SWIG, a tool that generates wrapper code around your C++ functions and classes, so that they are callable from Python) ‏

WINLAB Useful Resource  GNUradio:  Homepage (download, more links, etc) ‏   More comprehensive tutorial   Available Signal Processing Blocks   GNU Radio Mailing List Archives   CGRAN: 3 rd Party GNU Radio Apps   Python: - online version of built-in Python function documentation - Python Quick Reference Card - long version of Python Quick Reference Card - extensive Python forum