Downsampling and applying a lowpass filter to digital audio

后端 未结 10 834
北恋
北恋 2021-02-02 17:41

I\'ve got a 44Khz audio stream from a CD, represented as an array of 16 bit PCM samples. I\'d like to cut it down to an 11KHz stream. How do I do that? From my days of engine

相关标签:
10条回答
  • 2021-02-02 17:57

    Notice (in additions to the other comments) that the simple-easy-intuitive approach "downsample by a factor of 4 by replacing each group of 4 consecutive samples by the average value", is not optimal but is nevertheless not wrong, nor practically nor conceptually. Because the averaging amounts precisely to a low pass filter (a rectangular window, which corresponds to a sinc in frequency). What would be conceptually wrong is to just downsample by taking one of each 4 samples: that would definitely introduce aliasing.

    By the way: practically any software that does some resampling (audio, image or whatever; example for the audio case: sox) takes this into account, and frequently lets you choose the underlying low-pass filter.

    0 讨论(0)
  • 2021-02-02 17:57

    I recently came across BruteFIR which may already do some of what you're interested in?

    0 讨论(0)
  • 2021-02-02 18:02

    You have to apply low-pass filter (removing frequencies above 5500 Hz) and then apply decimation (leave every Nth sample, every 4th in your case).

    For decimation, FIR, not IIR filters are usually employed, because they don't depend on previous outputs and therefore you don't have to calculate anything for discarded samples. IIRs, generally, depends on both inputs and outputs, so, unless a specific type of IIR is used, you'd have to calculate every output sample before discarding 3/4 of them.

    Just googled an intro-level article on the subject: https://www.dspguru.com/dsp/faqs/multirate/decimation

    0 讨论(0)
  • 2021-02-02 18:03

    You could make use of libsamplerate to do the heavy lifting. Libsamplerate is a C API, and takes care of calculating the filter coefficients. You to select from different quality filters so that you can trade off quality for speed.

    If you would prefer not to write any code, you could just use Audacity to do the sample rate conversion. It offers a powerful GUI, and makes use of libsamplerate for it's sample rate conversion.

    0 讨论(0)
  • 2021-02-02 18:10

    I would try applying DFT, chopping 3/4 of the result and applying inverse DFT. I can't tell if it will sound good without actually trying tough.

    0 讨论(0)
  • 2021-02-02 18:14

    You're right in that you need apply lowpass filtering on your signal. Any signal over 5500 Hz will be present in your downsampled signal but 'aliased' as another frequency so you'll have to remove those before downsampling.

    It's a good idea to do the filtering with floats. There are fixed point filter algorithms too but those generally have quality tradeoffs to work. If you've got floats then use them!

    Using DFT's for filtering is generally overkill and it makes things more complicated because dft's are not a contiuous process but work on buffers.

    Digital filters generally come in two tastes. FIR and IIR. The're generally the same idea but IIF filters use feedback loops to achieve a steeper response with far less coefficients. This might be a good idea for downsampling because you need a very steep filter slope there.

    Downsampling is sort of a special case. Because you're going to throw away 3 out of 4 samples there's no need to calculate them. There is a special class of filters for this called polyphase filters.

    Try googling for polyphase IIR or polyphase FIR for more information.

    0 讨论(0)
提交回复
热议问题