COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
LAB # 4: Discrete Time Signals and Systems in Frequency Domain.
In the previous two labs we dealt with the time-domain representation of discrete-time signals and systems,
and investigated their properties. Further insight into the properties of such signals and systems is obtained
by their representation in the frequency-domain.
Background Review
R 4.1 The discrete-time Fourier transform (DTFT) X(ejω) of a sequence x [n] is defined by
In general X(ejω) is a complex function of the real variable ω and can be written as
where Xre(ejω) and Xim(ejω) are, respectively, the real and imaginary parts of X(ejω) ,and are real functions
of ω. X(ejω) can alternately be expressed in the form
The quantity |X(ejω)| is called the magnitude function and the quantity θ(ω) is called the phase function, with
both functions again being real functions of ω. In many applications, the Fourier transform is called the
Fourier spectrum and, likewise, |X(ejω)| and θ(ω) are referred to as the magnitude spectrum and phase
spectrum, respectively.
R 4.2 The DTFT X(ejω) is a periodic continuous function in ω with a period π.
R 4.3 The Fourier transform X(ejω) of a sequence x[n] exists if x[n] is absolutely summable, that is,
R 4.4 The inverse discrete-time Fourier transform x[n] of X(ejω) is given by
R 4.5 The DTFT satisfies a number of useful properties that are often utilized in a number of applications. A
detailed listing of these properties and their analytical proofs can be found in any text on digital signal
processing. These properties can also be verified using MATLAB. We list below a few selected properties
that will be encountered later in this Lab.
R 4.6 Time-Shifting Property If G(ejω ) denotes the DTFT of a sequence g[n] , then the DTFT of the time-
shifted sequence g[n – no] is given by ejωno G(ejω ).
1
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
R 4.7 Frequency-Shifting Property If G(ejω ) denotes the DTFT of a sequence g[n] , then the DTFT of the
the sequence ejωong[n] is given by G(ejω-wo ) .
R 4.8 Convolution Property If G(ejω ) and H(ejω ) denote the DTFTs of the sequences g[n] and h[n] ,
respectively, then the DTFT of the sequence g[n]*h[n] is given by G(e jω ).H(ejω ).
R 4.9 If G(ejω )denotes the DTFT of a sequence g[n] , then the DTFT of the time-reversed sequence g[−n] is
given by G(e-jω ).
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 zeros
Language Constructs and Debugging
Break end for if input pause error
Elementary Functions
abs angle conj exp imag real
Two-Dimensional Graphics
axis grid legend plot stem title
xlabel ylabel
General Purpose Graphics Functions
clf subplot
Signal Processing Toolbox
freqz impz
For additional information on these commands, type help command in the Command window.
Exercise 4.1 The DTFT Computation:
The discrete-time Fourier transform (DTFT) X(ejω) of a sequence x[n] is a continuous function of ω. Since
the data in MATLAB is in vector form, X(ejω) can only be evaluated at a prescribed set of discrete
frequencies. Moreover, only a class of the DTFT that is expressed as a rational function in e−jω in the form
can be evaluated.
2
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
The DTFT X(ejω) of a sequence x[n] of the form of above equation can be computed easily at a prescribed
set of L discrete frequency points ω= ωl using the MATLAB function freqz. Since X(ejω) is a continuous
function of ω, it is necessary to make L as large as possible so that the plot generated using the command
plot provides a reasonable replica of the actual plot of the DTFT.
Program P4_1 can be used to evaluate and plot the DTFT
% Program P4_1
% Evaluation of the DTFT
clf;
% Compute the frequency samples of the DTFT
w = -6*pi:8*pi/511:6*pi;
num = [2 1];den = [1 -0.6];
h = freqz(num, den, w);
% Plot the DTFT
subplot(2,1,1)
plot(w/pi,real(h));grid
title('Real part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
plot(w/pi,imag(h));grid
title('Imaginary part of H(e^{j\omega})')
xlabel('\omega /\pi');
ylabel('Amplitude');
pause
subplot(2,1,1)
plot(w/pi,abs(h));grid
title('Magnitude Spectrum |H(e^{j\omega})|')
xlabel('\omega /\pi');
ylabel('Amplitude');
subplot(2,1,2)
plot(w/pi,angle(h));grid
title('Phase Spectrum arg[H(e^{j\omega})]')
3
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
xlabel('\omega /\pi');
ylabel('Phase in radians');
Questions:
Q 4.1 What is the expression of the DTFT being evaluated in Program P4_1?
Q 4.2 What is the function of the MATLAB command pause?
Q 4.3 Run Program P4_1 and plot the real and imaginary parts of the DTFT, and the magnitude and phase
spectra. Is the DTFT a periodic function of ω? If it is, what is the period?
Q 4.4 Modify Program P4_1 to evaluate in the range 0 ≤ ω ≤ π the following DTFT:
and repeat Question Q4.3. Comment on your results. Can you explain the jump in the phase spectrum? The
jump can be removed using the MATLAB command unwrap. Evaluate the phase spectrum with the jump
removed.
Q 4.5 Modify ProgramP4_1 to evaluate the DTFT of the following finite-length sequence:
g[n]=[1 3 5 7 9 11 13 15 17],and repeat Question Q4.3.
Exercise 4.2 Time Shifting Property
Program P4_2 can be used to verify the time-shifting property of the DTFT
% Program P4_2
% Time-Shifting Properties of DTFT
clf;
w = -pi:2*pi/255:pi; % frequency vector for evaluating DTFT
D = 10; % Amount of time shift in samples
num = [1 2 3 6 5 6 7 8 9];
% h1 is the DTFT of original sequence
% h2 is the DTFT of the time shifted sequence
h1 = freqz(num, 1, w);
h2 = freqz([zeros(1,D) num], 1, w);
subplot(2,2,1)
% plot the DTFT magnitude of the original sequence
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence','FontSize',8)
4
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the DTFT magnitude of the shifted sequence
subplot(2,2,2)
plot(w/pi,abs(h2));grid
title('Magnitude Spectrum of Time-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the DTFT phase of the original sequence
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the DTFT phase of the shifted sequence
subplot(2,2,4)
plot(w/pi,angle(h2));grid
title('Phase Spectrum of Time-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
Questions:
Q. 4.4 Run the program P4_2 and comment on your results.
Q. 4.5 Repeat Question Q4.4 for a different value of the time-shift.
Exercise 4.3 Frequency Shifting Property
Program P4_3 can be used to verify the frequency shifting property of the DTFT
% Program P4_3
% Frequency-Shifting Properties of DTFT
clf;
w = -pi:2*pi/255:pi; % freqency vector for evaluating DTFT
wo = 0.6*pi; % Amount of frequency shift in radians
% h1 is the DTFT of the original sequence
5
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
% h2 is the DTFT of the frequency shifted sequence
num1 = [1 3 5 7 9 11 13 15 17];
L = length(num1);
h1 = freqz(num1, 1, w);
n = 0:L-1;
num2 = exp(wo*i*n).*num1;
h2 = freqz(num2, 1, w);
% plot the DTFT magnitude of the original sequence
subplot(2,2,1)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the DTFT magnitude of the freq shifted sequence
subplot(2,2,2)
plot(w/pi,abs(h2));grid
title('Magnitude Spectrum of Frequency-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the DTFT phase of the original sequence
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the DTFT phase of the shifted sequence
subplot(2,2,4)
plot(w/pi,angle(h2));grid
title('Phase Spectrum of Frequency-Shifted Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
6
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
Questions:
Q 4.6 Run the program P4_3 and comment on your results.
Q 4.7 Which parameter controls the amount of frequency-shift?
Q 4.8 Repeat Question Q4.8 for a different value of the frequency-shift.
Q 4.9 Modify P4_3 to run for length of 4 & 14
i.e.
num=[1:2:7] (Length=4)
num=[1:2:31] (Length=16)
Comment on effect of varying length on Magnitude Spectrum & Phase spectrum.
Exercise 4.4 Convolution Property
Program P4_4 can be used to verify the convolution property of the DTFT
% Program P4_4
% Convolution Property of DTFT
clf;
w = -pi:2*pi/255:pi; % freqency vector for evaluating DTFT
x1 = [1 3 5 7 9 11 13 15 17]; % first sequence
x2 = [1 -2 3 -2 1]; % second sequence
y = conv(x1,x2); % time domain convolution of x1 and x2
h1 = freqz(x1, 1, w); % DTFT of sequence x1
h2 = freqz(x2, 1, w); % DTFT of sequence x2
% hp is the pointwise product of the two DTFT's
hp = h1.*h2;
% h3 is the DTFT of the time domain convolution;
% it should be the same as hp
h3 = freqz(y,1,w);
% plot the magnitude of the product of the two original spectra
subplot(2,2,1)
plot(w/pi,abs(hp));grid
title('Product of Magnitude Spectra','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
7
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
% plot the magnitude spectrum of the time domain convolution
subplot(2,2,2)
plot(w/pi,abs(h3));grid
title('Magnitude Spectrum of Convolved Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the phase of the product of the two original spectra
subplot(2,2,3)
plot(w/pi,angle(hp));grid
title('Sum of Phase Spectra','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the phase spectrum of the time domain convolution
subplot(2,2,4)
plot(w/pi,angle(h3));grid
title('Phase Spectrum of Convolved Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
Questions:
Q 4.10 Run the program P4_4 and comment on your results.
Exercise 4.5 Time Reversal Property
Program P4_5 can be used to verify the time reversal property of the DTFT
% Program P4_5
% Time Reversal Property of DTFT
clf;
w = -pi:2*pi/255:pi; % frequency vector for evaluating DTFT
% original ramp sequence
% note: num is nonzero for 0 <= n <= 3.
num = [1 2 3 4];
L = length(num)-1;
h1 = freqz(num, 1, w); % DTFT of original ramp sequence
h2 = freqz(fliplr(num), 1, w);
8
COMSATS University Islamabad
Department of Electrical Engineering (Wah Campus)
Digital Signal Processing Lab Manual
h3 = exp(w*L*i).*h2;
% plot the magnitude spectrum of the original ramp sequence
subplot(2,2,1)
plot(w/pi,abs(h1));grid
title('Magnitude Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the magnitude spectrum of the time reversed ramp sequence
subplot(2,2,2)
plot(w/pi,abs(h3));grid
title('Magnitude Spectrum of Time-Reversed Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Amplitude');
% plot the phase spectrum of the original ramp sequence
subplot(2,2,3)
plot(w/pi,angle(h1));grid
title('Phase Spectrum of Original Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
% plot the phase spectrum of the time reversed ramp sequence
subplot(2,2,4)
plot(w/pi,angle(h3));grid
title('Phase Spectrum of Time-Reversed Sequence','FontSize',8)
xlabel('\omega /\pi');
ylabel('Phase in radians');
Questions:
Q 4.11 Run the program P4_5 and comment on your results
Q 4.12 Explain how the program implements the time-reversal operation.