Sampling Simulation with MATLAB

7.2.5 Sampling Simulation with MATLAB

The simulation of sampling with MATLAB is complicated by the representation of analog signals and the numerical computation of the analog Fourier transform. Two sampling rates are needed: one being the sampling rate under study, f s , and the other being the one used to simulate the analog

signal, f sim >> f s . The computation of the analog Fourier transform of x(t) can be done approximately using the fast Fourier transform (FFT) multiplied by the sampling period. For now, think of the FFT as an algorithm to compute the Fourier transform of a discretized signal.

To illustrate the sampling procedure consider sampling a sinusoid x(t) = cos(2πf 0 t) where f 0 =1 KHz. To simulate this as an analog signal we choose a sampling period T sim = 0.5 × 10 −4 sec/sample or a sampling frequency f sim = 20, 000 samples/sec.

No aliasing sampling—If we sample x(t) with a sampling frequency f s = 6000 > 2 f 0 = 2000 Hz, the sampled signal y(t) will not display aliasing in its frequency representation, as we are satisfying the Nyquist sampling rate condition. Figure 7.7(a) displays the signal x(t) and its sampled version y(t), as well as their approximate Fourier transforms. The magnitude spectrum |X()| corresponds to the sinusoid x(t), while |Y()| is the first period of the spectrum of the sampled signal (recall the spec- trum of the sampled signal is periodic of period  s = 2πf s ). In this case, when no aliasing occurs, the first period of the spectrum of y(t) coincides with the spectrum of x(t) (notice that as a sinusoid, the magnitude spectrum |X()| is zero except at the frequency of the sinusoid or ±1 KHz; likewise |Y()| is zero except at ±1 KHz and the range of frequencies is [−f s / s 2, f / 2] = [−3, 3] KHz). In Figure 7.7(b) we show the sinc interpolation of three samples of y(t); the solid line is the interpolated values or the sum of sincs centered at the three samples. At the bottom of that figure we show the sinc interpola- tion, for all the samples, obtained using our function sincinterp . The sampling is implemented using our function sampling .

C H A P T E R 7: Sampling Theory

Analog signal Sampled signal

) (t

), y 0 1 Interpolated (t

sinc x −1

t (sec)

(t )x x −0.5

f (KHz)

t (sec) ×10 −3

(b) FIGURE 7.7 No aliasing: sampling simulation of x(t) = cos(2000πt) using f s = 6000 samples/sec. (a) Plots are of the signal

(a)

x(t) and the sampled signal y(t), and their spectra ( |Y()| is periodic and so a period is shown). (b) The top plot illustrates the sinc interpolation of three samples, and the bottom plot is the sinc-interpolated signal x r ( t) and the sampled signal. In this case x r ( t) is very close to the original signal.

Sampling with aliasing—In Figure 7.8 we show the case when the sampling frequency is f s = 800 < 2f s = 2000, so that in this case we have aliasing. This can be seen in the sampled signal y(t) in the top plot of Figure 7.8(a), which appears as if we were sampling a sinusoid of lower frequency. It can also be seen in the spectra of x(t) and y(t): |X()| is the same as in the previous case, but now |Y()|, which is a period of the spectrum of the sampled signal y(t), displays a frequency of 200 Hz, lower than that of x(t), within the frequency range [ −400, 400] Hz or [−f s / s 2, f / 2]. Aliasing has occurred. Finally, the sinc interpolation gives a sinusoid of frequency 0.2 KHz, different from x(t).

Similar situations occur when a more complex signal is sampled. If the signal to be sampled is x(t) = 2 − cos(πf 0 t) − sin(2πf 0 t) where f 0 = 500 Hz, if we use a sampling frequency of f s = 6000 > 2

f max =2f 0 = 1000 Hz, there will be no aliasing. On the other hand, if the sampling frequency is

f s = 800 < 2f max = 2f 0 = 1000 Hz, frequency aliasing will occur. In the no aliasing sampling, the spectrum |Y()| (in a frequency range [−3000, 3000] = [−f s / s 2, f / 2]) corresponding to a period of the Fourier transform of the sampled signal y(t) shows the same frequencies as |X()|. The recon- structed signal equals the original signal. See Figure 7.9(a). When we use f s = 800 Hz, the given signal x(t) is undersampled and aliasing occurs. The spectrum |Y()| corresponding to a period of the Fourier transform of the undersampled signal y(t) does not show the same frequencies as |X()|. The reconstructed signal shown in the bottom right plot of Figure 7.9(b) does not resemble the original signal.