DSPRelated.com
Forums

Learning DSP with Python

Started by stephaneb 8 years ago8 replieslatest reply 8 years ago10389 views

Anyone here using #Python for their DSP work? I know @jms_nh (Aventures in Signal Processing with Python), @tpuolivali,  @cfelton (many posts) and @AllenDowney (Think DSP) are using Python.  Who else?

This thread is an experiment to see if we can use the new forum interface to come up with some useful general DSP content for the community.

Basically, you are invited to share any insight you may have related to the subject of the thread.  In this case "Learning DSP with Python".  Your contribution doesn't have to be long or complicated.  A short Python snippet to help understand a DSP concept for instance, or maybe a Python trick that you find useful and would like to share.  

This might not be the most exciting thread to participate in - but please see this as a warm up exercise to experiment with the new forum.

The hope is that many will participate so that the combination of several little insights and code snippets will make the thread a goto place for people who are currently learning DSP and/or Python.

Make sure to click on the 'thumbsup' button (), located to the left of every post, for the contributions that you like the most.  The forum system will automatically put at the top the posts that received the most number of thumbsups.

If your contribution includes a code snippet, don't forget to highlight the snippet by:

  1. Selecting it
  2. Clicking on the 'formatting' button ()
  3. Selecting 'Code'

Also don't forget that you can easily attach a file or add an image to your post by drag & dropping them in the editor. 

If you want to include some equations to your post, Mathjax is supported (tutorial here) by this forum. 

If this thread ends up being a success with lots of contributions and great content, I will make sure to promote it by email to DSPRelated's 60k+ subscribers.

Finally, let's award some of our beers (click on the beer button) to our favourite posts and participants, making sure to encourage them to contribute often!  

Thank you! #FAQ

[ - ]
Reply by cfeltonApril 8, 2016

I can provide a little feedback on my experience.  Personally, I have found Python to be a great tool for signal processing (DSP) design and analysis.  It should be noted that we are discussing using Python similar to the Matlab, Scilab, Mathematica, etc. and not for real-time DSP implementation (e.g. programming a DSP processor).

For me, Python is a powerful generic programming language that has become very popular with scientist and engineers.  My personal opinion, the popularity in these domains is because it is a high-level programming language and the language designers have done a great job.  In many ways, Python allows me to focus on the task at hand and less on the programming.  I can use Python for many programming tasks not just multiplying matrices.

Two books that specifically use Python and signal processing: 

  1. Think DSP by Allen Downey (already mentioned in the OP)
  2. Signal and systems for dummies by Mark Wickert (discloser Dr. Wickert was my advisor)

Most of functions DSP folks are familiar with are available in two Python packages: `numpy` and `scipy.signal`.  



[ - ]
Reply by jms_nhApril 8, 2016
my quick 2c:


- scipy.signal (along with numpy for low-level numerics and matplotlib for plotting) is a must for doing signal processing in Python (lti, lsim, lsim2, step, and step2 are the ones I've used most often.) I used it in my Padé article quite extensively.

- The python-control library https://github.com/python-control/python-control may be of interest also

[ - ]
Reply by AllenDowneyApril 8, 2016

@stephaneb Thanks for mentioning Think DSP!  

Everyone else: You can download the PDF or read it online at http://think-dsp.com

Think DSP is in technical review now and will be published in July.  So if you get a chance to look at it in the next few weeks, comments and corrections are particularly welcome.  (They will still be welcome after that, but harder to fix).

[ - ]
Reply by JOSApril 8, 2016

I still use Octave and Matlab for high-level analysis scripting, but I contributed to a free online course that uses Python for its audio signal processing examples:

https://www.coursera.org/course/audio

I found the Python onboarding to be helpful and effective.

- Julius

[ - ]
Reply by drlidsApril 8, 2016

I've used Xavier Serra's sms-tools, available at https://github.com/MTG/sms-tools

It's a bit clunky, but interesting. I used it for his Coursera MOOC, Audio Signal Processing for Music Applications, which is a great course.

There's also a fork of sms-tools that has been optimized, at https://github.com/bzamecnik/sms-tools


[ - ]
Reply by cfeltonApril 8, 2016
[ - ]
Reply by macsdevApril 8, 2016

Apart from the other things that have been mentioned before, I also like Python Data Analysis Library (pandas). Reading data in from files is a breeze with pandas. For example, say you have a large CSV file with multiple columns (with first row being labels for your columns). Let us your columns are named column1, column2 etc.,These are a few things you can do:

import pandas as pd
df = pd.read_csv(fileName.csv, index_col=False)
column1 = df['column1']
column2_unique = df['column2'].unique()
# Filtering
filter = df['column3'] == 50
column3_50 = df[filter]['column3']
# Check if you have a field
if('column4' in df):  
  print "column4 exists"




[ - ]
Reply by cfeltonApril 8, 2016

@macsdev, I agree pandas is a very useful package.  I don't know if it is just me or if it is a general trend that data folks seem to use column-data whereas signal folks use row-data.