# Sampling

## Introduction

In this chapter we will look at sampling and how it affects signal processing. Sampling is the process of taking a continuous stream of data with infinite points of resolution and getting that data into a form that can be stored in a finite data set.

## Sampling Overview

Imagine that we have a song that is being played in a studio. We would like to record the song and store it on a computer in form that will allow the song to be played back to sound as much like the original as possible. However, the song being played has an infinite set of points when it is played. We must throw out much of this data and yet keep enough to reconstruct the song. This is where sampling comes in. By taking evenly spaced out samples of the data stream, we can later reconstruct the stream of data. The sampler converts the continuous time signal x(t) into a discrete-time sequence x(n) by taking the values of x(t) at integer multiples of the sampling perioud, T. Typically, discrete signals are formed by periodically sampling a continuous time signal using the form:

There are, however, a few things that we need to keep in mind when trying to sample signals with many frequencies in them. When we sample data, we want to be able to sample enough data to get a correct reconstruction (this is discussed further below), but we donâ€™t want to sample too much data that our sets become unmanageable.

## Sampling Theory

According to Sampling Theory, you must sample fast enough that you eliminate all possible aliases that can occur from sampling. Aliasing is what happens when you sample a signal that can later be reconstructed with two possible frequencies. This can be seen by the picture shown below. Another example of this can be seen in older western movies when watching the spoked wheels of a stagecoach rotate backward at a slow rate. This happens when each frame of film is taken at a slightly faster rate than that of the rotating wheel. In order to sample fast enough to eliminate all possible aliases, you must sample at a rate greater than twice the maximum frequency found in the signal to be sampled.

Going back to our example of audio, we know that humans can hear from about 20 Hz up to about 20,000 Hz. Therefore we know that we want to make sure that we sample fast enough that we will get this entire frequency spectrum. In order to do this, we apply the principle where F is our highest frequency and T is our sampling rate to get a value of T = 40,000 Hz. This is also known as the Nyquist Theorem. This explains why audio that is recorded onto a CD is sampled at a rate of 44,100 Hz (they sample slightly higher than necessary for a 20 KHz max frequency).
Something to note here is the fact that even though we want to sample our signal for frequencies between 20 and 20,000 Hz, most signals have many more frequencies in them due to white noise. In order to make sure that only the desired frequency is sampled you can run your signal through a pre-filter (sometimes called an anti-aliasing filter). This guarantees that the sampled data system receives analog signals having a frequency spectrum no greater than those frequencies allowed by the filter.

To see how the sampled data is reconstructed, refer to my section on how a CD Player works.

## Sampling Process

In order to see how the sampling process works, imagine a periodic sequence of impulses,

Now multiply your signal by the impulses to form the sampled signal

After which the sampled signal is converted into a discrete-time signal by mapping the impulses that are spaced in time by into a sequence x(n) where the sample values are indexed by the integer variable n:

Principle author of this page: Shawn Santana