SIGNALS and SYSTEMS LABORATORY 10: Sampling, Reconstruction, and Rate Conversion
Total Page:16
File Type:pdf, Size:1020Kb
SIGNALS AND SYSTEMS LABORATORY 10: Sampling, Reconstruction, and Rate Conversion INTRODUCTION Digital signal processing is preferred over analog signal processing when it is feasible. Its advantages are that the quality can be precisely controlled (via wordlength and sampling rate), and that changes in the processing algorithm are made in software. Its disadvantages are that it may be more expensive and that speed or throughput is limited. Between samples, several multiplications, additions, and other numerical operations need to be performed. This limits sampling rate, which in turn limits the bandwidth of signals that can be processed. For example, the standard for high fidelity audio is 44,100 samples per second. This limits bandwidth to below the half-sampling frequency of about f0 / 2 = 22 kHz, and gives the processor only 22.7 microseconds between samples for its computations. It should be noted here that the half-sampling frequency f0 / 2 may also be referred to as the Nyquist frequency and the sampling rate f0 may be referred to as either the Nyquist sampling rate, Shannon sampling rate, or critical sampling rate. In order to do digital signal processing of analog signals, one must first sample. After the processing is completed, a continuous time signal must be constructed. The particulars of how this is done are addressed in this lab. We will examine i. aliasing of different frequencies separated by integer multiples of the sampling frequency, ii. techniques of digital interpolation to increase the sampling rate (upsampling) and convert to continuous time, iii. sample rate conversion using upsampling followed by downsampling. The highest usable frequency in digital signal processing is one half the sampling frequency. In practice, however, undesirable effects creep in at frequencies below the half sampling frequency. (This typically happens near 90% of f0 / 2. This is why the standard for audio is 44kHz instead of 40 kHz.) We shall observe this phenomenon and explain it. SAMPLING IN TIME, ALIASING IN FREQUENCY x(t) x[k] 1 f0 = samples/second t 0 Figure One Sampling Figure One is a representation for the sampling operation. The input signal is analog and continuous time. The output signal is typically digital, i.e. quantized, but we will ignore the fact that the output samples are finite words of digital data and not real numbers. The part that interests us is that the signal x[k] is discrete time. The input signal x(t) is continuous time and has a Fourier transform. Fourier (1) x(t) ←→ X ( jω) The discrete time output signal x[k] has a DTFT. The time and frequency representations for this signal are ∞ DTFT 1 2π (2) x[k] = x(kt ) ←→ X (e jω t0 ) = X ()j(ω − nω ) , ω = = 2π f . 0 t ∑ 0 0 t 0 0 n=−∞ 0 Page 1 of 19 The time domain relation on the left-hand side of equation (2) is very simple, but the frequency domain relation on the right hand side is not. It is far more interesting. All the spectral components of X(jω) at frequencies that differ by an integer multiple of the sampling frequency are added together. Thus one cannot distinguish these spectral components from the samples x[k]. If the sampling frequency is f0, then for every sinusoid of frequency f there is another sinusoid of frequency f + f0, which has the same samples. The same is true for f + 2f0 , f + 3f0 , and so on. All of these sinusoids go by the same alias, namely the sinusoid of frequency f. We will observe this phenomenon of aliasing experimentally. This is demonstrated in Figure Two below. x(t) |X(jω)| 1 0.5 0.4 0.5 0.3 0 0.2 -0.5 0.1 -1 0 0 1 2 3 4 5 -20π 0 20π ∞ ω [rad/sec] jω t0 1 X (e ) = X ()j(ω − nω0 ) x[k] = x(kt0 ), t0 = 0.05 sec. t0 ∑ n=−∞ 1 5 4 0.5 3 0 2 -0.5 1 -1 0 × × 0 20 40 60 80 100 -60π -40π -20π 0 20π 40π 60π ω [rad/sec] Figure Two Sampling In Time, Aliasing In Frequency A few comments about Figure Two. The continuous-time signal x(t) is a dampened sinusoid defined by (3) x(t) = e−t sin(10t)u(t), were u(t) is the unit step function. This signal could be an example of a natural response of an underdamped parallel RLC circuit. The spectrum of x(t) is a commonly known Laplace transform given by 10 (4) X ( jω) = X (s) = s= jω 2 s − 2s +101 s= jω which is shown in the upper right panel of Figure Two. From this graph, it can be seen that X(jω) is essentially bandlimited to the frequency band –20π ≤ ω ≤ 20π. This is to say that the frequency components |ω | > 20π contain much less energy than the frequency components of |ω | ≤ 20π. In practice, the signal x(t) will be guaranteed to be Page 2 of 19 bandlimited by an analog lowpass filter called an anti-aliasing filter. The Shannon sampling theorem then says that we need to sample at a rate twice the maximum frequency component of our bandlimited signal. In our case, this ω0 2π 1 means that our sampling frequency will be ω 0 = 40π. (Also, f0 = = 20 Hz, and t0 = = = 0.05sec .) In 2π ω0 f0 accordance with the Shannon sampling theorem, x(t) was sampled at rate ω 0 = 40π rad/sec. The sample data signal is shown in the lower left panel of Figure Two and the accompanying discrete-time frequency response is shown in the lower right panel. Notice the marks on the frequency axis of the lower right panel. These marks show where the aliases of the original signal are centered. As the sampling rate increases, the center frequencies of the X(jω) aliases will move farther away from the original signal’s spectrum. In Figure Two, the sampling frequency ω 0 prevents a noticeable overlap of aliases, leaving X (e jω t0 ) looking essentially like X(jω). Thus aliasing effects are minimized. Aliasing effects due to undersampling amount to a set of samples that appear to be the samples of a signal with a lower frequency, hence the term alias. This is to be avoided since these effects cannot be removed in digital processing. To prevent this, one should sample at the Nyquist sampling rate or higher. THE DISCRETE-TIME TO CONTINOUS TIME RECONSTRUCTION PROCESS Let us state an unwelcome fact. Given the input x(t), one can easily get the output samples x[k], but the reverse is not true. Given the output samples, we cannot reconstruct the input without knowing extra information, because we have thrown out everything between the samples. Obviously there are infinitely many ways to fill in the gaps between samples. The sampling operation is many to one, and is not generally invertible. However, if the input is bandlimited to the half sampling frequency, then there will be exactly one input signal x(t) for the given set of samples. This is the Shannon sampling theorem, and the bandlimited reconstruction is ∞ x(t) = x[k]h(t − kt ) (5) ∑ 0 , where h(t) = sinc(π t / t0 ). k=−∞ Equation (5) represents the ideal. It is the goal of a good analog reconstruction design to approximate this relation. Therefore, make note of two things: first, equation (5) is a pulse amplitude modulation (PAM) equation, and second, the PAM pulseshape is that of the sinc function, or Shannon wavelet. The sinc function in question is the impulse response of an ideal lowpass filter with gain equal to the sampling period t0 , and bandwidth one half the sampling frequency, hence the term bandlimited reconstruction. One departure from the ideal is allowed in audio systems. Time delay is of no consequence, and therefore one can use a delayed sinc pulse. In digital feedback control systems however, time delay can present stability problems and is to be avoided. The time domain process of reconstructing x(t) from its samples x[k] is demonstrated in Figure Three below. Page 3 of 19 x[k] h(t) = sin(πt/t0) / (πt/t0) 4 1 3 0.5 2 0 1 0 -0.5 -3 -2 -1 0 1 2 3 -5 0 5 x(t) = x[k] h(t - kt ) Σ 0 4 3 2 1 0 -1 -4 -3 -2 -1 0 1 2 3 4 Figure Three: A PAM implementation of Bandlimited Reconstruction In Figure Three above, a random discrete time sequence x[k] was created that is seven samples long. This finite sequence was then reconstructed using Shannon reconstruction. This might be called ideal construction. Notice in the upper right panel that t0 = 1 sec, since the zero crossings of h(t) occur at 1 second intervals. From this, it can be inferred that a continuous time signal x(t) was sampled at a rate of one sample per second (f0 = 1 Hz and ω 0 = 2π rad/sec) to generate x[k]. PRACTICAL RECONSTRUCTION METHODS: THE DIGITAL PIECE The basic electronic element used in converting a discrete time digital signal to a continuous time analog voltage signal is called a digital to analog converter or DAC. If the conversion is very fast, then the output of the DAC will be essentially constant between sample times, and look like a sequence of up/down stair steps. We shall see that this signal has undesirable high frequency artifacts. For a sample rate of 4 kHz, for example, the DAC output will sound artificial with high frequency tinny sounds that aren’t in the right harmonic relation to the original signal.