Sie sind auf Seite 1von 6

The Hong Kong Polytechnic University

Department of Electronic and Information Engineering


EIE312: Linear Systems
LS105: Sampling

The sampling theorem specifies conditions under which a bandlimited continuous-time signal can be
completely represented by discrete samples. The resulting discrete-time signal x[n] = x(nT) contains all
the information in the continuous-time signal x(t) so long as the continuous-time signal is sufficiently
bandlimited in frequency, i.e., X(ω) = 0 for |ω| ≥ π/T. When this condition is satisfied, the original
continuous-time signal can be perfectly reconstructed by interpolating between the samples of x[n]. If
x[n] satisfies the sampling theorem, it is possible to process x[n] entirely in discrete-time to obtain the
samples that would have resulted from sampling x(t) at a different rate. This processing is known as
sampling rate conversion. Working with sampled data, together with the flexibility of discrete-time
systems, leads to a powerful strategy for implementing continuous-time LTI systems known as “discrete-
time processing of continuous-time signals.” In this technique, a bandlimited continuous-time input
signal is sampled, the resulting samples are processed by a discrete-time system, and then the output
samples of the discrete-time system are interpolated to give the continuous-time output signal; the overall
system is shown in Fig. 1.

In this laboratory exercise, you will explore the issues involved in sampling and reconstructing signals.
These include:
(1) examination of the importance of the continuous-time signal being appropriately bandlimited;
(2) comparison of two practical approximations to the ideal interpolation filter, and
(3) using LabVIEW to observe the effect of sampling rate to the reconstructed signals.

xc(t) x[n] y[n] yc(t)


C/D Hd(ejω) D/C

T T
Fig. 1 Discrete-time processing of a continuous-time signal.

1. Aliasing due to Undersampling


You will investigate the effects of aliasing due to sampling on signals reconstructed by bandlimited
interpolation. If a continuous-time signal x(t) is sampled every T seconds, then its samples form the
discrete-time sequence x[n] = x(nT). The Nyquist sampling theorem states that if x(t) has bandwidth less
than half of ωs = 2π/T, i.e., X(ω) = 0 for |ω| > ωs/2, then x(t) can be completely reconstructed from its
samples x(nT). The bandlimited interpolation or signal reconstruction is most easily visualized by first
multiplying x(t) by an impulse train

x p (t ) = x(t ) t = nT = ∑ x(nT )δ (t − nT ) .
n = −∞
(1)

The signal x(t) can be recovered from xp(t) by filtering xp(t) with an ideal lowpass filter with cutoff
frequency ωs/2. Define xr(t) to be the reconstructed signal given by lowpass filtering xp(t). If the
bandwidth of x(t) is greater than ωs/2, then the samples x(nT) do not completely determine x(t), and xr(t)
will not generally be equal to x(t). In the following problems, you will examine the effects of
undersampling a pure sinusoid and a chirp signal.

EIE/PolyU/LS105_Sampling/March2007 1
Problems
Consider the sinusoidal signal
x(t) = sin(ω0t).
If x(t) is sampled with the frequency ωs = 2π/T rad/sec, then the discrete-time signal x[n] = x(nT) is equal
to
x[n] = sin(ω0nT).

Assume the sampling frequency is fixed at ωs = 2π(8192) rad/sec.

(a) Assume ω0 = 2π(1000) rad/sec and define T=1/8192. Create the vector n=[0:8191], so that
t=n*T contains the 8192 time samples of the interval 0 ≤ t < 1. Create a vector x which contains
the samples of x(t) at the time samples in t.

(b) Display the first fifty samples of x[n] versus n using stem. Display the first fifty samples of x(t)
versus the sampling times using plot. (Use subplot to simultaneously display these two plots.)

Note that plot(t,x) displays a continuous-time signal given the samples in x, using straight lines to
interpolate between sample values. While this interpolation is not generally equal to the bandlimited
reconstruction which follows from the sampling theorem, it can often be a very good approximation.

To compute samples of the continuous-time Fourier transform of the bandlimited reconstruction xr(t), use
the following function:

function [X,f] = ctfts(x,T)


% CTFTS calculates the continuous-time Fourier transform (CTFT) of a
% periodic signal x(t) which is reconstructed from the samples in the
% vector x using ideal bandlimited interpolation. The vector x
% contains samples of x(t) over an integer number of periods, and T
% contains the sampling period.
%
% The vector X contains the area of the impulses at the frequency
% values stored in the vector f.
%
% This function makes use of the relationship between the CTFT
% of x(t) and the DTFT of its samples x[n], as well as the
% relationship between the DTFT of the samples x[n] and the DTFS of x[n].
N = length(x);
X = fftshift(fft(x,N))*(2*pi/N);
f = linspace(-1,1-2/N,N)/(2*T);

This function uses fft to calculate the Fourier transform of the reconstructed signal. The M-file ctfts.m is
provided, and should be placed in your MATLABPATH.

(c) Use [X,f]=ctfts(x,T) to calculate the continuous-time Fourier transform of the reconstructed
signal xr(t). Plot the magnitude of X versus f. Is X nonzero at the proper frequency values? (Note
that almost all the elements in X are nonzero, but most are small values due to numerical round-
off errors.) Is the phase of X correct, assuming that the phase is equal to zero when X is nearly
zero, i.e., nonzero only due to round-off error?

(d) Repeat Parts (a)-(c) for the sinusoidal frequencies ω0 = 2π(2000) and 2π(3000) rad/sec. Again, is
the magnitude of X nonzero for the expected frequencies? Is the phase of X correct?

(e) Play each of the sampled signals created in Part (d) using sound(x,1/T). Does the pitch of the
tone that you hear increase with increasing frequency ω0? Note that, like plot, the function

EIE/PolyU/LS105_Sampling/March2007 2
sound performs interpolation. In essence, your computer converts the discrete-time signal in
MATLAB into a continuous-time signal on its speaker.

(f) Now repeat Parts (a) and (c) – do not repeat Part (b) – for the sinusoidal frequencies ω0 =
2π(4000), 2π(5000), and 2π(6000) rad/sec. Also play each sampled signal using sound. Does the
pitch of the tone that you hear increase with each increase in the frequency ω0? If not, can you
explain this behavior?

Now consider the signal


1 2
x(t ) = sin(ω 0 t + βt ) , (2)
2
which is often called a chirp signal due to the sound it makes when played through a loudspeaker. The
“chirp” sound is due to the increasing instantaneous frequency of the signal over time. The instantaneous
frequency of a sinusoidal signal is given by the derivative of its phase, i.e., the argument of sin(⋅). For the
chirp signal, the instantaneous frequency is
d  1 2
ω inst (t ) =  ω 0 t + βt 
dt  2 
= ω 0 + βt

Assume for the following problems that ωs = 2π(8192) rad/sec:

(g) Set ω0 = 2π(3000) rad/sec and β = 2000 rad/sec2. Store in the vector x the samples of the chirp
signal on the interval 0 ≤ t < 1.

(h) Use sound to play the chirp signal contained in x. Can you explain what you just heard?

(i) Determine the approximate time sample at which the chirp signal has its maximum pitch. Given
the linear equation for instantaneous frequency and your understanding of aliasing, explain how
you could have predicted this time sample.

(j) Store in x the samples for the first 10 seconds of the chirp signal. Play the signal using sound.
Explain how you could have predicted the times at which the played signal has zero (or very low)
frequency.

2. Signal Reconstruction from Samples


This section covers the reconstruction of a signal x(t) from its samples x(nT), where T is the sampling
period and n is any integer. As discussed, if x(t) has bandwidth less than ωs = 2π/T, then x(t) can be
completely recovered by lowpass filtering the pulse train sampling of x(t):

x p (t ) = ∑ x(nT )δ (t − nT ) .
n = −∞

The lowpass filter used to reconstruct x(t) from xp(t) is


T , ω < ω s / 2,
H (ω ) = 
 0, otherwise,
which is an ideal filter with cutoff frequency ωs/2. This filter has the impulse response
sin(ω s t / 2)
hbl (t ) = . (3)
ω st / 2
The bandlimited reconstruction is then given by

EIE/PolyU/LS105_Sampling/March2007 3

x bl (t ) = ∑ x(nT )hbl (t − nT ) . (4)
n = −∞
Whether or not this signal is a “good” reconstruction of x(t) depends on the bandwidth of x(t). If x(t) has
bandwidth greater than ωs, then the reconstruction xbl(t) generally will not be equal to x(t).

If x(t) has a bandwidth exceeding ωs, it still may be possible to recover x(t) from its samples x(nT) if you
have additional information about x(t). For instance, if x(t) is known to be piecewise linear, a linear
interpolation may be used to reconstruct x(t). The linear interpolation of the samples x(nT) is given by
convolving xp(t) with the following impulse response:
1 − t / T , t ≤ T,
hlin (t ) =  (5)
 0, otherwise.
The continuous-time reconstructed signal xlin(t) = xp(t)*hlin(t) is equivalent to connecting the samples x(nT)
with straight lines. However, just as bandlimited interpolation may not do a very good job of recovering a
signal which is sampled below the Nyquist rate, the linear interpolator may not produce a very good
reconstruction if the original signal x(t) is not piecewise linear. As the following problems demonstrate,
the performance of any interpolation filter depends upon the characteristics of the original signal x(t).

In the following problems, you will use both bandlimited and linear interpolation to reconstruct the
signals
 8πt  1 − t / 2, t ≤ 2,
x1 (t ) = cos  , x 2 (t ) = 
 5   0, otherwise,
from samples obtained at sample times t = nT with T = 1/2.

Problems

(a) Show analytically that both xbl(t) and xlin(t) are equal to the sample values x(nT) at the sampling
times t = nT. Such interpolators are called exact interpolators, since they maintain the exact
values of the original signal at the sampling times. Are the bandlimited and linear interpolation
filters causal?

(b) Are x1(t) and x2(t) bandlimited? If so, with what bandwidth?

(c) Create a vector ts which contains the sampling times t = nT on the interval |t| ≤ 4. Store in the
vectors xs1 and xs2 the samples of x1(t) and x2(t) at the corresponding times in ts. Use stem to
plot xs1 and xs2 versus ts. The following code may help you.
T = 1/2; % sampling interval
ts = -4:T:4; % interval of ts
xs1 = cos(8*pi*ts/5); % signal x1(t)
xs2(abs(ts)<=2) = 1 - abs(ts(abs(ts)<=2))/2; % signal x2(t)
xs2(abs(ts)>2) = 0;

To reconstruct x1(t) and x2(t) from these samples, note that the reconstructed signals can only be
computed at a finite number of samples in MATLAB. Therefore, you will calculate the interpolated
signals only at t = n/8 on the interval |t| ≤ 2. In other words, on the interval |t| ≤ 2 you will calculate three
samples in between every sample contained in xs1 and xs2. The sampling interval of the interpolated
signal is thus Ts = 1/8.

Another problem encountered in MATLAB is the finite duration of hbl(t). One solution is to approximate
hbl(t) by a windowed version of the signal. For the remainder of this exercise, replace hbl(t) with the
finite-length interpolator

EIE/PolyU/LS105_Sampling/March2007 4
h (t ), t ≤ 2,
hb1f (t ) =  b1
 0, otherwise.

Call y1bl(t) and y2bl(t) the signals given by interpolating the samples of x1(t) and x2(t) with the interpolating
filter hb1f(t). Similarly, call y1lin(t) and y2lin(t) the signals given by interpolating the samples of x1(t) and
x2(t) with the linear interpolator hlin(t).

(d) Set Ti=1/8, and create a vector of the interpolation times ti=[-2:Ti:2]. Store in the vectors hbl and
hlin the values of hblf(t) and hlin(t) at the interpolation times. Use plot to display these two
impulse responses versus ti. What are the values of impulse responses at the samples times ts?
The peak value of each impulse response should be at t = 0.

Note that, because both hlin(t) and hblf(t) are nonzero only for |t| ≤ 2, the interpolated signals on the
interval |t| ≤ 2 are a function only of the samples x(nT) on the interval |t| ≤ 4. The following problems use
conv to reconstruct the signals at the interpolation times in ti from the samples in xs1 and xs2. However,
a lot of bookkeeping is necessary to account for the noncausality of the interpolation filters and to keep
track of the samples in xs1 and xs2 which correspond to different time samples than those of the
interpolation filters hbl and hlin.

(e) Calculating the interpolated signals at the times in ti requires the superposition of a number of
shifted versions of hlin (or hbl), each weighted by the appropriate sample value. This summation
is equivalent to a convolution, which can be implemented using the function conv. Consider the
linear interpolation of the samples of x2(t). The first step is to make the sample times in xs2
correspond with those in hlin. This can be accomplished by creating the vector
N = 4*(length(xs2)-1)+1; % number of samples in the reconstructed signal
xe2 = zeros(1,N); % initialize all samples to zero
xe2(1:4:N) = xs2; % every third sample in xe2 is equal to xs2
The time of each element in xe2 is given by te = [-4:Ti:4]. For each time in te equal to a sample
time in ts, xe2 contains the corresponding value in xs2. Otherwise, xe2 is zero. Use stem to
plot xe2 versus te, and compare it with your plot of xs2.

(f) Use conv to convolve xe2 with hlin. A subset of the output of conv contains the linear
interpolation at the times ti. Remember that the linear interpolator stored in hlin corresponds to a
noncausal filter, but conv assumes that the filter is causal. Extract the desired portion of the
output corresponding to |t| ≤ 2 and store it in the vector y1lin. Use plot to display y1lin versus ti.
Your interpolation should exactly replicate the values of x2(t) on the interval |t| ≤ 2. How could
you have predicted this? The following code may help you.
y2lin = conv(xe2,hlin); % xe2 * hlin
begin = ceil(length(y2lin)/2)-floor(length(ti)/2); % the beginning and last indices
last = ceil(length(y2lin)/2)+floor(length(ti)/2); % for the interval |t| <= 2
y1lin = y2lin(begin:last); % extract the desired portion

(g) Use the same procedure to compute the bandlimited interpolation of the samples of x2(t).
Remember that you only need to compute the interpolation at the times in ti. How does this
interpolation compare with the linear interpolation? Explain.

(h) Use the same procedure to compute the linear and bandlimited interpolation of the samples of
x1(t). Remember that you only need to compute the interpolation at the times in ti. Which
interpolation more faithfully reproduces the original signal x1(t) over the interval |t| < 2?

(i) Explain the relative performance of the two interpolators.

EIE/PolyU/LS105_Sampling/March2007 5
3. Signal Sampling and Reconstruction Using LabVIEW

Figure 2 shows an interface for you to further investigate the sampling theorem and the reconstruction of
sampled signals. In this interface, you are provided with two signal generators, SG1 and SG2, whose
outputs are added. The combined signal is then sampled with a controllable sampling rate, and the
sampled signal is displayed by a CRO and a spectrum analyzer. This sampled signal is applied to a low-
pass filter, whose bandwidth is equal to half of the sampling rate of the signal.

Fig. 2 Sampling and reconstruction of signals.

(a) Execute the program “sampling.exe” to start the interface.


(b) Set SG1 to output a sine waveform with a frequency of 1000Hz, and SG2 to have zero amplitude.
Increase the sampling rate gradually from 1000Hz to 10000Hz, and observe what happens to the
sampled waveform, the spectrum, and the reconstructed signal.
(c) Set SG1 and SG2 to output sine waveforms with frequencies of 1000Hz and 3000Hz,
respectively, and with amplitudes of about 0.64 and 0.21, respectively. What does the signal look
like? Now, increase the sampling frequency from 4000Hz to 8000Hz, and discuss your
observations.
(d) Try other types of signal or a combination of different signals, and observe their spectra and
reconstruction signals with different sampling rates.

− END −

EIE/PolyU/LS105_Sampling/March2007 6

Das könnte Ihnen auch gefallen