TL;DR
A sampler records a signal only at discrete points, so any detail finer than its Nyquist limit folds back as a false, coarser pattern. Anti-aliasing stops this by removing that fine detail, or by averaging it over the area each sample covers, before the samples are taken. The result is a faithful picture at the sampler's resolution instead of jagged edges, false tones or moiré.
Builds on: Nyquist–Shannon Sampling Theorem, Low-Pass Filter, Convolution · Leads to: Digital Image, Moiré Pattern
Where it's used
Audio converters. Every analogue-to-digital converter in a recording chain has an analogue low-pass filter in front of it, and it rounds each sample to a finite number of levels. The compact disc format, introduced in 1982, samples at 44,100 samples per second, so frequencies above 22,050 Hz must be removed before sampling. Otherwise a stray ultrasonic whine from a motor or a microphone would reappear as an audible tone.
Computer graphics. A renderer computes the colour of each pixel by sampling the scene at a few points inside the pixel. Without anti-aliasing, the edge of a sloped line or a tilted roof steps from one pixel to the next as a staircase. Games use multisampling or temporal anti-aliasing to average several samples per pixel, and film renderers use many more.
Digital cameras. A sensor records one value per pixel, so a fine pattern such as a striped shirt or a window screen can alias into large, wavy bands. Many cameras once placed a thin optical low-pass filter in front of the sensor for this reason, at a small cost in sharpness. Photographing a screen is a common way to see the effect, which is called moiré.
Oversampling in measurement. Many modern audio converters sample far above the audio band, for example at 64 times the final rate, then filter digitally and throw away most of the samples. The analogue filter then only has to act well above the audio band, which is much easier to build.
How it works
Picture a single row of pixels looking at a scene with one hard edge. The scene is dark for and bright for . Each pixel covers one unit of width, so pixel 1 covers the interval from to , and exactly half of it is bright.
- Take one sample per pixel at its centre. The centres are . Pixel 0 is dark, and the sample at falls on the bright side, since bright starts there. The output is . Check: pixel 1 should be half bright, but it is fully bright, so the edge has moved by half a pixel.
- Take four sub-samples inside each pixel. For pixel 1 the positions are . Two are on the dark side and two on the bright side. Check: two out of four matches the half of the pixel that is bright.
- Average the sub-samples. The value of pixel 1 is . Pixel 0 has all four sub-samples dark, giving 0, and pixels 2 and 3 are all bright, giving 1. Check: the new output is , which has the intermediate value an area-based picture should have.
- Read what the averaging did. The average is a Convolution of the scene with a box as wide as one pixel. It removes the sharp step that the sampler could not represent, leaving a soft edge that the grid can record.
- Name the idea. Averaging over each pixel's area before sampling is prefiltering. Taking more sub-samples and averaging them is supersampling. Both act before the samples are taken, because the removed detail cannot be recovered afterwards.
flowchart LR S[Continuous scene] --> F[Low-pass or area average] F --> P[Sample at the grid] P --> Q[Quantise to levels] S -. "no filter: fine detail folds back" .-> P
The dotted line is the route anti-aliasing exists to block. Detail that is too fine goes straight into the sampler and comes out as a false pattern.
The math
The walkthrough needs three things: the value a pixel should have, the averaging that approximates it, and the frequency limit that decides how much filtering is needed.
Step 1 in symbols: the ideal pixel value
Let be the scene brightness at position , and let each pixel have width , so pixel covers . The ideal value of pixel is the average brightness over its area, a definite integral divided by the width:
A single sample at the centre gives instead. Supersampling with sub-samples per pixel replaces the integral with a sum:
In the walkthrough , , and is 0 to the left of and 1 to the right. Pixel 1 has , and the sum gives as well. The centre sample gives , which is wrong by half.
Step 2 in symbols: averaging is a convolution
Let for and otherwise. This is the box filter. Convolving the scene with it and then sampling at the centre gives the area average, since
So prefiltering with a box and sampling at the centre is the same as taking the ideal area average. This is the Convolution that the walkthrough calls averaging.
Step 3 in symbols: how much filtering is needed
Sampling at spacing has sampling frequency and Nyquist frequency . The Nyquist–Shannon Sampling Theorem says the prefiltered signal must have no content at or above . The ideal prefilter is a Low-Pass Filter with response for and above. The box filter has frequency response
which is the Fourier transform of the box. Check two values. At the sampling frequency the response is , so the box removes exactly the frequency that would alias to zero. At the Nyquist frequency it is . So the box removes the sharpest detail but leaves about 64 percent of the amplitude at Nyquist, and some of that aliases anyway. This is why a box is a cheap approximation and not a perfect filter.
Step 4 in symbols: the sample
After prefiltering the signal is , and the sampler records . The stored value is in the box case. The sampler never sees content above if the prefilter has removed it, and then no false frequency can appear.
Worked examples
Take one pixel covering and a scene that is dark for and bright for . The ideal value is the bright fraction of the pixel, .
- One centre sample at is dark, so the value is . Error: .
- Two sub-samples at and give dark and bright, so the value is . Error: .
- Four sub-samples at give dark, dark, dark, bright, so the value is . Error: .
Interpretation: a single sample is all or nothing, and the error is as large as the whole bright part. Each doubling of the sub-samples gives a finer estimate, and with four sub-samples the edge fraction is exact because the edge falls on the boundary between two sub-pixels.
Take one row of pixels, , and a bright line of width from to on a dark background. The ideal pixel values are the fraction of each pixel covered by the line: pixel 1 gets (from to ), pixel 2 gets (from to ), and pixels 0 and 3 get .
- Single centre samples at . The line covers none of these points, so the output is . Check: the line is visible in the scene but gone from the picture.
- Four sub-samples in pixel 2 at . The first two lie on the line and the last two do not, so . Check: the true coverage is , and is close.
- Four sub-samples in pixel 1 at . None lie on the line, so . The true coverage is , which the sampler rounds away.
- The output is with the sub-samples, against with single samples.
Interpretation: a point sampler can miss a feature completely, and no later step can bring back a line that was never recorded. Supersampling finds the line and gives its brightness roughly right, at the cost of four times the work.
A studio records at 48,000 samples per second, so the Nyquist frequency is Hz. A motor produces a tone at Hz that is well above the audio band.
- The tone is above the Nyquist frequency, , so it must be removed before sampling.
- Without a filter, the tone folds back to Hz.
- Check: Hz lies inside the audible band, which runs to about 20,000 Hz, so a listener would hear a tone that was never in the room.
- The analogue low-pass filter must therefore attenuate the Hz tone strongly before the converter samples, because the alias cannot be taken out afterwards.
Interpretation: the filter's job is to act above Hz, and if it is designed with a gentle slope, it must start rolling off well below that frequency, which is one reason converters oversample.
Try it. The same motor is recorded at 44,100 samples per second. What is the alias of its Hz tone, and is it audible?
Answer: the Nyquist frequency is Hz, and the alias is Hz. That is inside the audible band, so it would be heard.
Common mistakes and tradeoffs
Misconception 1: anti-aliasing is just blurring. It is tempting to think that filtering only makes the picture soft. In fact the filter removes detail that the grid cannot represent, so the blur is the part that the sampler could not have used. A sharper picture made by sharpening the samples does not recover the removed detail, because sharpening adds back frequencies that were never recorded.
Misconception 2: aliasing can be fixed after sampling. It is tempting to think a digital filter can clean up aliased samples. In fact a 30 kHz tone sampled at 48 kHz and a true 18 kHz tone give the same samples, so no digital step can tell them apart. The fix has to come before the sampler.
Misconception 3: higher resolution removes the need for anti-aliasing. It is tempting to think more pixels make the problem go away. In fact higher resolution only raises the Nyquist limit, and a finer pattern, such as a fabric weave, can still alias. The problem moves to a finer scale rather than disappearing.
When to use it. Always use it when the signal or scene may contain detail finer than the sampling grid, which in practice is almost always. The cost is a loss of sharpness and extra computation for supersampling.
| Situation | What goes wrong | Better choice |
|---|---|---|
| Real-time rendering with a tight frame budget | Full supersampling is too slow | Multisampling on edges, or temporal anti-aliasing that reuses earlier frames |
| Offline film rendering | Quality matters more than speed | Many sub-samples per pixel, with a filter wider than one pixel |
| Audio converters | The analogue filter must be steep, which is hard and noisy | Oversampling, then a digital filter and decimation |
| Camera sensors | Fine repeating patterns form moiré | An optical low-pass filter, or a lens that blurs slightly |
| Distant textures in a game | Many texels fall inside one pixel and the result shimmers | Prefiltered textures, such as mipmaps |
History
Harry Nyquist described the limit on how fast a signal can be sent and recovered in a 1928 paper on telegraph transmission, and Claude Shannon put the sampling statement in its modern form in 1949. Their result says a signal with no frequencies above half the sampling rate can be rebuilt from its samples, and it implies that frequencies above that limit cannot be told apart from lower ones.
Digital audio made the rule a practical design constraint. The compact disc format of 1982 uses a sampling rate of 44,100 per second and needs a filter that cuts off just above 20 kHz, which is why converters are built with steep analogue filters or with oversampling.
In computer graphics the problem was recognised early. Franklin Crow described aliasing in computer-generated shaded images in the late 1970s, and the methods that followed, from supersampling to filtered textures, are all forms of the same prefiltering idea.
Recap
- A sampler records a signal only at discrete points, so detail above the Nyquist limit folds back as a false, coarser pattern.
- Anti-aliasing removes that detail before sampling, either with a Low-Pass Filter or by averaging over each sample's area, which is a Convolution with a box.
- A box filter is a cheap approximation: it removes the sampling frequency exactly but only partly attenuates content at the Nyquist frequency.
- Supersampling is the same idea in numerical form, and it can find features that a single sample misses.
- Next, read Digital Image for how a sampled picture is stored, and Moiré Pattern for the visible result of aliasing in fine repeating patterns.
Check yourself
QuestionRecall: why must anti-aliasing happen before the signal is sampled, and not after?Show answer
Once a signal is sampled, a high frequency above the Nyquist limit produces the same sample values as a lower frequency, so the two cannot be separated afterwards. Removing or averaging away the high detail has to happen while the signal is still continuous, or at least before the samples are taken, because any detail that has aliased is already mixed into the recorded values.
QuestionComputation: a pixel covers and the scene is bright for , dark otherwise. What does a single centre sample give, what does four equally spaced sub-samples give, and what is the true area value?Show answer
The centre sample is at , which is bright, so it gives . Four sub-samples at give dark, dark, bright, bright, so the average is . The true area value is the bright fraction of the pixel, . So the centre sample is off by and the four sub-samples are off by .
QuestionWhy: why does the box filter remove the sampling frequency completely but leave some of the Nyquist frequency?Show answer
The box filter's response is . At the sampling frequency the numerator is , so that frequency is removed exactly. At the Nyquist frequency the response is , so a substantial part of the content at that frequency survives and can alias. A better prefilter has a response closer to a sharp cut-off at the Nyquist frequency, which is what the ideal low-pass filter provides.
QuestionApplied: a designer records a sensor signal at 1,000 samples per second and finds a 600 Hz hum in the samples that is not present in the physical source. What is the likely cause, and what should be changed?Show answer
The Nyquist frequency is Hz, so a source above it folds back. A source at Hz aliases to Hz, and so does one at Hz. A source at 600 Hz would itself be above the limit and would alias to 400 Hz, so the 600 Hz hum must come from a higher-frequency component in the physical source. The fix is an analogue low-pass filter with its cut-off below 500 Hz, placed before the converter, because the alias cannot be removed afterwards. Raising the sampling rate moves the Nyquist limit up, but it only helps for sources that fall below the new limit, so the filter is still needed.