0
$\begingroup$

I'm building a real-time audio resampler (think pitch bend) that needs to have a several different performance vs quality configuration options. I understand that I'll need to apply a low-pass filter before resampling in order to avoid aliasing.

The requirements for the first filter are this:

  • very efficient
  • better than nothing

For this filter, I don't mind if I have a very slow roll-off, or if there's significant phase distortion. I just want it to be as fast as possible, and to attenuate frequencies above nyquist to some degree.

The requirements for the second filter are:

  • reasonably efficient
  • significant reduction in frequencies above nyquist

I'm guessing that I'll want to go with one of the classic algorithms I hear about for the second filter (chebyshev, butterworth), and potentially something like a recursive moving average filter for the first.

I realize my question may so vague as to be useless ("very efficient" and "reasonably efficient" are obviously relative terms!) I realize that filter selection and design is an art that one can spend a lifetime on. I'm quite inexperienced with DSP and am just looking for a couple algorithms I can get my hands dirty with. I'm hoping someone with audio experience can pip up and say "here are my general purpose, go-to algorithms for efficient lowpass filtering".

$\endgroup$
  • $\begingroup$ You're right in that you need to pin down some more details to make a decision. Filter designs in most cases are parametric, allowing you to trade off things like filter order, transition width, passband distortion, stopband attenuation, and so on. There are a number of knobs that you can turn to choose the position in that trade space that makes sense for your application. Also, what platform will this be on? If it's a PC application, audio rates are low enough relative to modern CPU capabilities that you often don't need to worry much about computational load. $\endgroup$ – Jason R May 15 '15 at 16:38
  • $\begingroup$ The code is destined for a library that may run on a range of devices, which is why I'm interested in providing a couple options, one for higher quality, and one for higher efficiency. There may need to be many dozens of instances of it running at once, so performance could become an issue. I realize that there's going to be a lot of art, tuning, and fiddling. I'm hoping to choose a general family of filter first. Unfortunately, I'm not going to be able to devote time to implementing a large range of possibilities and comparing them all. I'm going to have to make an initial decision. $\endgroup$ – morgancodes May 15 '15 at 16:44
1
$\begingroup$

For a first cut, I would consider a windowed Sinc interpolation kernel for both resamplers. Very narrow window with a small polyphase table for the fast one. Much wider window with more phases in a larger, possibly interpolated lookup table for the slower higher quality filtered interpolator/resampler. Lots of parameters (including choice of window) that can be adjusted for both quality and performance to meet widely varying requirements.

$\endgroup$
  • $\begingroup$ Thanks! This is FIR filter, correct? Am I right in assuming that an IIR filter is generally going to be computationally cheaper? $\endgroup$ – morgancodes May 16 '15 at 1:15
  • $\begingroup$ An IIR filter can anti-alias filter with less computation, but does almost nothing to help with the resampling (unless the rate change is a pure integer, or a ratio with a small numerator), especially for the small rate change deltas involved with pitch bending. Whereas an interpolator can perform much better for tiny and varying sample rate changes. $\endgroup$ – hotpaw2 May 16 '15 at 2:54
  • $\begingroup$ Ahh, got it. So the windowed sinc, isn't a low pass filter, it's a one-stop bandlimited interpolator that doesn't require an anti-aliasing filter. Yeah? This strikes me as probably more difficult for a novice to implement than a classic filter plus (linear/cubic/hermite/etc) interpolation combo, but maybe not? $\endgroup$ – morgancodes May 16 '15 at 15:13
  • $\begingroup$ @morgancodes Using a windowed sinc interpolation or upsample-filter-downsample are actually two different ways of doing the same mathematically. It's not necessarily obvious to see both of them as the same thing, but in any case, one won't be easier or harder for your to implement in the end. $\endgroup$ – Lolo May 17 '15 at 3:53
  • 1
    $\begingroup$ Although a firpm() filter might have a bit less ripple and stop band leakage, it's hard to dynamically modify the filter (width, etc.) on the fly to meet widely varying performance needs, as per the question, unless the system has the performance to support a live MATLAB license+installation. Whereas, with a simple window formula, one might even be able to recalculate the coefficients per sample if for some reason needed (pedagogy, etc.) $\endgroup$ – hotpaw2 May 18 '15 at 5:36
1
$\begingroup$

Given that:

  • you are new to DSP
  • you are designing code to be used in a library for a variety of devices (and data types perhaps?)
  • your filter applies to an upsampled signal*

I recommend you start creating an implementation for an FIR that can take an arbitrary coefficient table for now.

Writing an FIR is simple, easy to debug, and you don't have any feedback loop as with IIRs that may induce error propagation and instability issues (especially with fixed-point data).

Once you have written your FIR, you can readily experiment with any filter coefficient tables you put your hands on until you find the compromise you think is right for your low- and high-end filters.

In addition, if the code finds its way into a library that later needs to be optimized for a given device, people will have an optimized FIR routine that can readily be leveraged. Same isn't necessarily true with IIRs as there are different flavors of IIR implementations.

  • Upsampled signal ==> lots of zeros ==> lots of multiplications you can easily ignore when computing a given sample output from an FIR
$\endgroup$
0
$\begingroup$

As stated previously, there is a tradeoff with rolloff and computation time. You can really get away with a 1st-order lowpass IIR filter (sure you can use Butterworth as mentioned) designed in MATLAB with a cutoff frequency a bit below sampling frequency Fs/2.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.