0% found this document useful (1 vote)
157 views

DSP Lab 7 Manual

This document provides background information and instructions for Lab #6 on sampling of continuous time signals and reconstruction. The lab investigates: 1) Converting a continuous time signal to a discrete time signal through periodic sampling and reconstructing the continuous signal from the discrete one using an analog filter. 2) The effects of sampling in the time and frequency domains, including the Nyquist sampling theorem which states the minimum required sampling frequency. 3) MATLAB programs are provided to generate examples of sampling a sinusoidal signal at different rates, demonstrate aliasing effects in the time and frequency domains, and investigate the relationship between the continuous and discrete Fourier transforms after sampling.

Uploaded by

AR Rehman
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 (1 vote)
157 views

DSP Lab 7 Manual

This document provides background information and instructions for Lab #6 on sampling of continuous time signals and reconstruction. The lab investigates: 1) Converting a continuous time signal to a discrete time signal through periodic sampling and reconstructing the continuous signal from the discrete one using an analog filter. 2) The effects of sampling in the time and frequency domains, including the Nyquist sampling theorem which states the minimum required sampling frequency. 3) MATLAB programs are provided to generate examples of sampling a sinusoidal signal at different rates, demonstrate aliasing effects in the time and frequency domains, and investigate the relationship between the continuous and discrete Fourier transforms after sampling.

Uploaded by

AR Rehman
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/ 10

COMSATS University Islamabad

Department of Electrical Engineering (Wah Campus)


Digital Signal Processing Lab Manual

LAB # 6: Sampling of continuous time signals and its reconstruction.

Digital signal processing algorithms are often used to process continuous-time signals. To this end, it is
necessary to convert a continuous-time signal into an equivalent discrete-time signal, apply the necessary
digital signal processing algorithm to it, and then convert back the processed discrete-time signal into an
equivalent continuous-time signal. In the ideal case, the conversion of a continuous-time signal into a
discrete-time form is implemented by periodic sampling and, to prevent aliasing, an analog anti-aliasing filter
is often placed before sampling to band-limit the continuous-time signal. The conversion of a discrete-time
signal into a continuous-time signal requires an analog reconstruction filter. In this lab you will investigate
the effect of sampling in the time domain and the frequency domain, respectively. In addition, you will learn
the basics of analog-to-digital and digital-to-analog conversions.
Background Review
R 6.1 Let ga (t) be a continuous-time signal that is sampled uniformly at t =nT generating the sequence g[n]
where

With T being the sampling period. The reciprocal of T is called the sampling frequency F T
R 6.2 The frequency-domain representation of ga(t) is given by its continuous-time Fourier transform Ga(jΩ),

whereas the frequency-domain representation of g[n] is given by its discrete-time Fourier transform G(ejω) ,

The relation between Ga (jΩ) and G(ejω) is given by

R6.3 Sampling Theorem : Let ga(t) be a band limited signal with Ga (jΩ) = 0 for |Ω| >Ωm. Then ga(t) is
uniquely determined by its samples ga(nT) ,n = 0,1 ,2 ,3 ,..., if

The highest frequency Ωm contained in ga(t) is usually called the Nyquist frequency as it determines the
minimum sampling frequency ΩT > Ωm that must be used to fully recover ga(t) from its sampled version. The
frequency 2Ωm is called the Nyquist rate.

1
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

If the sampling rate is higher than the Nyquist rate, it is called oversampling. On the other hand, if the
sampling rate is lower than the Nyquist rate, it is called under-sampling. Finally, if the sampling rate is
exactly equal to the Nyquist rate, it is called critical sampling.
R 6.4 A convenient way to view this sampling process is illustrated in Fig

First, the continuous-time signal is multiplied by a periodic sequence of impulses,

to form the sampled signal

Then, the sampled signal is converted into a discrete-time signal by mapping the impulses that are spaced in
time by Ts into a sequence x[n] where the sample values are indexed by the integer variable n:

R 6.5 The process may be analyzed in the frequency domain as follows, the Fourier transform of Sa(t) is

Therefore,

From above equation we can note that Fourier transform of x s(t) consist of repeated copies of fourier
transform of xa(t) s shown in figure below

2
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

R 6.6 We can achieve original signal xa(t) from xs(t) if we pass it to ideal low pass filter with a gain T and a
cutoff frequency Ω0.

MATLAB Commands Used


The MATLAB commands you will encounter in this exercise are as follows:
Operators and Special Characters
: . + - * / ; % <
Elementary Matrices and Matrix Manipulation
ones pi linespace
Language Constructs and Debugging
Break end for if input pause error
Elementary Functions
abs angle cos exp
Two-Dimensional Graphics
axis grid legend plot stem title
xlabel ylabel
General Purpose Graphics Functions
clf subplot
Signal Processing Toolbox
Filter freqz impz sinc
For additional information on these commands, type help command in the Command window.

3
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

The Sampling Process in the Time Domain


The purpose of this section is to study the relation in the time domain between a continuous time signal xa(t)
and the discrete-time signal x[n] generated by a periodic sampling of xa(t).
Exercise 6.1 Sampling of a Sinusoidal Signal:
In this project you will investigate the sampling of a continuous-time sinusoidal signal xa(t) at various
sampling rates. Since MATLAB cannot strictly generate a continuous-time signal, you will generate a
sequence {xa(nTH)} from xa(t) by sampling it at a very high rate, 1/T H, such that the samples are very close
to each other. A plot of xa(nTH) using the plot command will then look like a continuous-time signal.
% Program P6_1
% Illustration of the Sampling Process in the Time-Domain
clf;
t = 0:0.0005:1;
f = 13;
xa = cos(2*pi*f*t);
subplot(2,1,1)
plot(t,xa);grid
xlabel('Time, msec');ylabel('Amplitude');
title('Continuous-time signal x_{a}(t)');
axis([0 1 -1.2 1.2])
subplot(2,1,2);
T = 0.1;
n = 0:T:1;
xs = cos(2*pi*f*n);
k = 0:length(n)-1;
stem(k,xs);grid;
xlabel('Time index n');ylabel('Amplitude');
title('Discrete-time signal x[n]');
axis([0 (length(n)-1) -1.2 1.2])
Questions:
Q6.1 Run Program P6_1 to generate both the continuous-time signal and its sampled version, and display
them.
Q6.2 What is the frequency in Hz of the sinusoidal signal? What is the sampling period in seconds?

4
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

Q 6.3 Run Program P6_1 for four other values of the sampling period with two lower and two higher than
that listed in Program P6_1. Comment on your results.
Q 6.4 Repeat Program P6_1 by changing the frequency of the sinusoidal signal to 3 KHz and 7 KHz,
respectively. Is there any difference between the corresponding equivalent discrete-time signals and the one
generated in Question Q6.1? If not, why not?
Exercise 6.2 Aliasing Effect in the Time Domain
In this exercise you will generate a continuous-time equivalent ya(t) of the discrete-time signal x[n] generated
in Program P6_1 to investigate the relation between the frequency of the sinusoidal signal xa(t) and the
sampling period. To generate the reconstructed signal ya(t) from x[n] , we pass x[n] through an ideal low-
pass filter that in turn can be implemented according to R 6.6.
% Program P6_2
% Illustration of Aliasing Effect in the Time-Domain
clf;
T = 0.1;f = 13;
n = (0:T:1)';
xs = cos(2*pi*f*n);
t = linspace(-0.5,1.5,500)';
ya = sinc((1/T)*t(:,ones(size(n))) - (1/T)*n(:,ones(size(t)))')*xs;
plot(n,xs,'o',t,ya);grid;
xlabel('Time, msec');ylabel('Amplitude');
title('Reconstructed continuous-time signal y_{a}(t)');
axis([0 1 -1.2 1.2]);
Questions:
Q 6.5 Run Program P6_2 to generate both the discrete-time signal x[n] and its continuous-time equivalent
ya(t) , and display them.
Q 6.6 Explain working of line 10 of program which reads:
ya = sinc((1/T)*t(:,ones(size(n))) - (1/T)*n(:,ones(size(t)))')*xs;
Q 6.7 Repeat Program P6_2 by changing the frequency of the sinusoidal signal to 3 KHz and 7 KHz,
respectively. Is there any difference between the corresponding equivalent discrete-time signals and the one
generated in Q 6.5? If not, why not?

5
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

Effect of Sampling in the Frequency Domain


Exercise 6.3 Aliasing Effect in the Frequency Domain
The relation between the continuous-time Fourier transform (CTFT) of an arbitrary bandlimited continuous-
time signal and the discrete-time Fourier transform (DTFT) of the discrete-time signal is investigated next in
this project. In order to convert a continuous-time signal xa(t) into an equivalent discrete-time signal x[n],
the former must be band-limited in the frequency domain (see R6.2). To illustrate the effect of sampling in
the frequency domain we choose an exponentially decaying continuous-time signal with a CTFT that is
approximately bandlimited.
% Program P6_3
% Illustration of the Aliasing Effect in the Frequency Domain
clf;
t = 0:0.005:10;
xa = 2*t.*exp(-t);
subplot(2,2,1)
plot(t,xa);grid
xlabel(’Time, msec’);ylabel(’Amplitude’);
title(’Continuous-time signal x_{a}(t)’);
subplot(2,2,2)
wa = 0:10/511:10;
ha = freqs(2,[1 2 1],wa);
plot(wa/(2*pi),abs(ha));grid;
xlabel(’Frequency, kHz’);ylabel(’Amplitude’);
title(’|X_{a}(j\Omega)|’);
axis([0 5/pi 0 2]);
subplot(2,2,3)
T = 1;
n = 0:T:10;
xs = 2*n.*exp(-n);
k = 0:length(n)-1;
stem(k,xs);grid;
xlabel(’Time index n’);ylabel(’Amplitude’);
title(’Discrete-time signal x[n]’);

6
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

subplot(2,2,4)
wd = 0:pi/255:pi;
hd = freqz(xs,1,wd);
plot(wd/(T*pi), T*abs(hd));grid;
xlabel(’Frequency, kHz’);ylabel(’Amplitude’);
title(’|X(e^{j\omega})|’);
axis([0 1/T 0 2])
Questions:
Q6.6 What is the continuous-time function xa(t) in Program P6_3? How is the CTFT of xa(t) being computed?
Q6.9 Run Program P6_3 to generate and display both the discrete-time signal and its continuous-time
equivalent, and their respective Fourier transforms. Is there any visible effect of aliasing?
Q6.10 Repeat Program P6_3 by increasing the sampling period to 1.5. Is there any visible effect of aliasing?
Q6.11 Modify Program P6_3 for the case of xa(t) = e−πt2 and repeat Questions Q6.9 and Q6.10.
A/D and D/A Conversions
In this section you will learn the basics of analog-to-digital and digital-to-analog conversions, and binary
representations of decimal numbers.
Exercise 6.4 Binary Equivalent of a Decimal Number
Program P6_4 can be used to the generate the binary equivalent in sign-magnitude form of a decimal fraction
% Program P6_4
% Determines the binary equivalent of a decimal number in sign-magnitude form
d = input('Type in the decimal fraction = ');
b = input('Type in the desired wordlength = ');
d1 = abs(d);
beq = [zeros(1,b)];
for k = 1:b
int = fix(2*d1);
beq(k) = int;
d1 = 2*d1 - int;
end
if sign(d) == -1;
bin = [1 beq];
else

7
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

bin = [0 beq];
end
disp('The binary equivalent is');
disp(bin)
Questions:
Q 6.12 What is the function of the operator == in Programs P6_4?
Q 6.13 Using Program P6_3 develop the binary equivalents in sign-magnitude form of the following decimal
fractions:
(a) 0.80165,
(b) − 0.80165,
(c) 0.64333, and
(d) − 0.9125
for the following values of the word lengths: 6 and 8.
Q 6.14 Modify P6_1 so that aliasing does not occur and quantize xa for eight distinct levels.

Exercise 6.5 Decimal Equivalent of a Binary Number


Program P6_5 performs the reverse process and generates the decimal equivalent of a binary fraction in
sign-magnitude form.
% Program P6_5
% Determines the decimal equivalent of a binary number in sign-magnitude form
bin = input(’Type in the binary fraction = ’);
b = length(bin) - 1; d = 0;
for k = 1:b
d = d + bin(k+1)*2^(-k);
end
if sign(bin(1)) == 0;
dec = d;
else
dec = - d;
end
disp(’The decimal equivalent is’);
disp(dec);

8
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

Question:
Q6.15 Using Program P6_5 determine the decimal equivalents of the binary fractions developed in
Question Q6.13. How close are your answers to the original decimal fractions?
Exercise 6.6 Binary Number Representation Schemes
Program P6_6 can be used to determine the ones’-complement of a binary number in sign-magnitude form,
whereas Program P6_6 can be used to determine the two’s-complement representation of a negative binary
fraction in ones’-complement form.
% Program P6_6
% Determines the ones’-complement equivalent of a binary number in sign-magnitude form
bin = input(’Type in the binary number = ’);
if sign(bin(1)) == 0;
onescomp = bin;
else
bin(1) = 0; onescomp = ~bin;
end
disp(’Ones-complement equivalent is’);
disp(onescomp);

% Program P6_7
% Determines the two’s-complement equivalent of a negative binary fraction in ones’-complement form
b = input(’Type in the binary fraction = ’);
F = length(b);
twoscomp = ones(1,F);
c = 1;
for k = F:-1:2
if b(k) & c == 1;
twoscomp(k) = 0; c = 1;
else
twoscomp(k) = b(k) | c; c = 0;
end
end
disp(’Twos-complement equivalent is = ’);

9
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual

disp(twoscomp)
Questions:
Q6.16 What is the purpose of the operator ~ in Program P6_6?
Q6.17 Using Program P 6_6 determine and verify the ones’-complement representations of the binary
numbers developed in Question Q6.13.
Q6.16 What are the purposes of the operators | and & in Program P6_7?
Q6.19 Using Program P6_7 determine and verify the two’s-complement representations of the binary
numbers developed in Question Q6.13.

10

You might also like