Mark Wickert
Mark Wickert
https://www.youtube.com/watch?v=xWREmn7EajM
Abstract—This paper will take the audience through the story of how an elec- The next phase of the journey, focuses on the research and
trical and computer engineering faculty member has come to embrace Python, development side of signals and systems work. During a recent
in particular IPython Notebook (IPython kernel for Jupyter), as an analysis and sabbatical1 Python and IPython notebook (IPython kernel for
simulation tool for both teaching and research in signal processing and com- Jupyter) served as the primary digital signal processing modeling
munications. Legacy tools such as MATLAB are well established (entrenched)
tools on three different projects. Initially it was not clear which
in this discipline, but engineers need to be aware of alternatives, especially in
the case of Python where there is such a vibrant community of developers.
tool would be best, but following discussions with co-workers2
In this paper case studies will also be used to describe domain specific code Python seemed to be the right choice. Note, for the most part,
modules that are being developed to support both lecture and lab oriented the analysis team was new to Python, all of us having spent
courses going through the conversion from MATLAB to Python. These modules many years using MATLAB/Octave [MATLAB]/[Octave]. A nice
in particular augment scipy.signal in a very positive way and enable rapid motivating factor is that Python is already in the workflow in the
prototyping of communications and signal processing algorithms. Both student real-time DSP platform used by the company.
and industry team members in subcontract work, have responded favorably to The third and current phase of the Python transformation
the use of Python as an engineering problem solving platform. In teaching,
began at the start of the 2014-2015 academic year. The move
IPython notebooks are used to augment lecture material with live calculations
was made to push out Python to the students, via the IPython
and simulations. These same notebooks are then placed on the course Web Site
so students can download and tinker on their own. This activity also encourages
Notebook, in five courses: digital signal processing, digital com-
learning more about the language core and Numpy, relative to MATLAB. The stu- munications, analog communications, statistical signal processing,
dents quickly mature and are able to turn in homework solutions and complete and real-time signal processing. Four of the courses are traditional
computer simulation projects, all in the notebook. Rendering notebooks to PDF lecture format, while the fifth is very hands-on lab oriented, involv-
via LaTeX is also quite popular. The next step is to get other signals and systems ing embedded systems programming and hardware interfacing.
faculty involved. IPython Notebook works very well for writing lab reports, and
easily allows theoretical and experimental results to be integrated.
Index Terms—numerical computing, signal processing, communications sys-
A notebook interface is not a new concept in scientific computing
tems, system modeling
tool sets3 . Both of these tools are very powerful for specific
problem classes.
Introduction The remainder of this paper is organized into the follow-
ing sections: arriving at Python for communications and signal
This journey into Python for electrical engineering problem solv-
processing modeling, describing IPython notebook usage, case
ing began with the writing of the book Signals and Systems for
studies, and conclusions.
Dummies [Wic2013], published summer 2013. This book features
the use of Python (Pylab) to bring life to the mathematics
behind signals and systems theory. Using Python in the Dummies Arriving at Python for Communications and Signal Processing
book is done to make it easy for all readers of the book to Modeling
develop their signals and system problem solving skills, without About three years ago while working on a study contract for
additional software tools investment. Additionally, the provided a small business, I started investigating the use of open-source
custom code module ssd.py [ssd], which is built on top of alternatives over MATLAB. I initially homed in on using Octave
numpy, matplotlib, and scipy.signal, makes it easy to [Octave] for its syntax compatibility with MATLAB. Later I
work and extend the examples found in the book. Engineers love started to explore Python and became fascinated by the ease of
to visualize their work with plots of various types. All of the plots use offered by the IPython (QT) console and the high quality
in the book are created using Python, specifically matplotlib. of matplotlib 2D plots. The full power of Python/IPython
* Corresponding author: [email protected] 1. Academic year 2013-2014 was spent working for a small engineering
‡ University of Colorado Colorado Springs
firm, Cosmic AES.
Copyright © 2015 Mark Wickert. This is an open-access article distributed 2. Also holding the Ph.D. and/or MS in Electrical Engineering, with empha-
under the terms of the Creative Commons Attribution License, which permits sis in communications and signal processing.
unrestricted use, distribution, and reproduction in any medium, provided the 3. See for example Mathematica [Mathematica] (commercial) and wxMax-
original author and source are credited. ima [Maxima] (open source).
106 PROC. OF THE 14th PYTHON IN SCIENCE CONF. (SCIPY 2015)
for engineering and scientific computing gradually took hold as 1/2 convolutional code each source bit is encoded into two channel
I learned more about the language and the engineering problem bits using a shift register of length K (termed constraint length)
capabilities offered by pylab. with excusive or logic gate connections. The class allows arbitrary
When I took on the assignment of writing the Signals and constraint length codes and allows puncturing and depuncturing
Systems for Dummies book [Wic2013] Python seemed like a good patterns. With pucturing/depuncturing certain code bits are erased,
choice because of the relative ease with which anyone could obtain that is not sent, so as to increase the code rate from 1/2 to say 3/4
the tools and then get hands-on experience with the numerical (4 channel bits for every three source bits).
examples I was writing into the book. The power of numpy For decoding the class implements the Viterbi algorithm (VA),
and the algorithms available in scipy are very useful in this which is a dynamic programming algorithm. The most likely path
discipline, but I immediately recognized that enhancements to the received signal takes through a trellis structure is how the
scipy.signal are needed to make signals and systems tinker- VA recovers the sent bits [Zie2015]. Here the cost of traversing a
ing user friendly. As examples were written for the book, I began particular trellis branch is established using soft decision metrics,
to write support functions that fill in some of the missing details where soft decision refers to how information in the demodulated
not found in scipy. This is the basis for the module ssd.py, a radio signal is converted metric values.
constant work in progress to make open source signals and systems The class contains seven methods that include two graphical
software more accessible to the engineering community. display functions, one of which shows the survivor traceback
paths through the trellis back in time by the decoder decision
Modules Developed or Under Development depth. The traceback paths, one for each of the 2K−1 trellis states,
As already briefly mentioned, the first code module I developed give students insight into the operation of the VA. Besides the
is ssd.py4 . This module contains 61 functions supporting signal class, fec_conv also contains four functions for computing error
generation, manipulation, and display, and system generation and probability bounds using the weight structure of the code under
characterization. Some of the functions implement subsystems both hard and soft branch metric distance calculations [Zie2015].
such as a ten band audio equalization filter or the model of an A fourth module, synchronization.py, was developed
automobile cruise control system. A pair of wrapper functions while teaching a phase-locked loops course, Summer 2014. Syn-
to_wav() and from_wav() make it easy for students to write chronization is extremely important is all modern communications
and read 1D ndarrays from a wave file. Specialized plotting communications schemes. Digital communication systems fail
functions are present to make it easy to visualize both signals and to get data bits through a wireless link when synchronization
systems. The collection of functions provides general support for fails. This module supplies eight simulation functions ranging
both continuous and discrete-time signals and systems, as well from a basic phase-locked loop and both carrier and symbol
as specific support for examples found in [Wic2013]. Most all synchronization functions for digital communications waveforms.
of functions are geared toward undergraduate education. More This module is also utilized in an analog communications course
modules have followed since then. taught Spring 2015.
The second module developed, digitalcom.py, focuses
on the special needs of digital communications, both modulation Describing IPython Notebook Use Scenarios
and demodulation. At present this module contains 32 functions.
In this section I describe how Python, and in particular the IPython
These functions are focused on waveform level simulation of con-
notebook, has been integrated into teaching, graduate student
temporary digital communication systems. When I say simulation
research, and industry research and development.
I specifically mean Monte Carlo techniques which involve the use
of random bit streams, noise, channel fading, and interference.
Teaching
Knowledge of digital signal processing techniques plays a key
role in implementation of these systems. The functions in this To put things into context, the present lecturing style for all
module are a combination of communcation waveform generators courses I teach involves the use of a tablet PC, a data projector, a
and specialized signal processing building blocks, such as the microphone, and audio/video screen capture software. Live Python
upsampler and downsampler, which allow the sampling rate of demos are run in the notebook, and in many cases all the code
a signal to be raised or lowered, respectively. More functions is developed in real-time as questions come from the class. The
are under development for this module, particularly in the area notebook is more than just a visual experience. A case in point is
of orthogonal frequency division multiplexing (OFDM), the key the notebook audio control which adds sound playback capability.
modulation type found in the wireless telephony standard, long A 1D ndarray can be saved as a wave file for playback. Simply
term evolution (LTE). put, signals do make sounds and the action of systems changes
A third module, fec_conv.py, implements a rate 1/2 con- what can be heard. Students enjoy hearing as well as seeing
volutional encoding and decoding class [Zie2015]. In digital com- results. By interfacing the tablet lineout or headphone output to
munications digital information in the form of bits are sent from the podium interface to the classroom speakers, everyone can
the transmitter to the receiver. The transmission channel might hear the impact of algorithm tweaks on what is being heard.
be wired or wireless, and the signal carrying the bits may be at This is where the fun starts! The modules scipy.signal
baseband, as in say Ethernet, or bandpass on a carrier frequency, and ssd.py, described earlier, are imported at the top of each
as in WiFi. To error protect bits sent over the channel forward notebook.
error correction (FEC) coding, such as convolutional codes, may For each new chapter of lecture material I present on the tablet
be employed. Encoding is applied before the source bits are mod- PC, a new IPython notebook is created to hold corresponding
ulated onto the carrier to form the transmitted signal. With a rate numerical analysis and simulation demos. When appropriate,
starter content is added to the notebook before the lecture. For
4. http://www.eas.uccs.edu/wickert/SSD/docs/python/ example I can provide relevant theory right in the notebook to
SIGNAL PROCESSING AND COMMUNICATIONS: TEACHING AND RESEARCH USING IPYTHON NOTEBOOK 107
transition between the lecture notes mathematics and the notebook In this second case the code is moved to a production environment
demos. Specifically, text and mathematics are placed in markdown and recoding to say C/C++. It might also be that the original
cells. The notebook theory is however very brief compared to Python model is simply an abstraction of real electronic hardware,
that of the course lecture notes. Preparing this content is easy, in which case a hardware implementer uses the notebook (maybe
since the lecture notes are written in LaTeX I drop the selected just a PDF version) to create a hardware prototype, e.g., a field
equations right into mark down cells will minimal rework. Sample programable gate array (FPGA) or custom integrated circuit.
calculations and simulations, with corresponding plots, are often
generated in advance, but the intent is to make parameter changes Live From the Classroom
during the lecture, so the students can get a feel for how a Here live from the classroom means responding to questions
particular math model relates to real-word communications and using on-the-fly IPython notebook demos. This is an excellent
signal processing systems. way to show off the power of Python. Sometimes questions
Computer projects benefit greatly from the use of the note- come and you feel like building a quick model right then and
book, as sample notebooks with starter code are easily posted to there during a lecture. When successful, this hopefully locks in a
the course Web Site. The sample notebook serves as a template for solid understanding of the concepts involved for the whole class.
the project report document that the student will ultimately turn in The fact that the lecture is being recorded means that students
for grading. The ability to convert the notebook to a LaTeX PDF can recreate the same demo at their leisure when they watch
document works for many students. Others used screenshots of the lecture video. The notebook is also saved and posted as a
selected notebook cells and pasted them into a word processor supplement/companion to the lecture. As mentioned earlier, there
document. In Spring 2015 semester students turned in printed is a corresponding notebook for each chapter of lecture material5 .
copies of the notebook and as backup, supplied also the notebook I set the goal of re-posting the chapter notebooks each time a new
file. Marking on real paper documents is still my preference. lecture video is posted. This way the students have something to
play with as they work on the current homework assignment.
Graduate Student Research
In working with graduate students on their research, it is normal to
exchange code developed by fellow graduate students working on Case Studies
related problems. Background discussions, code implementations In this section I present case studies that present the details on
of algorithms, and worked examples form a perfect use case for one or more of the IPython notebook use cases described in the
IPython notebook. The same approach holds for faculty interaction previous section of this paper. Case studies from industry R&D
with their graduate students. In this scenario the faculty member, are not included here due to the propriety nature of the work.
who is typically short on free time, gains a powerful advantage in In all of the case studies you see that graphical results are
that more than one student may need to brought up to speed on the produced using the pylab interface to matplotlib. This is
same code base. Once the notebook is developed it is shared with done purposefully for two reasons. The first stems from the fact
one or more students and often demoed in front the student(s) on that currently all students have received exposure to MATLAB in
a lab or office computer. The ability to include figures means that a prior course, and secondly, I wish to augment, and not replace,
system block diagrams can also be placed in the notebook. the students’ MATLAB knowledge since industry is still lagging
As the student makes progress on a research task they docu- when it comes to using open source tools.
ment their work in a notebook. Faculty member(s) are briefed on
the math models and simulation results. Since the notebook is live, Digital Signal Processing
hypothetical questions can be quickly tested and answered.
As a simple starting point this first case study deals with the
Industry Research and Development mathematical representation of signals. A step function sequence
With the notebook engineers working on the same team are able u[n] is defined as
to share analytical models and development approaches using
(
1, n ≥ 0
markdown cells. The inclusion of LaTeX markup is a welcome u[n] = (1)
addition and furthers the establishment of notational conventions, 0, otherwise
during the development of signal processing algorithms. Here I consider the difference between two step sequences starting
Later, prototype algorithm development is started using code at n = 0 and the other starting at n = 5. I thus construct in Python
cells. Initially, computer synthesized signals (waveforms) are used
to validated the core functionality of an algorithm. Next, signal x3 [n] = x1 [n] − x2 [n] = u[n] − u[n − 5], (2)
captures (date files) from the actual real-time hardware are used
as a source of test vectors to verify that performance metrics are which forms a pulse sequence that turns on at n = 0 and turns off
being achieved. Notebooks can again be passed around to team at n = 5. A screen capture from the IPython notebook is shown in
members for further algorithm testing. Soon code cell functions Fig. 1.
can be moved to code modules and the code modules distributed Of special note in this case study is how the code syntax for
to team members via git [git] or some other distributed revi- the generation of the sequences follows closely the mathematical
sion control system. At every step of the way matplotlib form. Note to save space the details of plotting x2 [n] and x3 [n] are
[matpltlib] graphics are used to visualize performance of a par- omitted, but the code that generates and plots x3 [n] is simply:
ticular algorithm, versus say a performance bound. stem(n,x1 - x2)
Complete subsystem testing at the Python level is the final step
for pure Python implementations. When Python is used to con- 5. Notebook postings for each course at http://www.eas.uccs.
struct a behavioral level model, then more testing will be required. edu/wickert/
108 PROC. OF THE 14th PYTHON IN SCIENCE CONF. (SCIPY 2015)
t t
0 T 0
increasing t
h(λ)
x(t – λ) Integrand of Convolution Integral
λ
t–T t 0
u[n – 5]
u[n] – u[n – 5]
x(t) h( t ) y(t)
LTI System
Fig. 2: Simple one input one output LTI system block diagram.
Fig. 4: Solving the convolution integral in the notebook .
In mathematical terms the output y(t) is the integral
Z ∞
y(t) = h(λ )x(t − λ ) dλ (3) To bring closure to the tedious analytical solution develop-
−∞ ment, I encourage students check their work using computer
Students frequently have problems setting up and evaluating the simulation. The function ssd.conv_integral() performs
convolution integral, yet it is an important concept to learn. The numerical evaluation of the convolution integral for both finite
waveforms of interest are typically piecewise continuous, so the and semi-infinite extent limits. I simply need to provide an array of
integral must be evaluated over one or more contiguous intervals. signal/impulse response sample values over the complete support
Consider the case of x(t) = u(t) − u(t − T ), where u(t) is the unit interval. The screen capture of Fig. 5 shows how this is done
step function, and h(t) = ae−at u(t), where a > 0. To avoid careless in a notebook. Parameter variation is also explored. Seeing the
errors I start with a sketch of the integrand h(λ )x(t − λ ), as shown two approaches provide the same numerical values is rewarding
in Fig. 3. From there I can discover the support intervals or cases and a powerful testimony to how the IPython notebook improves
for evaluating the integral. learning and understanding.
SIGNAL PROCESSING AND COMMUNICATIONS: TEACHING AND RESEARCH USING IPYTHON NOTEBOOK 109
Fig. 10. Note also there are 77 poles at z = 0, which is expected Notebook Screen Capture