What is this about ?
Antialiasing is an important topic to understand when dealing with digital processing of data. In this article I concentrate on the various methods used to combat this phenomenon, and try to explain what is multirate filtering and how it is related to antialiasing.
Sampling
Both analog and digital signals can be sampled. If we use an ADC that runs at 10^6 samples per second, then we can say that the analog signal on the ADCs input is sampled at frequency Fs = 1 MHz. Each digital signal has some sampling frequency tied to it - the frequency at which it was sampled
[1]. If we take a digital signal that was sampled at frequency Fs, and grab each 4th sample discarding the others, we get a digital signal sampled at Fs/4.
What is aliasing ?
I won't go too much into mathematical details here, as I assume that the basics are well known. Whenever some signal (either analog or digital) is sampled at frequency Fs, aliasing will occur if the original signal had harmonics at Fs/2 or higher (that is, if the sampling frequency was below the Nyquist frequency of the signal). See the links section in the end of this articles for more details. Aliasing is "bad for you", it distorts a signal in a way that can't really be fixed, so engineers to their best to avoid it. Fortunately, it is quite simple, using antialias filters.
Antialias filters
So, we have a signal we want to sample, and we want to avoid aliasing. What should be done ? Generally, given that our sampling rate is Fs, we just need to make sure that there are no harmonics faster than Fs/2 in the signal. How can we assure this ? By using a lowpass filter that cuts all the harmonics above Fs/2. Such a lowpass filter is called an "antialias filter".
Say that the input to your system is an analog signal. You know that it has no "important" information at harmonics above 10 KHz, so you can safely sample it with an ADC at 20 KHz. However, although nothing above 10 KHz interests you, the signal might (and
will, in a real-world system) have some power at harmonics above 10 KHz, mostly because of noise and the imperfect nature of analog signals. So, how do you avoid aliasing ? Right, by using an antialias filter. And how is that done ? Exactly - just prepend a lowpass filter to the ADC, which cuts off at 10 KHz, and viola, you'll have a clean sampled signal.
Analog antialias filters
This is nice in theory, but in the real world, such an implementation poses some serious difficulties. To get a clean signal, you must use a very accurate lowpass filter, one that passes everything below 10 KHz and nothing above 10 KHz. In the DSP jargon such a filter is called a "brick-wall" filter, since it looks like a brick wall with completely right angles.
The sad truth is that such filters are impossible. They are unreal - a theoretical delirium. We can get quite close though, but constructing an analog filter that is close to a brick wall requires an accurate, high-order filtering circuitry, which is difficult and quite expensive. Fortunately, there is hope - multirate filtering to the rescue !
Digital antialias filters
I will discuss the general topic of multirate filtering below, but for now I want to explain how it helps with digital antialias filtering.
Consider the following solution to the problem presented in the last section: We know that there's interesting information at up to 10 KHz, so we should sample the signal at
at least 20 KHz, according to the sampling theorem
[2]. But nothing prevents us from sampling it at a much higher frequency, and gain an important advantage by doing so.
Suppose we sample the signal at 100 KHz instead of 20 KHz. Now, to avoid antialiasing in this sampling, we must attach a lowpass filter before the ADC that cuts off at 50 KHz. Note, however, that it is not obliged to be a brick wall filter, since 50 KHz is very far from 10 KHz where the information is, so we don't mind for some useless frequencies at 40+KHz to be attenuated. Hence, we can attach a very simple analog filter before the ADC - a RC for example, tuned to 50 KHz. This helps with the antialiasing of the 100 KHz sample, but it doesn't ensure a clean signal, since frequencies between 10 and 50 KHz still pass through, disrupting information that is stored at below 10 KHz.
To solve this problem, we now apply another antialias filter on the sampled data. We can now apply a digital lowpass filter tuned to cut-off at 10 KHz. Digital filters also can't be brick wall, but they can easily approach it, at a fraction of the cost of an analog filter with the same specification !
So, the full solution is: sample the input signal at 100 KHz with an ADC, which has a simple RC filter at its input configured to cut off at 50 KHz. Next, we apply an "almost brick wall" digital lowpass filter configured to cut off at 10 KHz. Then, we can resample our 100 KHz signal to 20 KHz (by simply discarding 4 out of each 5 samples) and yay - we have a clean 10 KHz signal sampled at 20 KHz, no aliasing and no noise disrupting the information.
Multirate systems
"Multirate" simply means
multiple sampling rates. A multirate DSP system uses multiple sampling rates within the system. In the example above, we have a multirate system because the signal is first sampled at 100 KHz and later re-sampled at 20 KHz. Generally, if we can allow to increase the initial sampling frequency of the analog signal (which is called
oversampling the signal), we can lower the overall cost of the system because the analog part becomes much simpler.
Decimation, Interpolation and Resampling
Decimation is decreasing the sampling rate of a signal. In our example, after the digital antialias filter is applied, the signal is decimated by a factor of 5 from 100 KHz to 20 KHz. Another common use for decimation is decreasing the sampling rate to ease on the computation. Suppose you just need to sample an audio signal, for which 44 KHz is usually enough, but you only have a 10 MHz ADC. Why overwhelm your processor with so much samples, when decimating by a factor of 100 would be just fine.
Interpolation is the reverse process - increasing the sampling rate of a signal. This is usually done by inserting a certain amount of zeros between each sample of a signal (inserting N zeros means a N + 1 times increase in the signal's frequency) and passing the signal through a digital lowpass filter. The aim is often to generate an input for a system with a faster sampling rate.
Resampling is a combination of Decimation and Interpolation. If you have a signal with sampling frequency Fs and you want to have a signal with a sampling frequency of 2.5 * Fs, you can first interpolate the signal by a factor of 5 and then decimate it by a factor of 2.
Note: in some digital FIR filter generation tools, it is often possible to combine a FIR with decimation and / or interpolation. This is because the combination allows for a more efficient implementation than separate stages of filtering and resampling.
Digital-only antialias filtering
A common misconception seems to be that it is possible to implement antialias filtering without analog circuitry. This is false. Between a real world analog signal and a digital system there must, somewhere, lie the brink where the analog signal is sampled to turn it into the digital signal. And in real physical signals, wherever there is sampling, there is aliasing. So analog filtering is essential, unless you are very sure that your analog signal really doesn't have any power at above Fs/2, which is rarely the case.
A good rule of thumb is: whenever you sample an analog signal for digital processing with an ADC at rate Fs, attach a simple RC lowpass filter configured to cut off at Fs/2 before the ADC (it is best to make is a little less than Fs/2 to account for the very imperfect performance of a RC filter). This assures that the sampled signal is free of aliases. Later, you can apply multirate techniques with digital filters to further shape your digital signal.
So remember, digital antialias filtering works only for digital signals.
Links
These links were active at the time I wrote the article. If you find a dead link, let me know. In any case, Googling for the link's title may bring you to its new location and other related sources.
- Wikipedia entry on aliasing
- Introduction to DSP - aliasing
- Introduction to digital filters
- Wikipedia entry on the Nyquist-Shannon sampling theorem
- Multirate FAQ
- The Scientist and Engineer's Guide to Digital Signal Processing - A free book
Notes
[1] - For simplicity it is sometimes useful to assume that an analog signal is just a digital signal sampled at a very high frequency, say 10^50 Hz.
[2] - The sampling theorem states that in order for a band limited (at Fv) signal to be reconstructed fully, it must be sampled at a rate Fs >= 2*Fv.