# Demonstration of sampling

Demonstrating the real effect of sampling in the frequency domain.

*June 4, 2023*

Stairstep representation of digital signals is very common in audiophile magazines and forums. Such a representation is *not wrong, it's just misleading*, as we don't hear the "waveform" itself. Only spectral analysis can reveal the real effect of sampling and help answer questions related to perception.

With the following interactive tool the amplitude spectrum of a sampled sine wave can be analized. Quantization and low-pass filter at the output are missing from the model, so we only see the effect of sampling. We can choose between two types of sampling: zero-order hold and pulse (zero-order hold in Wikipedia ^{➚}). Detailed instructions can be found further down the page.

dBFS

**Quick guide - how to use this tool**

Set the level of the input signal to *0 dBFS* and the frequency to *10 kHz* (*10000 Hz*). Set the DAC output to *zero-order hold* and the sampling frequency to *44.1 kHz*. Select "Show frequency response". Then increase the frequency of the signal generator with the spin button and see what happens...

Sampling creates new frequency components (called images, image frequencies). If the sampled signal doesn't contain harmonics above the Nyquist frequency then the generated components (images) appear above the Nyquist frequency and they can be removed with a low-pass filter.

Nyquist frequency: half of the sampling frequency. At a sampling frequency of 44.1 kHz, the Nyquist frequency is 22.05 kHz.

If the sampled signal contains harmonics above the Nyquist frequency then certain image components appear below the Nyquist frequency (aliasing).

What happens to the signal at the Nyquist frequency, half of the sampling rate? If the signal frequency is equal to the Nyquist frequency, then the phase difference between sampling and sine wave also affect the level of the output signal and image components. Zero phase difference produces zero output, 90 degree phase produces maximum output (in fact, the output will be larger than the input). This is not included in the simulation, and it has no significance in real-life.

**The output window**

The output window displays the frequency spectrum of the sampled sine wave. The red lines are the image components, the blue line is the component with the same frequency as the original signal. We can call this component "signal", however, we should not forget that this is not the input signal (the input signal is not shown). Depending on the frequency and settings, the level of the blue line and the input signal may be the same or different.

**Amplitude spectrum of zero-order hold & pulse out**

The amplitude spectrum of a zero-order hold DAC is the absolute value of the sinc function ( sinc(x) = sin(x)/x ).

The amplitude spectrum of a pulse out is the absolute value of the sinc function as well, but its shape is shifted up in the frequency range according to the pulse width. If the pulse width is 1/10 of the sampling interval then the frequency response will be similar of a system with zero-order hold output running at 10x sample rate. There is also a gain loss. If the pulse width is 1/10 of the sampling interval then the gain loss is 20 decibels ( gain_loss = 20*log(10/1) ). (Changing the pulse width doesn't affect the frequency of the image components.)

**Benefit of oversampling**

Oversampling doesn't add new information to the sampled signal. In digital-to-analog converters, the benefit of oversampling is that the image components are moved to a higher frequency so a simple, low-order analog filter can be used to remove unwanted components. Mild roll-off of gain above 10 kHz (sinc response) is also corrected.

(Another advantage of oversampling: increasing the sample rate reduces quantization noise. Doubling the sampling rate lowers the quantization noise floor by 3 dB. This means that fewer bits are needed to map a certain dynamic range when the DAC is operating at a sample rate much higher than 44.1kHz or 96kHz.)

**Demonstration of oversampling (and the benefit)**

Set the level of the input signal to *0 dBFS* and the frequency to *20 kHz*. Set the DAC output to *zero-order hold* and the sampling frequency to *44.1 kHz*. We can see that the first image component is very close to the audio band (24.1 kHz). If we set the sample rate to *88.2 kHz* then the first image component moves up to 68.2 kHz and the level is slightly reduced. The level of the component at 20 kHz that represents the original signal is also corrected.

The following table shows the frequencies and levels of the first image component for various oversampling values. Frequency of the test signal is 20 kHz and the level is 0 dBFS.

Sample rate | Frequency [kHz] | Level [dBFS] |

44.1kHz | 24.1 | -4.78 |

88.2kHz (2 x 44.1kHz) | 68.2 | -11.4 |

176.4kHz (4 x 44.1kHz) | 156.4 | -18.05 |

352.8kHz (8 x 44.1kHz) | 332.8 | -24.47 |

This demonstration shows only the result and the benefit of oversampling, not the actual process. In reality, oversampling involves insertion of zero values and a low-pass filter. Insertion of zeros changes the level of image components, but doesn't affect their frequency. Original image components are removed by the resampling filter, a low-pass filter with a cut-off frequency set to the original Nyquist frequency (this filter is also called an interpolation filter because the waveform appears smoother after filtering).

**Filtering after the DAC is not required - only strongly recommended**

We can't hear image frequencies (the middle ear is a steep low-pass filter), so why bother with them? Image frequencies have to be removed due to their negative side effects. They may generate extra heat and distortion in amplifiers and tweeters.

Sampling at 44.1 kHz has an upper limit frequency of 22 kHz, sampling at 96 kHz has an upper limit frequency of 48 kHz with appropriate filtering. The frequency range where an amplifier should have low distortion corresponds to these values. If a non-oversampling DAC without a low-pass filter (aka interpolating filter) is used, the upper limit requirement for the low-distortion range goes up to at least 200 kHz.

**Browser support**

Minimum supported browser versions:

Chrome | Edge | Firefox | Opera | Safari |

26 | 12 | 49 | 15 | 7 |

Similar software:

Noise perception modeler (white noise)

Speaker Driver Simulation With Room Response