Aliasing in Signal Processing: Nyquist-Shannon Theorem & Best Practices for Downsampling and Upsampling
1. Nyquist-Shannon Sampling Theorem (Standard)
This is the foundational principle for preventing aliasing in both downsampling and upsampling:
- The signal must be sampled at least at twice the highest frequency component in the signal (i.e., the sampling rate should be greater than or equal to twice the maximum frequency, known as the Nyquist rate).
Mathematically:
fs ≥ 2 × fmax
Where:
fsis the sampling rate.fmaxis the maximum frequency present in the signal.
For a signal with frequency content up to fmax, the Nyquist rate is 2 × fmax. If you violate this and sample below this threshold, aliasing will occur.
Aliasing in Signal Processing
Aliasing is a phenomenon that occurs when a continuous signal (or sampled signal) is undersampled during digital signal processing. This results in different signals becoming indistinguishable from each other when sampled at a lower rate. Aliasing is a major issue in both downsampling (decimation) and upsampling (interpolation), although it manifests differently in each case.
1. Aliasing during Downsampling (Decimation)
Downsampling involves reducing the sampling rate of a signal. When you downsample a signal, you take fewer samples per unit time. If the signal contains frequencies higher than half the new sampling rate (the Nyquist frequency), those high-frequency components get folded back into the lower frequency range, causing aliasing.
Conditions for Aliasing in Downsampling:
- The original signal contains frequency components above half the new sampling rate (i.e., above the Nyquist frequency).
- The Nyquist-Shannon sampling theorem states that to avoid aliasing, the original signal should be band-limited to half of the sampling rate (i.e., the Nyquist frequency).
- If you downsample without low-pass filtering (anti-aliasing filter) the signal to remove these high-frequency components, aliasing will occur.
Example:
Suppose your original signal has a sampling rate of 1000 Hz. This means that the Nyquist frequency is 500 Hz.
If you want to downsample to a new sampling rate of 300 Hz, the Nyquist frequency for this rate is 150 Hz.
Any frequency component in the signal above 150 Hz will alias and appear as lower-frequency components.
To prevent aliasing during downsampling:
- Pre-Filtering (Anti-Aliasing Filter): Apply a low-pass filter to the signal before downsampling. This filter should remove any frequency components above the Nyquist frequency of the new sampling rate.
For example, if you downsample from a sampling rate of fs = 1000 Hz to fs' = 300 Hz, the filter should remove all frequencies above 150 Hz (half of the new sampling rate).
- Downsample the Signal: After the low-pass filtering step, downsample the signal by selecting every
M-th sample, whereMis the downsampling factor.
Mathematical Standard for Downsampling:
fnew = fold / M
Where:
fnewis the new, lower sampling rate.foldis the original, higher sampling rate.Mis the downsampling factor.
2. Aliasing during Upsampling (Interpolation)
Upsampling, or interpolation, involves increasing the sampling rate of a signal. During upsampling, additional samples are inserted between the existing samples to increase the sample rate, but the frequency content of the signal does not change. Upsampling itself doesn't cause aliasing directly, but it can introduce artifacts if not handled properly.
Aliasing in Upsampling occurs due to:
- The introduction of high-frequency components (above the Nyquist frequency of the new sampling rate) into the signal after the interpolation process. This can happen because interpolation can generate frequencies higher than the Nyquist frequency of the target sampling rate.
Example:
Suppose your original signal has a sampling rate of 200 Hz, and you upsample to 800 Hz.
The Nyquist frequency of the original signal is 100 Hz (half of 200 Hz), so the signal may have frequencies between 0 Hz and 100 Hz.
After upsampling to 800 Hz, the Nyquist frequency is 400 Hz.
If the signal is upsampled by inserting samples, the interpolated signal may introduce high-frequency components (between 100 Hz and 400 Hz) that could cause aliasing.
How to Prevent Aliasing during Upsampling:
- Zero Padding: Insert
M-1zeros between each original sample. For example, if you want to upsample by a factor ofM = 3, insert two zeros between each original sample. - Apply Interpolation Filter: After zero padding, apply a low-pass filter (such as an FIR filter) to remove any high-frequency components that might have been introduced during the interpolation process. This filter should have a cutoff at the Nyquist frequency of the new sampling rate.
Mathematical Standard for Upsampling:
fnew = M × fold
Where:
fnewis the new, higher sampling rate.foldis the original, lower sampling rate.Mis the upsampling factor.
Summary of Aliasing:
- Downsampling (decimation): Aliasing occurs when the signal contains frequency components above the Nyquist frequency of the new sampling rate, which will fold back into the lower frequencies. Low-pass filtering (anti-aliasing filter) before downsampling is necessary to avoid aliasing.
- Upsampling (interpolation): Aliasing occurs if the interpolation introduces high-frequency components that exceed the Nyquist frequency of the new sampling rate. This can be avoided by using a low-pass filter to remove any high-frequency components before or after interpolation.