Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downsampling and applying a lowpass filter to digital audio

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 engineering class many years ago, I know that the stream won't be able to describe anything over 5500Hz accurately anymore, so I assume I want to cut everything above that out too. Any ideas? Thanks.

Update: There is some code on this page that converts from 48KHz to 8KHz using a simple algorithm and a coefficient array that looks like { 1, 4, 12, 12, 4, 1 }. I think that is what I need, but I need it for a factor of 4x rather than 6x. Any idea how those constants are calculated? Also, I end up converting the 16 byte samples to floats anyway, so I can do the downsampling with floats rather than shorts, if that helps the quality at all.

like image 455
twk Avatar asked Oct 26 '08 18:10

twk


People also ask

What does downsampling do to audio?

(1) To make a digital audio signal smaller by lowering its sampling rate or sample size (bits per sample). Downsampling is done to decrease the bit rate when transmitting over a limited bandwidth or to convert to a more limited audio format. Contrast with upsample.

What is downsampling in digital signal processing?

Downsampling by an integer factor. Rate reduction by an integer factor M can be explained as a two-step process, with an equivalent implementation that is more efficient: Reduce high-frequency signal components with a digital lowpass filter. Decimate the filtered signal by M; that is, keep only every Mth sample.

What does a low pass filter do in audio?

A low-pass filter (LPF) attenuates content above a cutoff frequency, allowing lower frequencies to pass through the filter. The slope of filter attenuation is usually quantified in decibels per octave.


2 Answers

Read on FIR and IIR filters. These are the filters that use a coefficent array.

If you do a google search on "FIR or IIR filter designer" you will find lots of software and online-applets that does the hard job (getting the coefficients) for you.

EDIT:

This page here ( http://www-users.cs.york.ac.uk/~fisher/mkfilter/ ) lets you enter the parameters of your filter and will spit out ready to use C-Code...

like image 119
Nils Pipenbrinck Avatar answered Oct 22 '22 10:10

Nils Pipenbrinck


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.

like image 45
Mendelt Avatar answered Oct 22 '22 08:10

Mendelt