[sdiy] Digital filtering (Oversampling and downsampling)

Scott Gravenhorst music.maker at gte.net
Mon Aug 3 18:47:58 CEST 2009


Tom Wiltshire <tom at electricdruid.net> wrote:
>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.

Hi Tom,

Fun, eh?  I've been there with this too.  My GateMan monosynth which supports
portamento uses a sample rate of 1.0MHz at the DAC as well as internally.  There is
no filtering other than the state variable filter used for timbre shaping.  While I
know that there is aliasing going on, I don't hear it because the harmonics that are
folding at Nyquist are so low in amplitude that the aliased signal is not
objectionable and probably not audible either.  I also use a high sample rate on the
GateManPoly at 250 KHz (no portamento) and again, I don't have problems with audible
aliasing.  Both synths generate their waveforms naively.

My PolyDaWG synths all use high sample rates as well at 250 KHz.  I hear no aliasing
here either, even using a square pulse to excite the waveguide.  The pulse is very
short, so aliasing might be contributing to the early attack portion of the sound. 
Perhaps it's because of the sample rate - or the fact that there's a filter that
keeps stripping harmonics off as the signal bounces through the waveguide - or
perhaps it's all three working together (which is what I believe is happening).

I have also experimented with a brickwall type FIR filter using oversampling and it
is quite effective with naively generated waveforms up to fundamentals of 5 KHz.

Another method to reduce aliasing is to use band limited waveforms.  That can get
complicated because a table with wave data that works for low fundamentals will
sound lackluster at higher fundamentals.  To do it well, it needs multiple tables
and logic to select when each table is used.

One advantage of an FPGA for DSP is it's sheer size which allows one to design a
reasonably large synthesizer, running at a high internal sample rate and then
brickwall filter and decimate before feeding the DAC at a lower rate.

In my view, a high sample rate is your friend.

-- ScottG
________________________________________________________________________
-- Scott Gravenhorst
-- FPGA MIDI Synthesizer Information: home1.gte.net/res0658s/FPGA_synth/
-- FatMan: home1.gte.net/res0658s/fatman/
-- NonFatMan: home1.gte.net/res0658s/electronics/
-- When the going gets tough, the tough use the command line.




More information about the Synth-diy mailing list