LAB 9 - Multirate Sampling
LAB 9 - Multirate Sampling
LAB 9
Multirate Sampling
Instructions:
• All tasks must be completed in this lab session for full credit.
• Students must show the output and MATLAB code for each task to the instructor
before proceeding to the next task.
References:
where 𝑇 is called the sampling period and its reciprocal 𝐹𝑆 = 1/𝑇 is called the sampling frequency, in samples
per second. Sampling frequency is also given in radians per second by the expression Ω𝑆 = 2𝜋/𝑇.
In many practical applications of digital signal processing, sampling rate of a signal may be required to be
changed, either increasing it or decreasing it by some amount. The process of converting a signal from a given
rate to a different rate is called sampling rate conversion. In turn, systems that employ multiple sampling rates
in the processing of digital signals are called multirate digital signal processing systems.
As an example, consider a system in which an analog signal 𝑥(𝑡) is sampled using the sampling rate of 𝐹𝑆 =
1/𝑇 samples/second. The resulting digital signal 𝑥[𝑛] is subsequently filtered using a lowpass filter (LPF) with
a cutoff frequency of 𝜔𝑐 . Thus, the output signal 𝑦[𝑛] has all its energy in the band 0 ≤ 𝜔 ≤ 𝜔𝑐 = 2𝜋𝑓𝑐 ≤ 𝜋.
According to the sampling theorem, such a signal may be represented by the rate of 2𝑓𝑐 /𝑇 samples/second
instead of its existing rate of 𝐹𝑆 = 1/𝑇, because |𝑓𝑐 | ≤ 0.5, and if 𝑓𝑐 ≪ 0.5, then 2𝑓𝑐 /𝑇 ≪ 𝐹𝑆 . Hence it would
seem more advantageous to lower the sampling frequency to a value closer to 2𝑓𝑐 /𝑇 and perform signal
processing operations at this lower rate.
Other applications include the need for an optimal interpolation in computer tomography and efficient
multistage designs of narrowband lowpass filters.
2𝜋
Ω𝑆 = ≥ 2Ω0 . (2)
𝑇
Hence, according to this theorem, samples of continuous-time signal taken frequently enough are sufficient to
represent the signal exactly, in the sense that the signal can be recovered from its samples with the knowledge
of the sampling period. The process of reconstructing the analog signal from its samples is called interpolation.
The reconstructed signal is given by
∞ ∞
sin 𝜋(𝑡 − 𝑛𝑇)/𝑇 sin 𝜋(𝑡 − 𝑛𝑇)/𝑇
𝑥(𝑡) = ∑ 𝑥[𝑛] = ∑ 𝑥(𝑛𝑇) . (3)
𝜋(𝑡 − 𝑛𝑇)/𝑇 𝜋(𝑡 − 𝑛𝑇)/𝑇
𝑛=−∞ 𝑛=−∞
If the reconstructed analog signal is sampled again at, e.g., twice the old rate, then we essentially double the
sampling rate, i.e., if the original discrete-time signal is given by (1), then the reconstructed signal is given by
(3) and the resampled signal is given by
∞ 𝑇 ∞ 𝑚
𝑇 sin 𝜋 (𝑚 2 − 𝑛𝑇) /𝑇 sin 𝜋 ( 2 − 𝑛)
𝑥 (𝑚 ) = ∑ 𝑥(𝑛𝑇) = ∑ 𝑥(𝑛𝑇) 𝑚 , (4)
2 𝑇 𝜋 ( − 𝑛)
𝑛=−∞ 𝜋 (𝑚 − 𝑛𝑇) /𝑇 𝑛=−∞ 2
2
𝑇
which results in the high-rate discrete-time signal 𝑦[𝑚] = 𝑥 (𝑚 2).
In this formulation of ideal interpolation, the discrete signal was converted to the analog signal and then back to
the discrete signal at twice the rate. There are methods which avoid this roundabout approach and perform
sampling rate conversion completely in the digital domain.
The process of sampling rate conversion in the digital domain can be viewed as a linear filtering operation, in
which the input signal 𝑥[𝑛] is characterized by the sampling rate 𝐹𝑥 = 1/𝑇𝑥 and the output signal 𝑦[𝑚] is
characterized by the sampling rate 𝐹𝑦 = 1/𝑇𝑦 , where 𝑇𝑥 and 𝑇𝑦 are the corresponding sampling intervals. In our
treatment, the ratio 𝐹𝑦 /𝐹𝑥 is constrained to be rational, i.e.,
𝐹𝑦 𝐿
= , (5)
𝐹𝑥 𝑀
2
1.2 DECIMATION BY A FACTOR 𝑀
The process of reducing the sampling rate by a factor 𝑀 (down-sampling by 𝑀) is called decimation. The
down-sampled signal 𝑦[𝑛] is obtained by selecting one out of 𝑀 samples of 𝑥[𝑛] and throwing away the other
(𝑀 − 1) samples out of every 𝑀 samples—that is,
Decimation is often represented by a downward arrow, as shown in the following block diagram.
produces an entirely different sequence by down-sampling, starting with the second sample (i.e., offset by 1).
Task 1
Write a MATLAB function my_downsample (x, M, phase) that down-samples the input sequence x (not
necessarily causal) by an integer factor of M, with “phase” as an optional argument, defining the integer offset.
The structure of the function is given below.
3
% [y, ny] = Down-sampled sequence and its discrete-time index vector
% [x, n] = Input sequence and its discrete-time index vector
% M = Decimation factor
% phase = Optional offset, must be an integer
% ------------------------------
% Write your code here.
% ------------------------------
Use the functions downsample and my_downsample to down-sample the sequence 𝑥[𝑛] = 0.4𝑛 𝑢[𝑛], −2 ≤
𝑛 ≤ 5, by a factor of 3 with a phase value of −2. Plot 𝑥[𝑛] and the down-sampled sequences from the two
functions on a 3x1 grid of the figure window.
Note: Phase determines the sample the down-sampling starts from. Hence, [y, ny] = my_downsampling (x, n, 3,
-2) should yield
y=
6.25 0.4 0.0256
ny =
012
for the above-mentioned sequence. The MATLAB function y = downsample (x, M, phase) considers the
sequence x to be causal and takes value of the phase between 0 and 𝑀 − 1, which is vector-index of the vector x
minus 1. Hence, negative phase values for non-causal sequences should be pre-processed to find the
corresponding vector-index of the vector x, which then should be used in y = downsample (x, M, phase).
where 𝑋(𝜔) represents the frequency spectrum of 𝑥[𝑛]. The above expression indicates that the spectrum of the
down-sampled sequence consists of periodic repetition of the spectrum of the original sequence, with period of
repetition equal to 2𝜋. If the consecutive images of the spectrum do not overlap, then the original spectrum
𝑋(𝜔) can be obtained from 𝑌(𝜔) by passing 𝑦[𝑛] through an ideal low-pass filter with cut-off frequency of
𝜋/𝑀, if there is no overlap between the consecutive images of 𝑌(𝜔).
However, if the consecutive images of 𝑌(𝜔) do overlap (which depends on the combination of factors such as
the sampling frequency 𝛺𝑆 , bandwidth of the continuous-time domain signal 𝑥(𝑡) and the decimation factor 𝑀),
then the original spectrum of 𝑋(𝜔) cannot be obtained from 𝑌(𝜔). This condition is called aliasing. In order to
avoid aliasing, the original discrete-time signal 𝑥[𝑛] is processed through the above-mentioned ideal low-pass
filter, having cut-off frequency of 𝜋/𝑀, before down-sampling by a factor of 𝑀. The functional block diagram
of the resulting ideal decimation is shown in Figure 2.
4
Figure 2: The ideal decimator as made up of the ideal low-pass filter and the down-sampler.
Thus, the filter eliminates the spectrum of 𝑋(𝜔) in the range 𝜋/𝑀 ≤ 𝜔 ≤ 𝜋. The implication is that only the
frequency components of 𝑥[𝑛] in the range |𝜔| ≤ 𝜋/𝑀 are of interest in further processing of the signal.
The decimated signal is then given by
∞
where ℎ[𝑛] is the impulse response of the ideal low-pass filter. Although the filtering operation on 𝑥[𝑛] is linear
and time invariant, the down-sampling operation renders the ideal decimator a time-variant system.
Task 2
Let 𝑥[𝑛] = cos[0.125𝜋𝑛] , 0 ≤ 𝑛 ≤ 32. Decimate this sequence by factors 𝑀 = 2, 4, 8. Plot the original
sequence and the three decimated sequences on a 2x2 grid of the figure window. Which of the decimated
signals cannot be used to construct the original signal 𝑥[𝑛]. Why ?
5
1.3 INTERPOLATION BY A FACTOR 𝐿
An increase in the sampling rate by an integer factor of 𝐿, i.e., 𝐹𝑦 = 𝐿𝐹𝑥 , can be accomplished by interpolating
𝐿 − 1 between successive values of the signal. The interpolation process can be accomplished in two steps. The
first step creates an intermediate signal at the high rate 𝐹𝑦 by interlacing zeros in between nonzero samples in an
operation called up-sampling. In the second step, the intermediate signal is filtered to “fill in” zero-interlaced
samples to create the interpolated high-rate signal.
The block diagram of the up-sampler is shown in Figure 3. Again, any system containing the up-sampler is a
time-varying system.
6
produces two different signals by up-sampling, starting with the second and the third sample (i.e., offset by 1),
respectively. Note that the lengths of the up-sampled signals are 𝐿 times the length of the original signal.
Task 3
Write a MATLAB function my_upsample (x, L, phase) that up-samples the input sequence x by an integer
factor of L, with “phase” as an optional argument, defining the integer offset. The structure of the function is
given below.
Use the functions upsample and my_upsample to up-sample the sequence 𝑥[𝑛] = 0.4𝑛 𝑢[𝑛], −2 ≤ 𝑛 ≤ 5, using
𝐿 = 3 and phase value of −2. Phase should be treated as the origin of the up-sampled sequence, i.e., it identifies
the sample the up-sampling starts from. Hence, [u, nu] = my_upsample (1:6, -3:2, 2, -2) should yield
u=
1002003004005006
nu =
-3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11 12
Plot 𝑥[𝑛] and the up-sampled sequences from the two functions on a 3x1 grid of the figure window.
Note: The discussion in the note at the end of Task 1 applies to the phase in the MATLAB function u = upsample
(x, L, phase) as well.
Figure 4: The ideal interpolator as made up of the up-sampler and the ideal low-pass filter.
7
∞ ∞
1 𝜔𝐿 2𝜋𝑘 1 𝜔 (2𝜋/𝐿)𝑘
𝑈(𝜔) = 𝑋(𝜔𝐿) = ∑ 𝑋𝐶 ( − ) = ∑ 𝑋𝐶 ( − ), (10)
𝑇 𝑇 𝑇 𝑇 (𝑇/𝐿) (𝑇/𝐿)
𝑘=−∞ 𝑘=−∞
where 𝑋𝐶 (Ω) is the frequency spectrum of the continuous-time signal 𝑥(𝑡), which is sampled at the sampling
period of 𝑇 to obtain 𝑥[𝑛]. The expression in (10) shows that the spectrum 𝑈(𝜔) is periodic with period 2𝜋/𝐿
instead of 2𝜋. This problem can be resolved by filtering the sequence 𝑢[𝑛] through an ideal low-pass filter
having cut-off frequency 𝜔𝑐 = 𝜋/𝐿 and amplitude 𝐿, which corrects for the amplitude scaling in (10) [see, e.g.,
1, 2]. The functional block diagram of the resulting ideal interpolation is shown in Figure 4.
The output sequence 𝑦[𝑛] can be expressed as a convolution of the sequence 𝑢[𝑛]with the unit sample response
ℎ[𝑛] of the low-pass filter. Thus
∞
Task 4
Let 𝑥[𝑛] = cos[𝜋𝑛] , 0 ≤ 𝑛 ≤ 32. Interpolate this sequence by factors 𝐿 = 2, 4, 8. Plot the original sequence
and the three interpolated sequences on a 2x2 grid of the figure window.
Exercise:
1. Consider the discrete-time sequence 𝑥[𝑛] = 𝑒 −500|𝑛𝑇| , where −40 ≤ 𝑛 ≤ 40 and 𝑇 = 0.25msecs.
Assume that this sequence is bandlimited to frequency 𝜔 = 0.5𝜋. Using combination of decimation and
interpolation, obtain the signal 𝑦[𝑛] = 𝑥[0.2𝑛] without any loss of information. Also, plot 𝑥[𝑛] and
𝑦[𝑛], on the same axis, against time over the interval which can be found using the range of 𝑛 and the
value of 𝑇.