How to resample a signal without aliasing
My previous post described how resampling a signal can cause aliasing problems. The worst problems occur when dramatically reducing the number of samples used to represent a signal, or when the source includes lots of high frequency detail. Specifically, there is a magic value called the Nyquist frequency, which is half the rate at which are you taking output samples. If the source signal contains information with a higher frequency than this threshold, you will have aliasing problems.
To put this another way: in order to avoid aliasing, you must take at least twice as many output samples as the finest detail in your input signal.
That leaves us with basically just two ways to avoid aliasing:
- Take more output samples
- Or have less fine detail in the input signal
- Smooth (aka. blur) the input data to remove fine detail
- Or smooth (aka. filter) on the fly as we read our sample values
Option 2.2 can dynamically adjust to different sampling frequencies, but tends to be expensive to implement, as it must average many different samples from slightly different locations in the input.
A third option is to declare this whole digital sampling business a mug's game and refuse to play at all. In some situations it is possible to work entirely with mathematical equations, transforming one signal into another by applying mathematical transformations to the equations which describe them. This approach inherently avoids digital approximation, so will not produce any aliasing, but the math tends to get very complex. It is not widely used in realtime computer graphics, but many offline renderers (eg. RenderMan) work this way.
Ok, that's enough theory. Next, let's get practical...