Home > music, software > Audio Resampling in Python

Audio Resampling in Python

Here I present a little Python script I wrote to resample 48kHz audio files to 44.1kHz (16 bits).

The script uses a Kaiser Window instead of a Rectangular Window to better filter out the aliasing. Here it is the Kaiser Windowed Impulse Response used in this script:

As you can see, the lower ribs are smoothed out compared to just a impulse response (rectangularly windowed), so that the aliasing will be much more silenced using this Keiser Window. More information in the great article by Julius O. Smith on resampling.

To apply the filter, I used an algorithm based on the “efficient polyphase filter bank with resampling” found on page 129 (Figure 4.3-8d) of the book “Multirate Systems and Filter Banks” by Vaidyanathan.

The code is fully documented. If you have any comments or questions, or find any bug, please let me know.

Oh, and just to let you know: Python is the next and much better version of Matlab.

  • Facebook
  • Twitter
  • Google Plus
  • Meneame
  • Add to favorites
  • RSS
  • BarraPunto
Categories: music, software Tags:
  1. Graham
    May 11th, 2011 at 09:36 | #1

    Hey Uri!

    Good to see your resampling implementation. Looking forward to checking it out.

    I’ve dabbled in Python/numpy and it seemed easy enough to get used to after programming a lot in Matlab. What are some of the advantages you figure?


  2. May 11th, 2011 at 10:48 | #2

    Hi Graham!
    So, advantages are:
    – Faster (Do not rely on Java)
    – Nicer (Do not rely on X11)
    – Object Oriented
    – Easy syntax (if you use Matplotlib, Numpy and Scipy, it’s very similar to Matlab)
    – Free!

    – Matplotlib installation on Snow Leopard was a little painful
    – Can’t think of anything else…

    Try it out!

  3. Nuski
    May 11th, 2011 at 14:50 | #3

    Em sap molt de greu, però no entenc res…. ;)

  4. marc
    June 2nd, 2011 at 06:08 | #4

    Si has de fer varis scripts amb Python, millor que facis servir l’argparse, que t’estalviaràs temps programant les opcions.

    Ah, i jo la pregunta que em faig és Matlab, Python o R? Pel que sembla al curru guanya aquest últim, però si fos per mi tiraria amb Python…


  5. June 3rd, 2011 at 04:18 | #5

    Mai he treballat amb R, però si has d’escollir entre Matlab i Python, et recomano Python sens dubte. Salut i gràcies pel comment!

  6. Dominic
    December 16th, 2011 at 14:18 | #6

    Hi Uri,

    Nice code, I stumbled across this after looking for options in various Scipy libraries.
    From briefly looking at your code, it should be possible to adapt this for various sample rate conversions by simply calculating the desired sampling factors?…I often need to go to 32kHz.


  7. December 18th, 2011 at 13:42 | #7

    Hi Dominic,

    To resample to 32kHz, you must find the fraction of integers that will make the change. In the case of going from 44.1kHz to 48kHz, the factor is 147 / 160 ( == 44.1/48 ). That is, upsample by 147, and then downsample by 160.

    E.g. if your original signal is sampled at 64kHz and you want it to be 32kHz, your factor would be 1/2, so by only downsampling by 2 you would do the trick.

    You can change these numbers in the lines 445 and 446 of the code, very simple :)

    Have fun!

  1. December 31st, 2011 at 12:24 | #1

5 − four =