[sdiy] Digital filtering (Oversampling and downsampling)

Tom Wiltshire tom at electricdruid.net
Mon Aug 3 17:59:34 CEST 2009


Hi All,

I'm currently doing quite a lot of experiments with digital  
filtering, which I only recently worked out how to do.

The biggest problem with cheap digital systems (like dsPIC) for  
synths is aliasing. Fans of PPG aside, most people think aliasing is  
objectionable, and I agree with them. No birdies in my synth, please.  
I'll be pretty lucky to get rid of them completely, but hey, y'gotta  
try.

One technique for reducing aliasing is to use oversampling. The  
general scheme is to run the system with an internal sample rate that  
is some multiple of the final output rate. For example, with a 48KHz  
output rate, you could run your sound generation algorithm at 384KHz  
for x8 oversampling. Whilst even a rate this fast won't remove all  
your problems (the 100th harmonic of a ramp wave at the highest MIDI  
note is over 1MHz) it will certainly help. As long as what you're  
doing is simple enough that you can do it eight times, rather than  
just once, in the time you have between your output samples, then  
you're fine. This might be true for fairly straightforward algorithms  
like sine FM or perhaps wavetable oscillators.

The final part of an oversampling system is to reduce the internal  
sample rate for output. This is done by applying a digital filter to  
remove any unwanted high frequency content (remember that a signal  
with a sample rate of 384KHz could have frequencies up to 192KHz) and  
then chucking away most of the samples (7 out of 8 to get from 384 to  
48KHz). This combination of filtering and decimation is called  
"downsampling".

This downsampling filter seems to be where most of the problems are.  
It makes sense to have a fairly low final output sample rate, since  
that give me longest between output samples to generate my signal.  
Let's stick with 48KHz for the sake of argument. I need the  
downsampling filter to provide significant attenuation by 24KHz to  
avoid aliasing in the decimation step; say -80dB, but you choose a  
level. If I roll the downsampling filter off at about 20KHz, I'm left  
needing a very steep slope, since I want to pass 20KHz, but  
completely block 24KHz and above. This requires a complex digital  
filter with a lot of coefficients and a lot of calculating.

If instead I choose a higher output sample rate, I can relax the  
downsampling filter specification. Let's try 96KHz.  Now I want to  
pass 20KHz, and I need significant attenuation by Fs/2=48KHz. This  
gives me 28KHz for the transition band of the filter, rather than  
4KHz. This is much less demanding and can be done with fewer  
coefficients and calculated quicker. Now we only have to generate  
half as many samples to get up to our oversampled rate of 384KHz (now  
we're oversampling at x4 not x8). We've got half as much time to do  
it, but we can finish up with less-than-half as much to do, since the  
downsampling filter can be much simpler.

This means that sometimes it seems to actually be *easier* to run  
with a faster sample rate.

Is this really true? How far does this go? Would I do better still  
trying to run at 192KHz?

Balancing these competing demands without a lot of previous  
experience seems to be very difficult and very much an art not a  
science. If anyone has any useful experience or pointers to offer,  
I'd be grateful for any help I can get.

Thanks,
Tom





More information about the Synth-diy mailing list