In this lesson, you will learn how to calculate the minimum sampling frequency required to digitize an analog signal without losing critical information or creating artifacts.
Understanding the Nyquist-Shannon Limit
When we convert an analog signal—like a sound wave or a sensor reading—into a digital format, we use an Analog-to-Digital Converter (ADC). If we sample too slowly, high-frequency components of the original signal can "masquerade" as lower frequencies, a phenomenon known as aliasing.
The Nyquist-Shannon Sampling Theorem states that to perfectly reconstruct a periodic signal, your sampling frequency () must be strictly greater than twice the highest frequency () present in the signal. This threshold, , is known as the Nyquist rate.
Calculating the Minimum Sampling Frequency
If you are monitoring a signal with a maximum frequency component of 1 kHz, your sampling frequency must satisfy:
In practice, we often sample slightly higher than the absolute minimum to account for real-world filter imperfections. If your system runs a periodic interrupt to trigger an ADC conversion, you must configure your timer to fire at this calculated rate:
// Example: If f_max = 500Hz, we need f_s > 1000Hz
// Setting timer frequency to 1200Hz to stay safely above Nyquist rate
void Timer_Config_For_Sampling(void) {
uint32_t sampling_freq = 1200;
// Configure hardware timer to trigger ADC at 1200Hz
Timer_Set_Frequency(sampling_freq);
Timer_Enable_Interrupt(ADC_Trigger_Callback);
}
Why This Matters for Embedded Systems
If you sample a 1 kHz sine wave at only 800 Hz, the resulting digital data will contain a "ghost" signal at 200 Hz. Because the digital system cannot distinguish this ghost from a true 200 Hz signal, you have introduced noise that you cannot remove later. By ensuring your sampling rate is at least double your highest expected frequency, you preserve the integrity of your input data, allowing your algorithms to process the signal accurately without aliasing distortion.
Key Takeaway: To avoid aliasing, always configure your sampling peripheral to operate at a frequency strictly greater than twice the highest frequency component of your analog signal.