Tuesday, October 15, 2019

Singal Processing 101, Sampling

Although often deemed as simple and easy to understand, Shannon's sampling theorem is absolute the most important pillar that underpins the whole modern digital world.  It is never too much to emphasize this!

Signal which is band limited by $W$ can be fully determined by discrete samples with interval less than $\frac{1}{2W}$ seconds:

\[f(t)=\sum_{n=-\infty}^{+\infty}f({n \over 2W})\frac{\sin\pi(2Wt-n)}{\pi(2Wt-n)} \]

This is the very bridge connects the math living your computer program to physical world ! The theory has quite a few interesting points worth to discuss. We will get them later, for now, let us get an impression of this ${\rm sinc}(2Wt)$ function.

Two features of this function are very important
1. $h(n/2W) =0$ for $n \neq 0$
2. Alternate sign of peaks, but decrease slowly.

On ADC sampling rate

Sampling theorem says if we align each sample at the peak, we can get full signal only if the signal change slow enough (bandwidth is less than W). In real application, it means if the ADC sampling rate is fast enough (at least 2W), the samples we get retain all the information of the signal.  A natural question would be: whether sampling rate 2W would be enough ?

Practically, the sampling rate should be strictly greater than 2W.  There are two important factors limiting on how slow an ADC sampling rate can be.  First, the anti-aliasing filter and Second, the latency / history we need to reproduce the signal.

Suppose the signal is very clean and has nothing beyond W on the spectrum, and if the sampling rate is 2W, we have to use sinc(t) to reconstruct the signal. However, sinc(t) decays two slowly and in order to get a value accurately, we have to use large amount of previous and future samples, which typically becomes impractical.

In addition, the analog anti-aliasing filter usually plays a more important role on selecting the sampling rate, as often, the signal is not clean enough, there are a lot of interference component on the spectrum beyond W.   Following picture show the digital spectrum if there is only a second order Butterworth filter and the sampling rate is around 4W:
The second highest peak is the folded image component from a down converter which is at 22.7MHz, the sampling rate is 5MHz.

The choice of analog filter depends a quite a lot of system constrains, like the phase linearity, stop band performance, pass band performance, and implementation cost etc.  But choose the sampling rate to be at least 4W gives an octave of decay at the image frequency (sampling rate).

Higher sampling rate will relax the requirement on analog anti-aliasing filter, and help to reduce the quantization noise, or equally, quantization levels (by oversampling and decimation). But chips start to be expensive beyond 1MHz.

On aliasing 

Sampling a continuous signal $f(t)$ at a cycle of 1/2W seconds means that the spectrum of $f(t)$, $\hat{f}(f)$ is repeated every 2W Hz.   If $f(t)$ is band limited to W, it will look like this:
 However, if the spectrum of $f(t)$ exceeds W, it will look like
as we can see, no matter what filtering is applied to the signal, there is no way to reverse the alias.

As aforementioned, there might be a lot of interference on the spectrum along with the useful signal, e.g, image component of the mixer (frequency multiplier), 2nd order harmonics, and 3rd order harmonics, appropriate filtering will help to remove/attenuate these unwanted components, so that the digital spectrum is not polluted by aliasing.

Following two figures shows how anti-aliasing filter affects the output of ADC





As we can see, ensure sufficient attenuation on interference/unwanted signal is key for a clean digital signal.  Increase the sampling rate will relax the design constrains on this filter.

On bandpass sampling

Because of the spectrum of digital signal will repeat every 2W Hz, (cycle with 2W), sampling $\sin((2kW+\omega_0)t)$ with sampling rate 1/2W will produce the exact same data as sampling  $\sin(\omega_0t)$. Above figure also illustrates this: the gray unwanted signal has a very high frequency, but after sampling, it ends at the position (on the spectrum) as if we sample a signal lower than the blue signal.

This sparks a very interesting fact: for a narrow band passband signal, by carefully select the sampling rate, direct sampling the passband signal is the same as sampling the down converted signal.  But direct sampling does not need the mixer and the low pass anti-aliasing filter. Instead a bandpass filter at higher frequency is required, which is easier and cheap to implement.

Assignment: Use simpleFE to build a bandpass sampling example.