Sampling#

On a computer we are dealing with digital signals, that is, discrete signals. Sampling is the technique to transform a continious function

\[y: \mathbb{R} \rightarrow \mathbb{C}\]

into a discrete representation

\[y_{N}: \mathbb{Z} \rightarrow \mathbb{C}.\]

Loss of Information#

Indeed, that’s not quite precise enough because we represent all complex number or irrational numbers by floating point numbers. Therefore, for complex number \(z = a + ib\),

\[a, b \in \mathbb{Q}\]

holds (most of the time). Sampling in the context of audio means that we use equidistant sample points.

../../../_images/8f1acb24ddba90eea7d76b91a867dc2b9694fbbb306712b7885f5fd0358884d2.png

For example, let us assume our sample rate (also called sample frequency) \(f_s\) is 2 hertz (Hz). And let us assume we want to sample a sine wave \(y(t) = \sin(2\pi \cdot f \cdot t)\) with a frequency of 6 Hz, i.e., \(f = 6\). Then

\[y_N[0] \approx y(0), \ y_N[1] \approx y(0.5), \ y_N[2] \approx 1.0\]

and in general

\[y_N[n] \approx y\left(n \cdot \frac{1}{f_s} \right) = y(n \cdot T_s)\]

I indicate, that the value \(y_N[n]\) is only an approximation, since on a computer we use a certain bit depth of our floating point numbers! Therefore, we lose information, i.e. accuracy on two ends: (1) first of all in the time direction but also (2) in the amplitude direction.

Aliasing#

Calling

s.sampleRate // 44100 Hz

gives us the sample rate of our audio signals. On my machine, I use a sample rate of 44100 Hz, i.e. 44100 samples per second. Therefore, a audio signal \(y: \mathbb{N} \rightarrow \mathbb{Q}\) represents 1 seconds by 44100 samples (rational numbers)

\[y[i], y[i+1], \ldots, y[i+44099].\]

When the highest frequency of a signal is less than one-half of the sample rate, the resulting discrete-time sequence is said to be free of the distortion known as aliasing (different signals become indistinguishable to each other). This follows from the so called Nyquist–Shannon sampling theorem.

Nyquist–Shannon Sampling Theorem

If a function \(y(t)\) contains no frequencies higher than \(f\) hertz, it is completely determined by giving its ordinates at a series of points spaced \(1/(2f)\) seconds apart.

Aliasing can also generate frequencies that are not truly present. To avoid aliasing, the sampling rate must be more than twice the highest frequency of the sampled signal.

Aliasing

Aliasing is the effect that result from a two small sample rate by which different signals become indistinguishable to each other.

In the example above we can observe aliasing. We can see that a sample rate of 1 Hz is too low to capture \(y(t) = \sin(2\pi \cdot f \cdot t)\) for \(f = 2, 3, 6\) Hz. All these sine waves appear to be a sine wave of 1 Hz. They are indistinguishable if we use a sample rate that low.

../../../_images/67e6a2be3d7c44ec0b104a98c7869cc85fc03c36493de1ba8e0495d9f0c76d00.png

The human ear is able to recognize frequencies up to round about 20000 Hz. Since we need double the sample rate, 44100 gives us a little bit of room.