Nyquist-Shannon Sampling Theorem

It’s safe to say that the invention of the computer has changed the world we live in forever. Digital technology is so pervasive in modern life that it’s hard to imagine what things were like before this revolution occurred. Digital audio technology has made huge advances in the last 20 years as well. We now have the ability to record and transmit digital audio wirelessly, which is a miracle in and of itself. In this article, we’re going to dig a little deeper into a fundamental theorem in the realm of signal processing that plays an integral role in making this possible – the Nyquist-Shannon Sampling Theorem.

Background Knowledge

In order to understand what the Nyquist-Shannon Sampling Theorem means, we need a fundamental understanding of waveform theory. An analog electrical waveform is AC electricity that flows through an electrical circuit. The waveform has several important properties we need to recognize.

Frequency

Frequency is probably the most important term you’ll come across if you want to understand the Nyquist-Shannon Sampling Theorem. It is the number of full cycles that the waveform achieves in 1 second. The unit for frequency is Hertz, Hz, or cycles per second. When we say “cycle” we simply mean the passing of one peak and one trough of the waveform.

Think of a waveform like a ripple in a pond, or waves on the surface of the ocean. The frequency is simply the number of waves that pass over a fixed point every second. The period T is 1 divided by the frequency, and expressed in seconds.

Oscillating sine wave

Amplitude

Amplitude is the height of the waveform. In this case, it’s expressed as a voltage. We can see the waveform starts its cycle at 0 Volts. A quarter of the way through the cycle, at 90 degrees (we’ll explain that in a minute), the waveform is at its maximum amplitude. At 180 degrees, it’s back at 0 Volts. At 270 degrees, it’s at its lowest point. And at 360 degrees it’s back at 0 Volts and begins repeating the cycle at 0 degrees afterwards.

Phase

The phase of the waveform describes what position the waveform is in its cycle. It’s somewhat less important for understanding the Nyquist-Shannon Sampling Theorem, but important nonetheless for digital audio and signal processing. It’s expressed in degrees because if you place a point on the outside of a circle and spin the circle around, the position of the point can be expressed as an angle in degrees between the center of the circle and the horizontal axis.

The animation below shows one full waveform cycle. It starts with Point A at 0 degrees and Point B at 180 degrees. These two are said to be 180 degrees out of phase. As the waveform cycle progresses, we can see each point pass through all of the positions on the circle. The frequency here is how many full revolutions the circle will makes per second (without the pause).

Out of phase AE

Transducers

So we know that we can define analog AC electrical waveforms by their frequency, amplitude, and phase. But where do they come from? And why are they important?

Analog AC waveforms come from transducers. These are devices that convert differences in energy into electricity. Ribbon and condenser microphones are examples of electroacoustic transducers that convert vibrations in the air called sound into electricity. Speakers and studio monitors work in reverse, converting an electrical waveform into sound.

Here’s the problem, though. Computers don’t like continuous analog waveforms. They like digital information – 0s and 1s. So how do we convert an analog waveform coming from a microphone into something a computer can understand? Analog-to-digital (ADC) conversion, of course. This is where it all comes together and the Nyquist-Shannon Sampling Theorem comes into play.

Sampling & Analog-to-Digital Conversion

ADCs and DACs are found in many modern audio devices. Anything that plays MP3 files has a DAC inside it that converts binary MP3 files into analog audio signals that speakers and headphones can then convert into sound.

ADCs are found all over too. For musicians and producers, we know them from our audio interfaces. These devices contain both ADCs and DACs, but to understand the Shannon-Nyquist Sampling Theorem, we want to focus on ADCs.

The ADC performs a process called sampling. Sampling is where we take the continuous analog electrical waveform and take snapshots of the waveform’s amplitude at a fixed number of times per second, called the sample rate.

If you look at the first image above, you’ll see some small dots on the waveform. Each of these dots is defined by an amplitude (Y-axis) and a time (X-axis). They’re called samples, and connecting the samples gives us an approximation of the original sampled waveform. The equation is telling us that the sample period (time between samples) is equal to the inverse of the sample rate, where sample rate is also in Hz (samples taken per second). The samples are used to reconstruct the analog signal.

Understanding the Nyquist-Shannon Sampling Theorem

The Nyquist-Shannon Sampling Theorem has to do with the relationship between the sample rate of the ADC and the maximum waveform frequency that can be sampled. It states that the sample rate required to completely capture and reconstruct all of the information in a continuous waveform must be greater than two times the maximum frequency present within that continuous waveform.

So let’s say our waveform is 200 Hz. In order to successfully convert this analog signal to a digital signal and back without distortion, we need to use a sample rate that is greater than 400 Hz.

Human hearing is limited to roughly 20,000 Hz, so the sample rate needed to capture all of the data present in the range of human hearing would be anything greater than 40,000 Hz. This means the standard 44.1 kHz sample rate for CD quality audio is more than enough to accurately capture everything in the realm of human hearing. But what happens if we don’t meet this requirement?

Aliasing

Aliasing occurs when the maximum sampled frequency is above the Nyquist frequency, which is 1/2 the sample rate. Since the sampling isn’t fast enough, it’s not capable of capturing the analog audio signal fully. When the sampled digital signal gets sent back through a DAC, it ends up being distorted.

AliasingSines

Here, we can see aliasing in action. The red waveform is the original analog waveform we want to sample. The black dots are where samples are taken. We can see that the sample period (time between samples defined by sample rate) is too low. This results in the reproduction of a sinusoidal waveform at a much lower frequency (the blue waveform), at the alias frequency.

Anti-aliasing Filters

Alias frequencies can appear in the reconstructed signal anytime we try to sample a waveform that contains frequencies higher than 1/2 the sample rate (frequencies above the Nyquist frequency). Alias frequencies can also be much lower than the maximum sampled frequency, making their way back into the part of the frequency spectrum we’re interested in in the reconstructed signal and causing distortion.

To get around this, engineers add anti-aliasing filters to the signal before it’s sampled. This cuts out any high-frequency noise that could otherwise cause alias frequencies and artifacts to be present in the reconstructed signal.

For example, let’s say an audio signal contains frequencies up to 30 kHz. We’re only interested in frequencies below 20 kHz because anything above that is inaudible. If we’re using a sample rate of 44.1 kHz, the Nyquist frequency is 22.05 kHz. This means the extra 7.95 kHz of bandwidth above the 22.05 kHz Nyquist frequency has the potential to cause aliasing. A low-pass filter, the anti-aliasing filter, needs to be applied to the sampled signal to remove everything over 22.05 kHz.

Spread the Love
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
There are currently no comments.