Forums

Standard filters for interpolation/decimation?

Started by BrokenForm January 30, 2004
I'd really like not to reinvent the wheel for my current hobby
project, so I beg of all DSP people out there - what are the standard
filters used for 16X interpolation/decimation? Are they windowed-sinc,
Chebyshev, Butterworth, or something else? And what are the
coefficients, can I find tables of them somewhere?

My goal is to create a simple VST guitar distortion plugin which uses
non-linear transfer functions that are polynomials of order 15 or
less, and which uses 16X oversampling before the nonlinearity and
lowpass filtering + 16X decimation after the nonlinearity. This should
prevent aliasing from very high harmonics "folding" down back into the
audio range, and hopefully prevent gritty computery sound. I hope also
that using a Taylor-series expression for the transfer functions will
allow easy user control of even and odd harmonic mix at both low and
high input signal amplitudes, allowing good-quality simulation of both
transistor and tube distortion circuits.

Unfortunately, I'm confused by all the choices out there for doing the
16X interpolation/decimation. Should I do it in 4 stages of 2X
oversampling, or should it be one 16X stage? Would it be best for me
to use a Butterworth or Chebyshev IIR low-pass filter, or are those
just too shallow for this application? Should I use a nice sharp FIR
windowed-sinc filter, and accept the relatively high CPU load and the
inevitable group delay (of one-half the impulse response's length)
which must somehow be hacked around in the VST framework?

It seems to me that so many people must have done this before, that
designing my own filters would be equivalent to writing my own
malloc() routine.  Is there a standard way to do this, with well-known
filter coefficients?  Or does everybody just buy a different
proprietary toolkit (something I can't afford to do) - is this too
specialized to be general knowledge?
Hi,

I've read the whole of this post and I think that you are probably on
the wrong track. Please read on.

BrokenForm wrote:
> > I'd really like not to reinvent the wheel for my current hobby > project, so I beg of all DSP people out there - what are the standard > filters used for 16X interpolation/decimation? Are they windowed-sinc, > Chebyshev, Butterworth, or something else? And what are the > coefficients, can I find tables of them somewhere?
For sample rate conversion applications they are usually windowed sinc but for your application, I don't think that is the best option. In addition, windowed sinc filters are FIR and have a significant transport delay that would be undesirable if you wanted to apply distortion in real time.
> My goal is to create a simple VST guitar distortion plugin which uses > non-linear transfer functions that are polynomials of order 15 or > less,
I think you are probably getting a little carried away with the order of your polynomial. I would say that 8th order would be more than sufficient. In distortion applications, higher order harmonics are undesirable, sound bad and have a huge contribution to intermodulation distortion which you would probably try to minimise (it sounds awful). The vast majority of the pleasant sound of a nicely distorted guitar are the lower order harmonics like 2nd, 3rd, 4th and 5th.
> and which uses 16X oversampling before the nonlinearity and > lowpass filtering + 16X decimation after the nonlinearity.
I beleive that this is excessive or rather much too "high fidelity". Generally, guitar amplifiers and cabinets have a high order low pass characteristic which start rolling off at about 5kHz. Similarly, most standard guitar pickups (apart from the active EMGs etc) also have a order low pass characteristic. In addition, electric guitar stings do not generate large amounts higher order harmonics. By taking the above two factors into account, you can drastically reduce the amount of processing you have to do and probably end up with something that sounds far more realistic as well. My suggestions are as follows: - Do go with the idea of: interpolate -> lowpass -> distortion -> lowpass -> decimate - Limit yourself to an 8th order polynomial. - Implement "interpolate -> lowpass" as a single stage of zero stuffing four cascaded 2nd order lowpass sections. For example, to interpolate by 2 you would put a zero sample between each existing sample and then pass that through the filter. - For the filters, use the RBJ bi-quads: http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt The filters should have a upper cutoff frequency of about 5kHz with respect to the interpolated sample rate (ie if you are interploating 44.1kHz audio by 2 as above, the filter has to have a cuttoff of 5kHz wrt 88.2kHz). - With the four cascaded 2nd order IIR sections, have two of the set to constant cuttoff/Q (ie butterwoth reponse) and allow the user to modify the filter cuttoff (from 5kHz down to say 1kHz) and Q factor for effects that will emulate a wha-wha into a distortion (Jeff Beck anyone?) and the tone controls on the guitar. - For post-distortion downsampling, use similar filters to the input filters again allowing the frequency and Q factors of two of them to be modified to emulate the low pass characteristics of most guitar amp speaker cabinets. The final question to be answered is how much to interpolate by to prevent aliasing. I will assume an input and output sample rate of 44.1kHz. The cascade of 4 2nd order filters (ie a 4th order) at the input, with a maximum cuttoff frequency of 5kHz have rolloff of 48dB per octave. Ie Freuency Attenuation 10kHz 48dB 20kHz 96dB With an 8th order polynomial, you could probably get away with interpolating by 4 (sample rate of 176kHz) although 6 or 8 (352kHz) might be better. When calculating the filter coeficients, remember that you are aiming for a cuttoff of 5kHz with repect to the interplated sample rate (176kHz or 352kHz). HTH, Erik -- +-----------------------------------------------------------+ Erik de Castro Lopo nospam@mega-nerd.com (Yes it's valid) +-----------------------------------------------------------+ Microsoft is finally bringing all of its Windows operating system families under one roof. It will combine all of the features of CE, stability and support of ME and the speed of NT. It will be called Windows CEMENT...
doing it in multiple stages will reduce the processing load.  The first
stage (higher rate) filters do not have to have as sharp a cut-off, and
can often be as simple as a moving average (boxcar) filter.  By
decimating, the next stage has more time to compute the filtered result
for each sample, so you can get a more complex filter done in the same
amount of time.  This multi-stage approach is known as multi-rate
filtering.  P.P. Vaidyanathan has a good book on the subject.
Alternatively, you can do it with a polyphase filter, which essentially
drops the computation for the discarded outputs.  The result there, is
your output is the sum of the outputs of 16 sub filters all running at the
output sample rate.  The math and therefore the design for this is simpler
than the multi-rate filter, but the processing load is generally higher
than a multirate filter for a given response for decimation ratios larger
than about 4.  The filter for the polyphase implementation is designed as
though it were a single filter working at the input sample rate and
decimated at the output.  It doesn't reduce the number of filter taps,
rather it reduces the frequency each tap needs to be computed.

BrokenForm wrote:

> I'd really like not to reinvent the wheel for my current hobby > project, so I beg of all DSP people out there - what are the standard > filters used for 16X interpolation/decimation? Are they windowed-sinc, > Chebyshev, Butterworth, or something else? And what are the > coefficients, can I find tables of them somewhere? > > My goal is to create a simple VST guitar distortion plugin which uses > non-linear transfer functions that are polynomials of order 15 or > less, and which uses 16X oversampling before the nonlinearity and > lowpass filtering + 16X decimation after the nonlinearity. This should > prevent aliasing from very high harmonics "folding" down back into the > audio range, and hopefully prevent gritty computery sound. I hope also > that using a Taylor-series expression for the transfer functions will > allow easy user control of even and odd harmonic mix at both low and > high input signal amplitudes, allowing good-quality simulation of both > transistor and tube distortion circuits. > > Unfortunately, I'm confused by all the choices out there for doing the > 16X interpolation/decimation. Should I do it in 4 stages of 2X > oversampling, or should it be one 16X stage? Would it be best for me > to use a Butterworth or Chebyshev IIR low-pass filter, or are those > just too shallow for this application? Should I use a nice sharp FIR > windowed-sinc filter, and accept the relatively high CPU load and the > inevitable group delay (of one-half the impulse response's length) > which must somehow be hacked around in the VST framework? > > It seems to me that so many people must have done this before, that > designing my own filters would be equivalent to writing my own > malloc() routine. Is there a standard way to do this, with well-known > filter coefficients? Or does everybody just buy a different > proprietary toolkit (something I can't afford to do) - is this too > specialized to be general knowledge?
-- --Ray Andraka, P.E. President, the Andraka Consulting Group, Inc. 401/884-7930 Fax 401/884-7950 email ray@andraka.com http://www.andraka.com "They that give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin, 1759