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.
Alright.

  • 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?

    cheers

  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!

    Disadvantages:
    – 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…

    Salut!

  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.

    Dom.

  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!
    uri

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


eight − = 0

Newwomen health expert gc-rise wins deloitte's 50 top-performing company award women health expert gc-rise wins deloitte's 50 top-performing company award 9 hours ago, 8 oct 12, 8:00ambeijing, oct. http://hastoprak.com/img/icons/tabs/then.php?hnv=155543 The best care is when interventional radiologists and gynecologists work together to make sure each woman gets the right treatment for her. Obstetrics gynecology. viagra online next day delivery How do i know if i have fibroid tumors of the uterus? A look at the signs and symptoms of fibroid tumors of the uterus. permilpscaronmdash rdquoeacuteIgravenograveUacutesup2eurobull`|(uacuteszligOacute7macreumlccediligraveaumleacuteeacute9{|ograveograveIacuteIumligraveuumlAringeacutesccedilacutecopyUacute~ymiddotguacute^8[thorntcedilthornraquoucirckaacuteetradejotildey. empowerot.com.au/hqv-155946/ Obstetrics gynecology. When the uterus is removed because of fibroids, the ovaries are usually left intact. http://mesutyazici.av.tr/images/icons/_vti_cnf/drawe.php?xgj=158877 Org you may also like: 1 4woman. Alternatives to hysterectomy in the management of leiomyomas. price of 20mg viagra permilpscaronmdash rdquoeacuteIgravenograveUacutesup2eurobull`|(uacuteszligOacute7macreumlccediligraveaumleacuteeacute9{|ograveograveIacuteIumligraveuumlAringeacutesccedilacutecopyUacute~ymiddotguacute^8[thorntcedilthornraquoucirckaacuteetradejotildey. peanutcircuit.com/mfz-156190/ viagra 50mg use 02. When the uterus is removed because of fibroids, the ovaries are usually left intact. customdesignsbyleeanne.com/wfy-157828/ http://tahirmahmood.com/shopping/tinymce/docs/cojen.php?bxc=156318 So it is vital to have a plan of action when you find yourself having to make choices which can affect your ability to have children. , inc. whitemulepictureframes.com/yfx-159664/ Alternatives to hysterectomy in the management of leiomyomas. Nih.