0% found this document useful (0 votes)
97 views

LAB 9 - Multirate Sampling

The document describes multirate sampling and sampling rate conversion. It discusses downsampling a signal by an integer factor M, called decimation. The key points are: 1) Downsampling is performed by selecting every Mth sample of the input signal x[n] and discarding the rest, yielding the downsampled signal y[n]. 2) MATLAB's downsample function performs this operation, but the my_downsample function written in the lab allows specifying an offset phase value. 3) Ideal decimation repeats the spectrum of x[n] with periodicity 2π/M in the spectrum of y[n]. Lowpass filtering y[n] with a cutoff of π/

Uploaded by

M Hassan Bashir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

LAB 9 - Multirate Sampling

The document describes multirate sampling and sampling rate conversion. It discusses downsampling a signal by an integer factor M, called decimation. The key points are: 1) Downsampling is performed by selecting every Mth sample of the input signal x[n] and discarding the rest, yielding the downsampled signal y[n]. 2) MATLAB's downsample function performs this operation, but the my_downsample function written in the lab allows specifying an offset phase value. 3) Ideal decimation repeats the spectrum of x[n] with periodicity 2π/M in the spectrum of y[n]. Lowpass filtering y[n] with a cutoff of π/

Uploaded by

M Hassan Bashir
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Regd. No.

: _____________________ Name: _____________________ Section: _____________________

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:

1. Digital Signal Processing using MATLAB: A problem solving companion, Vinay K.


Ingle and John G. Proakis, 4th Edition, Cengage Learning, 2016
2. Discrete Time Signal Processing, Alan. V. Oppenheim and Ronald. W. Schafer, 3rd
Edition, Prentice Hall, 2010
3. Digital Signal Processing: Principles, Algorithms, and Applications, John G.
Proakis and Dimitris G. Manolakis, 4th Edition, Prentice Hall, 2007

1. SAMPLING RATE CONVERSION


Discrete-time signals can arise in many ways but they occur most commonly as sampled representations of
continuous-time signals, i.e., 𝑥[𝑛] is obtained from a continuous-time signal 𝑥(𝑡) as

𝑥[𝑛] = 𝑥(𝑛𝑇) , − ∞ < 𝑛 < ∞, (1)

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.

1.1 RECONSTRUCTION OF BANDLIMITED SIGNALS


The Nyquist-Shannon Sampling Theorem states that if the continuous-time signal 𝑥(𝑡) is bandlimited to
frequency Ω0 , i.e., |Ω| ≤ Ω0 , then it is uniquely determined by its samples 𝑥[𝑛] = 𝑥(𝑛𝑇), 𝑛 = 0, ±1, ±2, …, if
the sampling rate is at least twice the maximum frequency in 𝑥(𝑡), i.e.,

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)
𝐹𝑥 𝑀

where 𝐿 and 𝑀 are relative prime integers.

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,

𝑦[𝑛] = 𝑥[𝑛𝑀], 𝑛, 𝑀 integers. (6)

Decimation is often represented by a downward arrow, as shown in the following block diagram.

Figure 1: Down-sampling by a factor of 𝑀.

1.2.1 MATLAB IMPLEMENTATION OF DOWN-SAMPLING


MATLAB provides the function y = downsample (x, M, phase) that down-samples the input array x into the
output array y by keeping every 𝑀th sample starting with the first sample. The third parameter “phase” is
optional and specifies the sample offset which must be an integer between 0 and 𝑀 − 1. For example,

>> x = [1,2,3,4,3,2,1]; y = downsample (x, 2)


y=
1331

down-samples by a factor of 2 starting with the first sample. However,

>> x = [1,2,3,4,3,2,1]; y = downsample (x, 2, 1)


y=
242

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.

function [y, ny] = my_downsample (x, n, M, phase)


% Down-samples the sequence x into y by a factor of M, with an optional integer offset given by phase
% -------------------------------------------------------------------------------------------------------------------------------------
% [y, ny] = my_downsample (x, n, M, phase)

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).

1.2.2 THE IDEAL DECIMATOR


It can be shown that the frequency spectrum of the down-sampled sequence 𝑦[𝑛] is given by [1, 2, 3]
𝑀−1
1 𝜔 − 2𝜋𝑘
𝑌(𝜔) = ∑ 𝑋 ( ), 𝜔 = 𝛺(𝑀𝑇), (7)
𝑀 𝑀
𝑘=0

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

𝑦[𝑛] = ∑ ℎ[𝑘] 𝑥[𝑛𝑀 − 𝑘] , (8)


𝑘=−∞

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.

1.2.3 MATLAB IMPLEMENTATION OF DECIMATION


MATLAB provides the function y = decimate (x, M) that resamples the sequence in array x at 1/𝑀 times the
original sampling rate. The resulting resampled array y is 𝑀 times shorter, i.e., length(y) = length(x)/M. It is
impossible to implement the ideal lowpass filter in MATLAB; however, fairly accurate approximations exist.
The default lowpass filter used in the function is an eighth-order Chebyshev type-I lowpass filter with the cutoff
frequency of 0.8𝜋/𝑀. Using additional optional arguments, the filter order can be changed or an FIR filter of
specified order and cutoff frequency can be used.

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.

1.3.1 THE UP-SAMPLER


Let 𝑢[𝑛] denote the intermediate sequence with rate 𝐹𝑦 = 𝐿𝐹𝑥 , which is obtained from 𝑥[𝑛] by adding 𝐿 − 1
zeros between successive values of 𝑥[𝑛]. Thus

𝑥[𝑛/𝐿], 𝑛 = 0, ±𝐿, ±2𝐿, … ,


𝑢[𝑛] = { (9)
0, otherwise.

The block diagram of the up-sampler is shown in Figure 3. Again, any system containing the up-sampler is a
time-varying system.

Figure 3: Up-sampling by a factor of 𝐿.

1.3.2 MATLAB IMPLEMENTATION OF UP-SAMPLING


MATLAB provides the function u = upsample (x, L) that up-samples input array x into output u by inserting
(𝐿 − 1) zeros between input samples. An optional third parameter, “phase,” specifies the sample offset, which
must be an integer between 0 and (𝐿 − 1). For example,

>> x = [1,2,3,4]; u = upsample (x, 3)


u=
100200300400

up-samples by a factor of 2 starting with the first sample. However,

>> u = upsample (x, 3, 1)


u=
010020030040
>> u = upsample (x, 3, 2)
u=
001002003004

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.

function [u, nu] = my_upsample (x, L, phase)


% Up-samples the sequence x into y by a factor of L, with an optional integer offset given by phase
% -------------------------------------------------------------------------------------------------------------------------------
% [u, nu] = my_upsample (x, n, L, phase)
% [u, nu] = Up-sampled sequence and its discrete-time index vector
% [x, n] = Input sequence and its discrete-time index vector
% L = Interpolation factor
% phase = Optional offset, must be an integer
% ------------------------------
% Write your code here.
% ------------------------------

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.

1.3.3 THE IDEAL INTERPOLATOR


It can be shown [e.g., see 2] that the frequency spectrum of the up-sampled signal is given by

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

𝑦[𝑛] = ∑ ℎ[𝑛 − 𝑘] 𝑢[𝑘] , (11)


𝑘=−∞

Since 𝑢[𝑘] = 0 except at multiples of 𝐿, where 𝑢[𝑘𝐿] = 𝑥[𝑘], (11) becomes


𝑦[𝑛] = ∑ ℎ[𝑛 − 𝑘𝐿] 𝑥[𝑘] . (12)


𝑘=−∞

1.3.4 MATLAB IMPLEMENTATION OF INTERPOLATION


MATLAB provides the function [y, h] = interp (x, L) that resamples the signal in array x at 𝐿 times the original
sampling rate. The resulting resampled array y is 𝐿 times longer, i.e., length(y) = L*length(x). The ideal lowpass
filter is approximated by a symmetric filter impulse response, h, which is designed internally. It allows the
original samples to pass through unchanged and interpolates between so that the mean square error between
them and their ideal values is minimized. The third optional parameter, N, specifies the length of the symmetric
filter as 2*N*L+1, and the fourth optional parameter, alpha, specifies the cutoff frequency of the input signal in
π units. The default values are N = 5 and alpha = 0.5. Thus, if 𝐿 = 2, then the length of the symmetric filter is 21
for the default value of N.

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 𝑇.

You might also like