# Does a 20 kHz sine wave sampled at 44.1 kHz need to be reconstituted before playback?

I am interested in building a synthesizer but I am confused about the Nyquist-Shannon Theorem and sampling rates.

If I sample a 20 kHz sine wave at 200 kHz and plot the data points, the plot looks similar to that of the true signal. But, many websites I have read reference the Nyquist-Shannon theorem and say audio only needs to be recorded at twice the frequency or higher of the highest frequency one expects to record (or 40+ kHz since humans cannot hear audio frequencies greater than 20 kHz). When I plot the data from sampling the wave at 44.1 kHz, it looks nothing like a sine wave.

Before playing a 20 KHz sine wave sampled at 44.1 kHz on my speakers, must I do something to to reconstitute the original signal from the samples?

What confuses me is that I have seen microcontrollers play audio (.wav files) without reconstructing a signal, simply by taking sample data and playing it at the sample rate -- but I don't think that method will work if the frequency of an audio signal is close to half of the sampling frequency. I have found a lot of literature about sampling rates but nothing about playback rates.

• You need to read about "interpolation". Digital to analog conversion is only superficially like plotting: a digital sound system does not "join the samples" using straight lines when generating analog audio; it performs a more complex calculation, called "interpolation".
– MBaz
Jul 4, 2017 at 23:14

By the theory of sampling, sampling a signal in the time domain results in periodisation of this signal in the frequency domain, at the period Fs (where Fs is your sampling frequency). Shannon-Nyquist's theorem explains that in order to not loose information when sampling a signal, there shouldn't be overlapping of the periodic repetitions of the signal's spectrum. Considering that the period of repetition is Fs, the total width of your signal's spectrum should exceed Fs.

Moreover, analog signals are real which means their spectrum is symetric relatively to the f=0Hz axis. Thus, if your signal's FT must have a maximum width of Fs, it means that your maximum frequency to avoid overlapping should be Fs/2.

# Reconstruction filter

Now that your signal is correctly sampled i.e. there is no overlapping of the spectrum patterns in the frequency domain, you want to reconstruct it in the analog domain for example for audio playback. As explained before, sampling results in a periodisation of the analog signal's spectrum. That means that to go back to a continuous signal, you have to extract only one of the periods of your signal. To do that without distorting your signal, you need an ideal brick-wall filter (infinitely sharp transition band) called a reconstruction filter. Unfortunately, such a perfect filter is impossible to obtain. Indeed, its impulse response is a cardinal sine (Fourier transform of a gate) which by definition is infinite on both sides of the central lobe.

It can however be approached with very high order FIR filters or convolution with a windowed sinc (this is a pretty deep subject, there's plenty of resources on the internet).

# Answer to the original question

Depending on the quality of your reconstruction filter, sampling your signal close to Nyquist will indeed result in a distorted signal. That doesn't mean Nyquist theory is wrong, it is only theory. Depending on your DAC, you often want to oversample your signal if you need very high fidelity. Again, sampling you signal at a higher frequency will result in a periodisation of the signal at a longer period, which basically gives more space for your filter's transition band. The wider the transition band, the more oversampling you will need. As an example, the linear interpolation that your plotting software uses has the frequency shape of a squared sinc. It will thus completely distort your signal.

20 to 30 years ago, a typical audio range D/A converter would have a zeroth order hold (stair step) output which is what you might be concerned about.

A modern audio D/A will be upsampled and appropriately filtered, so it shouldn't be a problem.