DSP Lab 7 Manual
DSP Lab 7 Manual
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ω) ,
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
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.
3
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
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
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.
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