Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Sampling Essentials Bilingual

In this section, we explore how analog signals are converted into digital representations and vice versa.

Continuous-time signal

A continuous-time signal is characterised by having a value x(t)x(t) for every possible time tt. Informally: You draw a continuous-time signal without lifting your pen from the paper.

Sampling

Storing a continuous-time signal on a computer requires an infinite amount of memory. To solve this, we only measure the value of a continuous-time signal every TsT_\text{s} seconds. This is called sampling.

fs=1/Tsf_\text{s} = 1/T_\text{s}

where fsf_\text{s} is the sampling frequency (Hz) and TsT_\text{s} is the sampling time (seconds).

Discrete-time signal

A discrete-time signal only has a value xnx_n at certain times tn=nTst_n = nT_\text{s}. The xx-axis is often the sampling index nn.

Reconstruction

Converting a discrete-time signal xnx_n back into a continuous-time signal x(t)x(t) is called reconstruction. This is typically done using:

  1. Hold circuit: Creates a staircase signal.

  2. Post filter: Smooths the signal using a low-pass filter with a cut-off frequency of fs/2f_\text{s}/2.

Aliasing

Aliasing occurs when a sinusoidal component of one frequency disguises itself as another frequency due to insufficient sampling.

Python
MATLAB
01-Sampling-Reconstruction-Resampling.py
import numpy as np
import matplotlib.pyplot as plt

def sinusoid(samplingIndices, digitalFreq):
    '''Compute a cosine'''
    return np.cos(2*np.pi*digitalFreq*samplingIndices)

nData = 100
samplingFreq = 100 # Hz
samplingTime = 1/samplingFreq # s
samplingIndices = np.arange(nData)
time = samplingIndices*samplingTime
freqA = 10 # Hz
freqB = 90 # Hz (samplingFreq-freqA)

# plot the results
plt.figure(figsize=(10,6))
plt.plot(time, sinusoid(samplingIndices,freqA/samplingFreq), linewidth=2, marker='o', label="$x(t)$")
plt.plot(time, sinusoid(samplingIndices,freqB/samplingFreq), linewidth=2, marker='o', label="$y(t)$")
plt.legend()
plt.xlim((time[0],time[nData-1])), plt.ylim((-1.5,1.5))
plt.xlabel('time [s]'), plt.ylabel('Amplitude [.]');

Nyquist-Shannon sampling theorem

To avoid aliasing, the maximum frequency fmaxf_\text{max} in a continuous-time signal must satisfy:

2fmax<fs2f_\text{max} < f_\text{s}

Quantisation

Quantisation is the process of rounding the signal values to a finite number of levels so they can be stored on a computer.

Signal-to-Noise Ratio (SNR)

The SNR characterizes the quantisation quality:

SNR6β dB\text{SNR} \approx 6\beta \text{ dB}

where β\beta is the number of bits.