0% found this document useful (0 votes)
159 views81 pages

Proakis ch05

This document discusses computing the discrete Fourier transform (DFT) and discrete-time Fourier transform (DTFT) of several periodic sequences. It provides MATLAB code to calculate the DFT and DTFT of example sequences and plot the results. The DFT is computed directly from the sequence samples, while the DTFT is approximated using a long DFT. The key points are that the DFT provides a sampled version of the DTFT, and the DTFT can be reconstructed from the DFT if the DFT length is greater than or equal to the sequence length.

Uploaded by

OH
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)
159 views81 pages

Proakis ch05

This document discusses computing the discrete Fourier transform (DFT) and discrete-time Fourier transform (DTFT) of several periodic sequences. It provides MATLAB code to calculate the DFT and DTFT of example sequences and plot the results. The DFT is computed directly from the sequence samples, while the DTFT is approximated using a long DFT. The key points are that the DFT provides a sampled version of the DTFT, and the DTFT can be reconstructed from the DFT if the DFT length is greater than or equal to the sequence length.

Uploaded by

OH
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/ 81

Chapter 5

The Discrete-Time Fourier Transform


P5.1 Compute the DFS coefficients of the following periodic sequences using the DFS definition and then
verify your answers using M ATLAB .
1. x̃1 (n) = {4, 1, −1, 1}, N = 4

xtilde1 = [4,1,-1,1]; N = 4; Xtilde1 = dfs(xtilde1,N)


Xtilde1 =
5.0000 5.0000 + 0.0000i 1.0000 - 0.0000i 5.0000 + 0.0000i
2. x̃2 (n) = {2, 0, 0, 0, −1, 0, 0, 0}, N = 8

xtilde2 = [2,0,0,0,-1,0,0,0]; N = 8; Xtilde2 = dfs(xtilde2,N)


Xtilde2 =
Columns 1 through 4
1.0000 3.0000 + 0.0000i 1.0000 - 0.0000i 3.0000 + 0.0000i
Columns 5 through 8
1.0000 - 0.0000i 3.0000 + 0.0000i 1.0000 - 0.0000i 3.0000 + 0.0000i
3. x̃3 (n) = {1, 0, −1, −1, 0}, N = 5

xtilde3 = [1,0,-1,-1,0]; N = 5; Xtilde3 = dfs(xtilde3,N)


Xtilde3 =
Columns 1 through 4
-1.0000 2.6180 + 0.0000i 0.3820 - 0.0000i 0.3820
Column 5
2.6180 + 0.0000i
4. x̃4 (n) = {0, 0, 2j, 0, 2j, 0}, N = 6

xtilde4 = [0,0,2j,0,2j,0]; N = 6; Xtilde4 = dfs(xtilde4,N)


Xtilde4 =
Columns 1 through 4
0 + 4.0000i 0.0000 - 2.0000i 0.0000 - 2.0000i -0.0000 + 4.0000i
Columns 5 through 6
0.0000 - 2.0000i 0.0000 - 2.0000i

201
© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
202 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

5. x̃5 (n) = {3, 2, 1}, N = 3


xtilde5 = [3,2,1]; N = 3; Xtilde5 = dfs(xtilde5,N)
Xtilde5 =
6.0000 1.5000 - 0.8660i 1.5000 + 0.8660i
P5.2 Consider the finite-length sequence given below.

sinc2 {(n − 50)/2}, 0 ≤ n ≤ 100;
x(n) =
0, else.

1. DFT X(k):
n = 0:100; xn = sinc((n-50)/2).^2; N = length(xn); % given signal x(n)
Xk = dft(xn,N); k = 0:N-1; % DFT of x(n)
mag_Xk = abs(Xk); pha_Xk = angle(Xk)*180/pi; % Mag and Phase of X(k)
zei = find(mag_Xk < 0.00001); % Set phase values to
pha_Xk(zei) = zeros(1,length(zei)); % zero when mag is zero

Hf_1 = figure(’Units’,’normalized’,’position’,[0.1,0.1,0.8,0.8],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,5]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.2’);
subplot(2,1,1); H_s1 = stem(k,mag_Xk,’filled’); set(H_s1,’markersize’,3);
set(gca,’XTick’,[0:20:N],’fontsize’,8); axis([0,N,0,2.5])
set(gca,’YTick’,[0:0.5:2.5],’fontsize’,8); ylabel(’Magnitude’);
title(’Magnitude plots of DFT and DTFT’,’fontsize’,10); hold on
subplot(2,1,2); H_s2 = stem(k,pha_Xk,’filled’); set(H_s2,’markersize’,3);
set(gca,’XTick’,[0:20:N],’fontsize’,8); axis([0,N,-200,200])
set(gca,’YTick’,[-180;-90;0;90;180],’fontsize’,8);
xlabel(’k’); ylabel(’Degrees’);
title(’Phase plots of DFT and DTFT’,’fontsize’,10); hold on
The stemplotof X(k) is shown in Figure 5.1.
2. DTFT X ejω :
[X,w] = freqz(xn,1,1000,’whole’); % DTFT of xn
mag_X = abs(X); pha_X = angle(X)*180/pi; % mag and phase of DTFT
Dw = (2*pi)/N; % frequency resolution
subplot(2,1,1); plot(w/Dw,mag_X); grid
hold off
subplot(2,1,2); plot(w/Dw,pha_X); grid
hold off
 
The continuous plot of X ejω is also shown in Figure5.1.
3. Clearly, the DFT in part 1. is the sampled version of X ejω .

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 203

4. It is possible to reconstruct the DTFT from the DFT if length of the DFT is larger than or equal to the
length of sequence x (n). We can reconstruct using the complex interpolation formula
−1  
  N 2πk sin (ωN/2)
X ejω = X (k) φ ω − , where φ (ω) = e−jω(N −1)/2
N N sin (ω/2)
k=0

For N = 101, we have


   100
sin (50.5ω)
X ejω = X (k) e−j(50)ω
101 sin (ω/2)
k=0

Magnitude plots of DFT and DTFT


2.5

2
Magnitude

1.5

0.5

0
0 20 40 60 80 100

Phase plots of DFT and DTFT


180

90
Degrees

−90

−180
0 20 40 60 80 100
k

Figure 5.1: Plots of DTFT and DFT of signal in Problem 5.2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
204 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.3 The DTFT X(ejω ) of the following finite-length sequence using DFT as a computation tool
 −0.9|n|
2e , −5 ≤ n ≤ 5;
x(n) =
0, otherwise.

M ATLAB script:

clc; close all;


n = -5:5; xn = 2*exp(-0.9*abs(n)); N1 = length(xn);
N = 201; xn = [xn,zeros(1,N-N1)]; Xk = dft(xn,N); Xk = real(Xk);
w = linspace(-pi,pi,N); Xk = fftshift(Xk);
Hf_1 = figure(’Units’,’normalized’,’position’,[0.1,0.1,0.8,0.8],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,3]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.3’);
plot(w/pi,Xk,’g’,’linewidth’,1.5); axis([-1,1,-4,5]); hold on;
plot([-1,1],[0,0],’w’,[0,0],[-4,5],’w’,’linewidth’,0.5);
title(’DTFT of x(n) = 2e^{-0.9|n|}, -5\leq n\leq 5’,’fontsize’,10);
xlabel(’\omega/\pi’,’fontsize’,10); ylabel(’Amplitude’,’fontsize’,10);

The plot of the DTFT X(ejω ) is shown in Figure 5.2.

DTFT of x(n) = 2e−0.9|n|, −5≤ n≤ 5


5

2
Amplitude

−1

−2

−3

−4
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
ω/π

Figure 5.2: Plots of DTFT and DFT of signal in Problem 5.3

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 205

P5.4 Plot of the DTFT magnitude and angle of each of the following sequences using the DFT as a computation
tool.
1. x1 (n) = (0.6)|n| [u(n + 10) − u(n − 10)]. M ATLAB script:
n1 = [-10:10]; x1 = (0.6).^abs(n1); N1 = length(n1); N = 200; % Length of DFT
x1 = [x1(11:end), zeros(1,N-N1), x1(1:10)]; % Assemble x1
[X1] = fft(x1,N); w = (0:N/2)*2*pi/N;
mag_X1 = abs(X1(1:N/2+1)); pha_X1 = angle(X1(1:N/2+1))*180/pi;
Hf_1 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.4.1’);
subplot(2,1,1); plot(w/pi,mag_X1,’g’,’linewidth’,1); axis([0,1,0,11]);
title(’Magnitude of DTFT X_1(e^{j\omega})’); ylabel(’Magnitude’);
subplot(2,1,2); plot(w/pi,pha_X1,’g’,’linewidth’,1); axis([0,1,-200,200]);
title(’Angle of DTFT X_1(e^{j\omega})’); ylabel(’Degrees’); xlabel(’\omega/\pi’);
print -deps2 ../EPSFILES/P0504a
The plot of the DTFT X1 (ejω ) is shown in Figure 5.3.

Magnitude of DTFT X1(ejω)


5

4
Magnitude

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Angle of DTFT X1(ejω)


200

100
Degrees

−100

−200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ω/π

Figure 5.3: Plots of DTFT magnitude and phase in Problem 5.4.1

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
206 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

2. x2 (n) = n(0.9)n , 0 ≤ n ≤ 20. M ATLAB script:


n2 = [0:20]; x2 = n2.*(0.9).^n2; N2 = length(n2); N = 400; % Length of DFT
x2 = [x2,zeros(1,N-N2)]; % Assemble x2
[X2] = fft(x2,N); w = (0:N/2)*2*pi/N;
mag_X2 = abs(X2(1:N/2+1)); pha_X2 = angle(X2(1:N/2+1))*180/pi;
Hf_2 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_2,’NumberTitle’,’off’,’Name’,’P5.4.2’);
subplot(2,1,1); plot(w/pi,mag_X2,’g’,’linewidth’,1); %axis([0,1,0,5]);
title(’Magnitude of DTFT X_2(e^{j\omega})’); ylabel(’Magnitude’);
subplot(2,1,2); plot(w/pi,pha_X2,’g’,’linewidth’,1); axis([0,1,-200,200]);
title(’Angle of DTFT X_2(e^{j\omega})’); ylabel(’Degrees’); xlabel(’\omega/\pi’);
print -deps2 ../EPSFILES/P0504b
The plot of the DTFT X2 (ejω ) is shown in Figure 5.4.

Magnitude of DTFT X2(ejω)


60
Magnitude

40

20

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Angle of DTFT X2(ejω)


200

100
Degrees

−100

−200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ω/π

Figure 5.4: Plots of DTFT magnitude and phase in Problem 5.4.2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 207

3. x3 (n) = cos(0.5πn) + j sin(0.5πn), 0 ≤ n ≤ 50. M ATLAB script:


n3 = [0:50]; x3 = cos(0.5*pi*n3)+j*sin(0.5*pi*n3); N = 500;% Length of DFT
N3 = length(n3); x3 = [x3,zeros(1,N-N3)]; % Assemble x3
[X3] = dft(x3,N); w = (0:N/2)*2*pi/N;
mag_X3 = abs(X3(1:N/2+1)); pha_X3 = angle(X3(1:N/2+1))*180/pi;
Hf_3 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_3,’NumberTitle’,’off’,’Name’,’P5.4.3’);
subplot(2,1,1); plot(w/pi,mag_X3,’g’,’linewidth’,1); %axis([0,1,0,7000]);
title(’Magnitude of DTFT X_3(e^{j\omega})’); ylabel(’Magnitude’);
subplot(2,1,2); plot(w/pi,pha_X3,’g’,’linewidth’,1); axis([0,1,-200,200]);
title(’Angle of DTFT X_3(e^{j\omega})’); ylabel(’Degrees’); xlabel(’\omega/\pi’);
print -deps2 ../EPSFILES/P0504c
The plot of the DTFT X3 (ejω ) is shown in Figure 5.5.

Magnitude of DTFT X3(ejω)


60
Magnitude

40

20

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Angle of DTFT X3(ejω)


200

100
Degrees

−100

−200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ω/π

Figure 5.5: Plots of DTFT magnitude and phase in Problem 5.4.3

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
208 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

4. x(n) = {1, 2, 3, 4, 3, 2, 1}. M ATLAB script:


n4 = [-3:3]; x4 = [1,2,3,4,3,2,1]; N4 = length(n4); N = 100; % Length of DFT


[X4] = dft([x4, zeros(1,N-N4)],N); w = (0:N/2)*2*pi/N;
mag_X4 = abs(X4(1:N/2+1)); pha_X4 = angle(X4(1:N/2+1))*180/pi;
Hf_4 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_4,’NumberTitle’,’off’,’Name’,’P5.4.4’);
subplot(2,1,1); plot(w/pi,mag_X4,’g’,’linewidth’,1); axis([0,1,0,20]);
title(’Magnitude of DTFT X_4(e^{j\omega})’); ylabel(’Magnitude’);
subplot(2,1,2); plot(w/pi,pha_X4,’g’,’linewidth’,1); axis([0,1,-200,200]);
title(’Angle of DTFT X_4(e^{j\omega})’); ylabel(’Degrees’); xlabel(’\omega/\pi’);
print -deps2 ../EPSFILES/P0504d
The plot of the DTFT X4 (ejω ) is shown in Figure 5.6.

Magnitude of DTFT X4(ejω)


20

15
Magnitude

10

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Angle of DTFT X4(ejω)


200

100
Degrees

−100

−200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ω/π

Figure 5.6: Plots of DTFT magnitude and phase in Problem 5.4.4

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 209

5. x(n) = {−1, −2, −3, 0, 3, 2, 1}. M ATLAB script:


n5 = [-3:3]; x5 = [-1,-2,-3,0,3,2,1]; N5 = length(n5); N = 100; % Length of DFT


[X5] = dft([x5, zeros(1,N-N5)],N); w = (0:N/2)*2*pi/N;
mag_X5 = abs(X5(1:N/2+1)); pha_X5 = angle(X5(1:N/2+1))*180/pi;
Hf_5 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_5,’NumberTitle’,’off’,’Name’,’P5.4.5’);
subplot(2,1,1); plot(w/pi,mag_X5,’g’,’linewidth’,1); axis([0,1,0,20]);
title(’Magnitude of DTFT X_5(e^{j\omega})’); ylabel(’Magnitude’);
subplot(2,1,2); plot(w/pi,pha_X5,’g’,’linewidth’,1); axis([0,1,-200,200]);
title(’Angle of DTFT X_5(e^{j\omega})’); ylabel(’Degrees’); xlabel(’\omega/\pi’);
print -deps2 ../EPSFILES/P0504e
The plot of the DTFT X5 (ejω ) is shown in Figure 5.7.

Magnitude of DTFT X5(ejω)


20

15
Magnitude

10

0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Angle of DTFT X5(ejω)


200

100
Degrees

−100

−200
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ω/π

Figure 5.7: Plots of DTFT magnitude and phase in Problem 5.4.5

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
210 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.5 Let H(ejω ) be the frequency response of a real, causal impulse response h(n).
  
5 k
1. It is known that Re H ejω = k=0 (0.9) cos ωk. Consider
∞ ∞ ∞
  jω     
−jωk
Re H e = Re h(k)e = h(k) Re e−jωk = h(k) cos ωk
k=0 k=0 k=0

Comparing with the given expression, we obtain


 n
(0.9) , 0≤n≤5
h(n) =
0, else

M ATLAB verification:
n = 0:5; h = (0.9).^n; N1 = length(h); N = 100; h = [h,zeros(1,N-N1)];
H = dft(h,N); Hr = real(H);
k = [0:5]; w = linspace(0,2*pi,N+1);
Hr_check = (0.9.^k)*cos(k’*w(1:end-1));
error = max(abs(Hr-Hr_check))
error =
4.0856e-014
  
5 π  
2. It is known that Im H ejω = =0 2 sin ω and −π H ejω dω = 0. From the second condition
 π  
H ejω dω = h (0) = 0
−π

Consider
∞ ∞ ∞
  jω     
Im H e = Im h()e−jω = h () Im e−jω = − h () sin ω
=0 =0 =0

Comparing with the given expression, we obtain



−2n, 0≤n≤5
h(n) =
0, else

M ATLAB verification:
n = 0:5; h = -2*n; N1 = length(h); N = 100; h = [h,zeros(1,N-N1)];
H = dft(h,N); Hi = imag(H);
l = [0:5]; w = linspace(0,2*pi,N+1);
Hi_check = 2*l*sin(l’*w(1:end-1));
error = max(abs(Hi-Hi_check))
error =
3.8014e-013

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 211

P5.6 Let X(k) denote the N -point DFT of an N -point sequence x(n). The DFT X(k) itself is an N -point
sequence.
N

−1 N

−1
1. The N -point DFT of x (n): X (k) = x (m) WNmk . The N -point DFT of X (k): y (n) = X (k) WNkn .
m=0 k=0
Hence,
−1
N −1 −1 −1

N  
N 
N
y (n) = x (m) WNmk WNkn = x (m) WNmk WNkn , 0 ≤ n ≤ N − 1
k=0 m=0 m=0 k=0

N −1 
N −1 
N −1 ∞

(m+n)k
= x (m) WN = x (m) N δ (m + n − rN ) , 0 ≤ n ≤ N − 1
m=0 k=0 m=0 r=−∞


= N x (−n + rN ) = N x ((−n))N , 0 ≤ n ≤ N − 1
r=−∞

This means that y (n) is a “circularly folded and amplified (by N )” version of x (n). Continuing further,
if we take two more DFTs of x (n) then

N -point N -point N -point N -point


x (n) −→ −→ −→ −→ −→ N 2 x (n)
DFT DFT DFT DFT

Therefore, if a given DFT function is working correctly then four successive applications of this function
on any arbitrary signal will produce the same signal (multiplied by N 2 ). This approach can be used to
verify a DFT function.
2. M ATLAB function for circular folding:
function x2 = circfold(x1,N)
% Circular folding with respect to N
% ----------------------------------
% function x2 = circfold(x1,N)
% x2(n) = x1((-n) mod N)
%
x2 = real(dft(dft(x1,N),N))/N;
3. M ATLAB verification:
x = [1,3,5,7,9,-7,-5,-3,-1], N = length(x);
x =
1 3 5 7 9 -7 -5 -3 -1
Y = circfold(x,N)
Y =
1.000 -1.000 -3.000 -5.000 -7.000 9.000 7.000 5.000 3.000

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
212 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.7 Let x̃(n) be a periodic sequence with period N and let



ỹ(n) = x̃(−n) = x̃(N − n)
that is, ỹ(n) is a periodically folded version of x̃(n). Let X̃(k) and Ỹ (k) be the DFS sequences.
1. Consider

N −1 
N −1 
N −1
Ỹ (k) = DFS [ỹ(n)] = ỹ(n)WNnk = x̃(−n)WNnk = x̃(N − n)WNnk
n=0 n=0 n=0

N 
N −1 
N −1
(N −)k
= x̃()WN = x̃()WNN k WN−k = x̃()WN−k (. .. periodic)
=1 =0 =0

= X̃(−k) = X̃(N − k)
2. Let x̃(n) = {2, 4, 6, 1, 3, 5}PERIODIC with N = 6.

(a) Sketch of ỹ(n) for 0 ≤ n ≤ 5:
One period of the periodic sequence xtilde(n)
7
6
5
Amplitude

4
3
2
1
0
0 1 2 3 4 5
n
(b) Computation of X̃(k) for 0 ≤ k ≤ 5:
X_tilde = dft(x_tilde,N)
X_tilde =
Columns 1 through 4
21.0000 1.0000 - 1.7321i -6.0000 + 3.4641i 1.0000 - 0.0000i
Columns 5 through 6
-6.0000 - 3.4641i 1.0000 + 1.7321i
(c) Computation of Ỹ (k) for 0 ≤ k ≤ 5:
y_tilde = [x_tilde(1),fliplr(x_tilde(2:end))];
Y_tilde = dft(y_tilde,N)
Y_tilde =
Columns 1 through 4
21.0000 1.0000 + 1.7321i -6.0000 - 3.4641i 1.0000 + 0.0000i
Columns 5 through 6
-6.0000 + 3.4641i 1.0000 - 1.7321i
(d) M ATLAB verification:
W_tilde = [X_tilde(1),fliplr(X_tilde(2:end))];
error = max(abs(Y_tilde - W_tilde))
error =
2.5434e-014

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 213

P5.8 Determine the periodic sequences given the following periodic DFS coefficients. First use the IDFS defi-
nition and then verify your answers using M ATLAB .
1. X̃1 (k) = {4, 3j, −3j}, N = 3

Xtilde1 = [4,j*3,-j*3]; N = 3; xtilde1 = idfs(Xtilde1,N)


xtilde1 =
1.3333 -0.3987 + 0.0000i 3.0654 - 0.0000i
2. X̃2 (k) = {j, 2j, 3j, 4j}, N = 4

Xtilde2 = [j,j*2,j*3,j*4]; N = 4; xtilde2 = idfs(Xtilde2,N)


xtilde2 =
0 + 2.5000i 0.5000 - 0.5000i -0.0000 - 0.5000i -0.5000 - 0.5000i
3. X̃3 (k) = {1, 2 + 3j, 4, 2 − 3j}, N = 4

Xtilde3 = [1,2+j*3,4,2-j*3]; N = 4; xtilde3 = idfs(Xtilde3,N)


xtilde3 =
2.2500 -2.2500 + 0.0000i 0.2500 0.7500 - 0.0000i
4. X̃4 (k) = {0, 0, 2, 0}, N = 5

Xtilde4 = [0,0,2,0,0]; N = 5; xtilde4 = idfs(Xtilde4,N)


xtilde4 =
Columns 1 through 4
0.4000 -0.3236 + 0.2351i 0.1236 - 0.3804i 0.1236 + 0.3804i
Column 5
-0.3236 - 0.2351i
5. X̃5 (k) = {3, 0, 0, 0, −3, 0, 0, 0}, N = 8
Xtilde5 = [3,0,0,0,-3,0,0,0]; N = 8; xtilde5 = idfs(Xtilde5,N)
xtilde5 =
Columns 1 through 4
0 0.7500 - 0.0000i 0 + 0.0000i 0.7500 - 0.0000i
Columns 5 through 8
0 + 0.0000i 0.7500 - 0.0000i 0 + 0.0000i 0.7500 - 0.0000i

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
214 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.9 Let x̃1 (n) be periodic with fundamental period N = 40 where one period is given by

5 sin(0.1πn), 0 ≤ n ≤ 19
x̃1 (n) =
0, 20 ≤ n ≤ 39

and let x̃2 (n) be periodic with fundamental period N = 80, where one period is given by

5 sin(0.1πn), 0 ≤ n ≤ 19
x̃2 (n) =
0, 20 ≤ n ≤ 79

These two periodic sequences differ in their periodicity but otherwise have the same non-zero samples.
1. Computation of X̃1 (k) using M ATLAB :
n1 = [0:39]; xtilde1 = [5*sin(0.1*pi*[0:19]),zeros(1,20)]; N1 = length(n1);
[Xtilde1] = dft(xtilde1,N1); k1 = n1;
mag_Xtilde1 = abs(Xtilde1); pha_Xtilde1 = angle(Xtilde1)*180/pi;
zei = find(mag_Xtilde1 < 1000*eps);
pha_Xtilde1(zei) = zeros(1,length(zei));
Hf_1 = figure(’Units’,’normalized’,’position’,[0.1,0.1,0.8,0.8],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,5]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.9.1’);
subplot(3,1,1); H_s1 = stem(n1,xtilde1,’filled’); set(H_s1,’markersize’,3);
axis([-1,N1,-6,6]);
title(’One period of the periodic sequence xtilde_1(n)’,’fontsize’,10);
ntick = [n1(1):2:n1(N1),N1]’; ylabel(’Amplitude’);
set(gca,’XTickMode’,’manual’,’XTick’,ntick,’FontSize’,8);
subplot(3,1,2); H_s2 = stem(k1,mag_Xtilde1,’filled’); set(H_s2,’markersize’,3);
axis([-1,N1,0,max(mag_Xtilde1)+10]);
title(’Magnitude of Xtilde_1(k)’,’fontsize’,10); ylabel(’Magnitude’);
ktick = [k1(1):2:k1(N1),N1]’;
set(gca,’XTickMode’,’manual’,’XTick’,ktick,’FontSize’,8)
subplot(3,1,3); H_s3 = stem(k1,pha_Xtilde1,’filled’); set(H_s3,’markersize’,3);
title(’Phase of Xtilde_1(k)’,’fontsize’,10); xlabel(’k’); ylabel(’Degrees’);
ktick = [k1(1):2:k1(N1),N1]’; axis([-1,N1,-200,200]);
set(gca,’XTickMode’,’manual’,’XTick’,ktick,’FontSize’,8);
set(gca,’YTickMode’,’manual’,’YTick’,[-180;-90;0;90;180]);
Plots of x̃1 (n) and X̃1 (k) are shown in Figure 5.8.
2. Computation of X̃2 (k) using M ATLAB :
n2 = [0:79]; xtilde2 = [xtilde1, zeros(1,40)]; N2 = length(n2);
[Xtilde2] = dft(xtilde2,N2); k2 = n2;
mag_Xtilde2 = abs(Xtilde2); pha_Xtilde2 = angle(Xtilde2)*180/pi;
zei = find(mag_Xtilde2 < 1000*eps);
pha_Xtilde2(zei) = zeros(1,length(zei));
Hf_2 = figure(’Units’,’normalized’,’position’,[0.1,0.1,0.8,0.8],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,5]);
set(Hf_2,’NumberTitle’,’off’,’Name’,’P5.9.2’);
subplot(3,1,1); H_s1 = stem(n2,xtilde2,’filled’); set(H_s1,’markersize’,3);

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 215

One period of the periodic sequence xtilde1(n)


5

Amplitude
0

−5
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40

Magnitude of Xtilde1(k)
60
Magnitude

40

20

0
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40

Phase of Xtilde1(k)
180
90
Degrees

0
−90
−180
0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40
k

Figure 5.8: Plots of x̃1 (n) and X̃1 (k) in Problem 5.9.1

title(’One period of the periodic sequence xtilde2(n)’,’fontsize’,10);


ntick = [n2(1):5:n2(N2),N2]’; ylabel(’xtilde2’); axis([-1,N2,-6,6]);
set(gca,’XTickMode’,’manual’,’XTick’,ntick)
subplot(3,1,2); H_s2 = stem(k2,mag_Xtilde2,’filled’); set(H_s2,’markersize’,3);
axis([-1,N2,0,60]);
title(’Magnitude of Xtilde2(k)’,’fontsize’,10); ylabel(’|Xtilde2|’)
ktick = [k2(1):5:k2(N2),N2]’;
set(gca,’XTickMode’,’manual’,’XTick’,ktick)
subplot(3,1,3); H_s3 = stem(k2,pha_Xtilde2,’filled’); set(H_s3,’markersize’,3);
title(’Phase of Xtilde2(k)’,’fontsize’,10); xlabel(’k’); ylabel(’Degrees’)
ktick = [k2(1):5:k2(N2),N2]’; axis([-1,N2,-200,200]);
set(gca,’XTickMode’,’manual’,’XTick’,ktick)
set(gca,’YTickMode’,’manual’,’YTick’,[-180;-90;0;90;180])
Plots of x̃2 (n) and X̃2 (k) are shown in Figure 5.9.

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
216 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

3. Changing the period from N = 40 to N = 80 resulted in a lower frequency sampling interval (higher
frequency resolution) ω1 , i.e., in (5) ω1 = π/20 and in (5) ω2 = π/40. Hence there are more terms in the
DFS expansion of x̃2 (n). The shape of the DTFT begins to fill in with N = 80.

One period of the periodic sequence xtilde2(n)


5
xtilde2

−5
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80

Magnitude of Xtilde2(k)
60

40
|Xtilde2|

20

0
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80

Phase of Xtilde2(k)
180

90
Degrees

−90

−180
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80
k

Figure 5.9: Plots of Magnitude and Phase of X̃2 (k) in Problem 5.9.2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 217

P5.10 Consider the periodic sequence x̃1 (n) given in Problem 5.9. Let x̃2 (n) be periodic with fundamental
period N = 40, where one period is given by

x̃1 (n), 0 ≤ n ≤ 19
x̃2 (n) =
−x̃1 (n − 20), 20 ≤ n ≤ 39

1. Determine analytically the DFS X̃2 (k) in terms of X̃1 (k).


Note that the sequence x̃2 (n) can be expressed as x̃2 (n) = x̃1 (n) − x̃1 (n − 20). Hence
 
X̃2 (k) = X̃1 (k) − W4020k
X̃1 (k) = 1 − e−j2π20k/40 X̃1 (k)

  0, k ∼ even ,
= 1 − (−1)k X̃1 (k) =
2X̃1 (k), k ∼ odd.

2. Computation of the DFS X̃2 (k) using M ATLAB :


n1 = [0:19]; xtilde1 = [5*sin(0.1*pi*n1)];
n2 = [0:39]; xtilde2 = [xtilde1, -xtilde1]; N2 = length(n2);
[Xtilde2] = dft(xtilde2,N2); k2 = n2;
mag_Xtilde2 = abs(Xtilde2); pha_Xtilde2 = angle(Xtilde2)*180/pi;
zei = find(mag_Xtilde2 < 1000*eps);
pha_Xtilde2(zei) = zeros(1,length(zei));
Hf_1 = figure(’Units’,’normalized’,’position’,[0.1,0.1,0.8,0.8],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.10.2’);
subplot(3,1,1); H_s1 = stem(n2,xtilde2,’filled’); set(H_s1,’markersize’,3);
axis([-1,N2,-6,6]);
title(’One period of the periodic sequence xtilde_2(n)’,’fontsize’,10);
ntick = [n2(1):5:n2(N2),N2]’; ylabel(’Amplitude’);
set(gca,’XTickMode’,’manual’,’XTick’,ntick)
subplot(3,1,2); H_s2 = stem(k2,mag_Xtilde2,’filled’); set(H_s2,’markersize’,3);
axis([-1,N2,0,100]);
title(’Magnitude of Xtilde2(k)’,’fontsize’,10); ylabel(’Magnitude’)
ktick = [k2(1):5:k2(N2),N2]’;
set(gca,’XTickMode’,’manual’,’XTick’,ktick)
subplot(3,1,3); H_s3 = stem(k2,pha_Xtilde2,’filled’); set(H_s3,’markersize’,3);
title(’Phase of Xtilde2(k)’,’fontsize’,10); xlabel(’k’); ylabel(’Degrees’)
ktick = [k2(1):5:k2(N2),N2]’; axis([-1,N2,-200,200]);
set(gca,’XTickMode’,’manual’,’XTick’,ktick)
set(gca,’YTickMode’,’manual’,’YTick’,[-180;-90;0;90;180])
Plots of x̃2 (n) and X̃2 (k) are shown in Figure 5.10.
3. Verify your answer in part 1 above using the plots of X̃1 (k) and X̃2 (k)?
Comparing DFS X̃2 (k) in Figure 5.10 with X̃1 (k) in Figure 5.8, we note that every even-ordered sample
of X̃2 (k) is zero and every odd-ordered sample is twice that of X̃1 (k).

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
218 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

One period of the periodic sequence xtilde2(n)


5
Amplitude

−5
0 5 10 15 20 25 30 35 40
Magnitude of Xtilde2(k)
100
Magnitude

50

0
0 5 10 15 20 25 30 35 40
Phase of Xtilde2(k)
180
90
Degrees

0
−90
−180
0 5 10 15 20 25 30 35 40
k
Figure 5.10: Plots of Magnitude and Phase of X̃2 (k) in Problem 5.10.2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 219

P5.11 Consider the periodic sequence x̃1 (n) given in Problem 5.9. Let x̃3 (n) be periodic with period 80, ob-
tained by concatenating two periods of x̃1 (n), i.e.,

x̃3 (n) = [x̃1 (n), x̃1 (n)]PERIODIC

Clearly, x̃3 (n) is different from x̃2 (n) of Problem 5.9 even though both of them are periodic with period
80.
1. Computation and plot of the DFS X̃3 (k) using M ATLAB :
n1 = [0:39]; xtilde1 = [5*sin(0.1*pi*[0:19]),zeros(1,20)];
n3 = [0:79]; xtilde3 = [xtilde1, xtilde1]; N3 = length(n3);
[Xtilde3] = dft(xtilde3,N3); k3 = n3;
mag_Xtilde3 = abs(Xtilde3); pha_Xtilde3 = angle(Xtilde3)*180/pi;
zei = find(mag_Xtilde3 < 0.00001);
pha_Xtilde3(zei) = zeros(1,length(zei));
Hf_1 = figure(’Units’,’normalized’,’position’,[0.1,0.1,0.8,0.8],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,5]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.11.1’);
subplot(3,1,1); H_s1 = stem(n3,xtilde3,’filled’); set(H_s1,’markersize’,3);
title(’One period of the periodic sequence xtilde_3(n)’,’fontsize’,10);
ylabel(’Amplitude’); ntick = [n3(1):5:n3(N3),N3]’;axis([-1,N3,-6,6]);
set(gca,’XTickMode’,’manual’,’XTick’,ntick,’fontsize’,8)
subplot(3,1,2); H_s2 = stem(k3,mag_Xtilde3,’filled’); set(H_s2,’markersize’,3);
axis([-1,N3,min(mag_Xtilde3),max(mag_Xtilde3)]);
title(’Magnitude of Xtilde_3(k)’,’fontsize’,10); ylabel(’Magnitude’)
ktick = [k3(1):5:k3(N3),N3]’; set(gca,’XTickMode’,’manual’,’XTick’,ktick)
subplot(3,1,3); H_s3 = stem(k3,pha_Xtilde3,’filled’); set(H_s3,’markersize’,3);
title(’Phase of Xtilde3(k)’,’fontsize’,10); xlabel(’k’); ylabel(’Degrees’);
ktick = [k3(1):5:k3(N3),N3]’;axis([-1,N3,-180,180]);
set(gca,’XTickMode’,’manual’,’XTick’,ktick)
set(gca,’YTickMode’,’manual’,’YTick’,[-180;-90;0;90;180])
Plots of x̃3 (n) and X̃3 (k) are shown in Figure 5.11.

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
220 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

One period of the periodic sequence xtilde3(n)


5
Amplitude

−5
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80

Magnitude of Xtilde3(k)
100
Magnitude

50

0
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80

Phase of Xtilde3(k)
180

90
Degrees

−90

−180
0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80
k

Figure 5.11: Plots of x̃3 (n) and X̃3 (k) in Problem 5.11.1

2. Plots of X̃3 (k) have one zero between every sample of X̃1 (k). (In general, for phase plots, we do get non-
zero phase values when the magnitudes are zero. Clearly these phase values have no meaning and should
be ignored. This happens because of a particular algorithm used by M ATLAB. We avoided this problem
by using the find function.) This makes sense because sequences x̃1 (n) and x̃3 (n), when viewed over
−∞ < n < ∞ interval, look exactly same. The effect of periodicity doubling is in the doubling of
magnitude of each sample.
1. We can now generalize this argument. If
⎧ ⎫
⎨ ⎬
x̃M (n) = x̃1 (n) , x̃1 (n) , . . . , x̃1 (n)
⎩  ⎭
M times PERIODIC

then there will be (M − 1) zeros between samples of X̃M (k). The magnitudes of non-zero samples of
X̃M (k) will be M times the magnitudes of the samples of X̃1 (k), i.e.,

X̃M (M k) = M X̃1 (k) , k = 0, 1, . . . , N − 1


X̃M (k) = 0 , k = 0, 1, . . . , M N

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 221

P5.12 Let X(ejω ) be the DTFT of a finite-length sequence



⎨ n + 1, 0 ≤ n ≤ 49;
x(n) = 100 − n, 50 ≤ n ≤ 99;

0, otherwise.

1. Let
10-point  
y1 (n) = IDFS X(ej0 ), X(ej2π/10 ), X(ej4π/10 ), . . . , X(ej18π/10 )
 
which is a 10-point IDFS of ten samples of X ejω on the unit circle. Thus


y1 (n) = x(n − 10r) = {1 + 11 + · · · + 41 + 50 + 40 + · · · + 10,
r=−∞

2 + 12 + · · · + 42 + 49 + · · · + 9, · · · }periodic
= {255, 255, . . . , 255}periodic

M ATLAB verification:
n = 0:99; x = [n(1:50)+1,100-n(51:100)];
N1 = 10; k1 = 0:N1-1; w1 = 2*pi*k1/N1;
Y1 = dtft(x,n,w1); y1 = real(idfs(Y1,N1));
See the stem plot of y1 (n) in Figure 5.12.
2. Let
200-point  
y2 (n) = IDFS X(ej0 ), X(ej2π/200 ), X(ej4π/200 ), . . . , X(ej398π/200 )
 
which is a 200-point IDFS of 200 samples of X ejω on the unit circle. Thus
 
x(n), 0 ≤ n ≤ 49;
y2 (n) =
0, 50 ≤ n ≤ 100. periodic

M ATLAB verification:
n = 0:99; x = [n(1:50)+1,100-n(51:100)];
N2 = 200; k2 = 0:N2-1; w2 = 2*pi*k2/N2;
Y2 = dtft(x,n,w2); y2 = real(idfs(Y2,N2));
See the stem plot of y1 (n) in Figure 5.12.
3. The sequence y1 (n) is a 10-point aliasing version on x(n) while y2 (n) is a zero-padded version of x(n).

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
222 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

Original 100−point sequence x(n)

40
Amplitude

20

0
0 10 20 30 40 50 60 70 80 90 100

Aliased sequence y1(n)


300
Amplitude

200

100

0
0 1 2 3 4 5 6 7 8 9 10 11

Unaliased sequence y2(n)

50
40
Amplitude

30
20
10
0
−1 49 99 149 199
n

Figure 5.12: Plots of y1 (n) and y2 (k) in Problem 5.12

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 223

P5.13 The first six values of the 10-point DFT of a real-valued sequence x(n) are given by

{10, −2 + j3, 3 + j4, 2 − j3, 4 + j5, 12}

DFT computations using DFT properties:


1. x1 (n) = x((2 − n))1 0: Circular-folding followed by circ-shifting by 2.
M ATLAB script:
N = 10; X = [10,-2+j*3,3+j*4,2-j*3,4+j*5,12];
X = [X,conj(X(5:-1:2))]; x = real(idft(X,N))
WN = exp(-j*2*pi/N); k = 0:N-1; m = 2;
X1 = circfold(X,N); X1 = (WN.^(m*k)).*X1
% Matlab Verification
x1 = circfold(x,N); x1 = cirshftt(x1,m,N); X12 = dft(x1,N)
difference = max(abs(X1-X12))
x =
Columns 1 through 7
3.6000 -2.2397 1.0721 -1.3951 3.7520 1.2000 0.6188
Column 8 through 10
0.0217 1.4132 1.9571
X1 =
Columns 1 through 4
10.0000 + 0.0000i -3.4712 + 0.9751i -4.7782 + 1.4727i -3.3814 - 1.2515i
Columns 5 through 8
5.9914 + 2.2591i 12.0000 + 0.0000i 5.9914 - 2.2591i -3.3814 + 1.2515i
Columns 9 through 10
-4.7782 - 1.4727i -3.4712 - 0.9751i
X12 =
Columns 1 through 4
10.0000 + 0.0000i -3.4712 + 0.9751i -4.7782 + 1.4727i -3.3814 - 1.2515i
Columns 5 through 8
5.9914 + 2.2591i 12.0000 + 0.0000i 5.9914 - 2.2591i -3.3814 + 1.2515i
Columns 9 through 10
-4.7782 - 1.4727i -3.4712 - 0.9751i
difference =
1.2462e-014

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
224 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

2. x2 (n) = x((n + 5))10 : 10-point circular shifting by −5.


M ATLAB script:
N = 10; X = [10,-2+j*3,3+j*4,2-j*3,4+j*5,12];
X = [X,conj(X(5:-1:2))]; x = real(idft(X,N))
WN = exp(-j*2*pi/N); k = 0:N-1; m = -5;
X2 = (WN.^(m*k)).*dft(x,N)
% Matlab verification
x2 = cirshftt(x,m,N); X22 = dft(x2,N)
difference = max(abs(X2-X22))
x =
Columns 1 through 7
3.6000 -2.2397 1.0721 -1.3951 3.7520 1.2000 0.6188
Column 8 through 10
0.0217 1.4132 1.9571
X2 =
Columns 1 through 4
10.0000 2.0000 - 3.0000i 3.0000 + 4.0000i -2.0000 + 3.0000i
Columns 5 through 8
4.0000 + 5.0000i -12.0000 + 0.0000i 4.0000 - 5.0000i -2.0000 - 3.0000i
Columns 9 through 10
3.0000 - 4.0000i 2.0000 + 3.0000i
X22 =
Columns 1 through 4
10.0000 2.0000 - 3.0000i 3.0000 + 4.0000i -2.0000 + 3.0000i
Columns 5 through 8
4.0000 + 5.0000i -12.0000 - 0.0000i 4.0000 - 5.0000i -2.0000 - 3.0000i
Columns 9 through 10
3.0000 - 4.0000i 2.0000 + 3.0000i
difference =
3.2150e-014

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 225

3. x3 (n) = x(n)x((−n))10 : Multiplication by circularly-folded sequence.


M ATLAB script:
N = 10; X = [10,-2+j*3,3+j*4,2-j*3,4+j*5,12];
X = [X,conj(X(5:-1:2))]; x = real(idft(X,N))
X3 = circfold(X,N), X3 = circonvf(X,X3,N)/N
% Matlab verification
x3 = circfold(x,N); x3 = x.*x3; X32 = dft(x3,N)
difference = max(abs(X3-X32))
x =
Columns 1 through 7
3.6000 -2.2397 1.0721 -1.3951 3.7520 1.2000 0.6188
Column 8 through 10
0.0217 1.4132 1.9571
X3 =
Columns 1 through 4
10.0000 + 0.0000i -2.0000 - 3.0000i 3.0000 - 4.0000i 2.0000 + 3.0000i
Columns 5 through 8
4.0000 - 5.0000i 12.0000 + 0.0000i 4.0000 + 5.0000i 2.0000 - 3.0000i
Columns 9 through 10
3.0000 + 4.0000i -2.0000 + 3.0000i
X3 =
Columns 1 through 4
19.2000 + 0.0000i 10.2000 - 0.0000i 15.6000 + 0.0000i 6.4000 + 0.0000i
Columns 5 through 8
10.8000 - 0.0000i 24.4000 + 0.0000i 10.8000 + 0.0000i 6.4000 - 0.0000i
Columns 9 through 10
15.6000 + 0.0000i 10.2000 + 0.0000i
X32 =
Columns 1 through 4
19.2000 + 0.0000i 10.2000 - 0.0000i 15.6000 - 0.0000i 6.4000 + 0.0000i
Columns 5 through 8
10.8000 - 0.0000i 24.4000 - 0.0000i 10.8000 + 0.0000i 6.4000 - 0.0000i
Columns 9 through 10
15.6000 - 0.0000i 10.2000 - 0.0000i
difference =
2.4416e-014

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
226 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

4. x4 (n) = x(n) 10jx((−n))10 : 10-point circular convolution with a circularly-folded sequence.


M ATLAB script:
N = 10; n = [0:N-1]; X = [10,-2+j*3,3+j*4,2-j*3,4+j*5,12];
X = [X,conj(X(5:-1:2))]; x = real(idft(X,N))
X0 = X(mod(-k,N)+1); X4 = X .* X0
% Verification
x4 = circonvt(x,x(mod(-n,N)+1),N); X42 = dft(x4,N)
difference = max(abs(X4-X42))
x =
Columns 1 through 7
3.6000 -2.2397 1.0721 -1.3951 3.7520 1.2000 0.6188
Column 8 through 10
0.0217 1.4132 1.9571
X4 =
100 13 25 13 41 144 41 13 25 13
X42 =
1.0e+002
* Columns 1 through 4
1.0000 0.1300 + 0.0000i 0.2500 + 0.0000i 0.1300 - 0.0000i
Columns 5 through 8
0.4100 - 0.0000i 1.4400 + 0.0000i 0.4100 + 0.0000i 0.1300 + 0.0000i
Columns 9 through 10
0.2500 - 0.0000i 0.1300 - 0.0000i
difference =
1.0378e-013

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 227

5. x5 (n) = x(n)e−j4πn/5 : Circular-shifting by −4 in the frequency-domain.


M ATLAB script:
N = 10; n = [0:N-1]; X = [10,-2+j*3,3+j*4,2-j*3,4+j*5,12]; m = 4;
X = [X,conj(X(5:-1:2))]; x = real(idft(X,N))
X5 = [X(m+1:end),X(1:m)]
% Verification
WN = exp(-j*2*pi/N); x5 = x.*(WN.^(m*n)); X51 = dft(x5,N)
difference = max(abs(X5-X51))
x =
Columns 1 through 7
3.6000 -2.2397 1.0721 -1.3951 3.7520 1.2000 0.6188
Column 8 through 10
0.0217 1.4132 1.9571
X5 =
Columns 1 through 4
4.0000 + 5.0000i 12.0000 4.0000 - 5.0000i 2.0000 + 3.0000i
Columns 5 through 8
3.0000 - 4.0000i -2.0000 - 3.0000i 10.0000 -2.0000 + 3.0000i
Columns 9 through 10
3.0000 + 4.0000i 2.0000 - 3.0000i
X51 =
Columns 1 through 4
4.0000 + 5.0000i 12.0000 + 0.0000i 4.0000 - 5.0000i 2.0000 + 3.0000i
Columns 5 through 8
3.0000 - 4.0000i -2.0000 - 3.0000i 10.0000 + 0.0000i -2.0000 + 3.0000i
Columns 9 through 10
3.0000 + 4.0000i 2.0000 - 3.0000i
difference =
2.4895e-014

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
228 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.14 Complex-valued N -point sequence x(n) can be decomposed into N -point circular-conjugate-
symmetric and circular-conjugate-antisymmetric sequences using the following relations
1
xccs (n)= [x(n) + x∗ ((−n))N ]
2
1
xcca (n)= [x(n) − x∗ ((−n))N ]
2
If XR (k) and XI (k) are the real and imaginary parts of the N -point DFT of x(n), then
DFT [xccs (n)] = XR (k) and DFT [xcca (n)] = jXI (k)
1. Using the DFT properties of conjugation and circular folding, we obtain
1
DFT [xccs (n)] = {DFT [x(n)] + DFT [x∗ ((−n))N ]}
2
1 
= X(k) + X̂ ∗ ((−k))N , where X̂(k) = DFT [x((−n))N ]
2
1
= {X(k) + X ∗ (k)} = Re [X(k)] = XR (k)
2
similarly, we can show that
DFT [xcca (n)] = j Im [X(k)] = jXI (k)
2. The modified circevod function:
function [xccs, xcca] = circevod(x)
% Complex-valued signal decomposition into circular-even and circular-odd parts
% ----------------------------------------------------------------------------
-
% [xccs, xcca] = circecod(x)
%
N = length(x); n = 0:(N-1);
xccs = 0.5*(x + conj(x(mod(-n,N)+1)));
xcca = 0.5*(x - conj(x(mod(-n,N)+1)));
3. Let X(k) = [3 cos(0.2πk)+j4 sin(0.1πk)][u(k)−u(k−20)] be a 20-point DFT. M ATLAB verification:
N = 20; k = 0:N-1; X = 3*cos(0.2*pi*k) + j*sin(0.1*pi*k);
n = 0:N-1; x = idft(X,N); [xccs, xcca] = circevod(x);
Xccs = dft(xccs,N); Xcca = dft(xcca,N);
Hf_1 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’paperunits’,’inches’,’paperposition’,[0,0,6,4],’color’,[0,0,0]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.14.3’);
subplot(2,2,1); H_s1 = stem(n,real(X),’filled’); set(H_s1,’markersize’,3);
title(’X_R(k)’); ylabel(’Amplitude’); axis([-0.5,20.5,-4,4]);
subplot(2,2,3); H_s2 = stem(n,real(Xccs),’filled’); set(H_s2,’markersize’,3);
title(’X_{ccs}(k)’); ylabel(’Amplitude’); xlabel(’k’); axis([-0.5,20.5,-4,4]);
subplot(2,2,2); H_s3 = stem(n,imag(X),’filled’); set(H_s3,’markersize’,3);
title(’X_I(k)’); ylabel(’Amplitude’); axis([-0.5,20.5,-1.1,1.1]);
subplot(2,2,4); H_s4 = stem(n,imag(Xcca),’filled’); set(H_s4,’markersize’,3);
title(’X_{cca}(k)’); ylabel(’Amplitude’); xlabel(’k’); axis([-0.5,20.5,-1.1,1.1]);

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 229

The plots are shown in Figure 5.13.

XR(k) XI(k)
4
1

2 0.5
Amplitude

Amplitude
0 0

−2 −0.5

−1
−4
0 5 10 15 20 0 5 10 15 20

Xccs(k) Xcca(k)
4
1

2 0.5
Amplitude

0 Amplitude 0

−2 −0.5

−1
−4
0 5 10 15 20 0 5 10 15 20
k k

Figure 5.13: Plots in Problem P5.14.3

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
230 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.15 (Two real DFTs using one complex DFT) If X(k) is the N -point DFT of an N -point complex-valued
sequence
x(n) = xR (n) + jxI (n)
where xR (n) and xI (n) are the real and imaginary parts of x(n), then

DFT [xR (n)] = Xccs (k) and DFT [jxI (n)] = Xcca (k)

where Xccs (k) and Xcca (k) are the circular-even and circular-odd components of X(k) as defined in
Problem 5.14.
1. Analytical proof: Consider
 1
XR (k)= DFT [xR (n)] = {DFT [x(n)] + DFT [x∗ (n)]}
2
1 
= {X(k) + X ∗ ((−k))N } =Xccs
2
Similarly

 1 ⎪
jXI (k) = DFT [jxI (n)] = {DFT [x(n)] − DFT [x (n)]} ⎬

Xcca (k)
2 ⇒ XI (k) = = −jXcca (k)
1  ⎪ j
= {X(k) − X ∗ ((−k))N } =Xcca ⎭
2
2. This property can be used to compute the DFTs of two real-valued N -point sequences using one N -
point DFT operation. Specifically, let x1 (n) and x2 (n) be two N -point sequences. Then we can form
a complex-valued sequence
x(n) = x1 (n) + jx2 (n)
and use the above property. M ATLAB function real2dft:
function [X1,X2] = real2dft(x1,x2,N)
% DFTs of two real sequences
% [X1,X2] = real2dft(x1,x2,N)
% X1 = N-point DFT of x1
% X2 = N-point DFT of x2
% x1 = real-valued sequence of length <= N
% x2 = real-valued sequence of length <= N
% N = length of DFT
%
% Check for length of x1 and x2
if length(x1) > N
error(’*** N must be >= the length of x1 ***’)
end
if length(x2) > N
error(’*** N must be >= the length of x2 ***’)
end
N1 = length(x1); x1 = [x1 zeros(1,N-N1)];
N2 = length(x2); x2 = [x2 zeros(1,N-N2)];
x = x1 + j*x2;
X = dft(x,N);
[X1, X2] = circevod(X); X2 = X2/j;

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 231

We will also need the circevod function for complex sequences (see Problem P5.14). This can be
obtained from the one given in the text by two simple changes.
function [xccs, xcca] = circevod(x)
% Complex signal decomposition into circular-even and circular-odd parts
% ----------------------------------------------------------------------
% [xccs, xcca] = circecod(x)
%
N = length(x); n = 0:(N-1);
xccs = 0.5*(x + conj(x(mod(-n,N)+1)));
xcca = 0.5*(x - conj(x(mod(-n,N)+1)));
3. Compute and plot the DFTs of the following two sequences using the above function

x1 (n) = cos(0.1πn), x2 (n) = sin(0.2πn); 0 ≤ n ≤ 39

M ATLAB verification:
N = 40; n = 0:N-1; x1 = cos(0.1*pi*n); x2 = sin(0.2*pi*n);
[X1,X2] = real2dft(x1,x2,N);
X11 = dft(x1,N); X21 = dft(x2,N);
difference = max(abs(X1-X11))
difference = max(abs(X2-X21))
difference =
3.6876e-013
difference =
3.6564e-013

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
232 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.16 Circular shifting: The M ATLAB routine cirshftf.m to implement circular shift is written using the
frequency-domain property
  
y(n)=x((n − m))N = IDFT X(k)WNmk

This routine will be used in the next problem to generate a circulant matrix and has the following features.
If m is a scaler then y(n) is circularly shifted sequence (or array). If m is a vector then y(n) is a matrix,
each row of which is a circular shift in x(n) corresponding to entries in the vector m.

function y = cirshftf(x,m,N)
% Circular shift of m samples wrt size N in sequence x: (freq domain)
% -------------------------------------------------------------------
% function y=cirshift(x,m,N)
% y : output sequence containing the circular shift
% x : input sequence of length <= N
% m : sample shift
% N : size of circular buffer
%
% Method: y(n) = idft(dft(x(n))*WN^(mk))
%
% If m is a scalar then y is a sequence (row vector)
% If m is a vector then y is a matrix, each row is a circular shift
% in x corresponding to entries in vecor m
% M and x should not be matrices
%
% Check whether m is scalar, vector, or matrix
[Rm,Cm] = size(m);
if Rm > Cm
m = m’; % make sure that m is a row vector
end
[Rm,Cm] = size(m);
if Rm > 1
error(’*** m must be a vector ***’) % stop if m is a matrix
end
% Check whether x is scalar, vector, or matrix
[Rx,Cx] = size(x);
if Rx > Cx
x = x’; % make sure that x is a row vector
end
[Rx,Cx] = size(x);
if Rx > 1
error(’*** x must be a vector ***’) % stop if x is a matrix
end
% Check for length of x
if length(x) > N
error(’N must be >= the length of x’)
end

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 233

x=[x zeros(1,N-length(x))];
X=dft(x,N);
X=ones(Cm,1)*X;
WN=exp(-2*j*pi/N);
k=[0:1:N-1];
Y=(WN.^(m’ * k)).*X;
y=real(conj(dfs(conj(Y),N)))/N;

M ATLAB verification:
(a) x(n) = {5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4}, 0 ≤ n ≤ 10; m = −5, N = 12.

x = [5,4,3,2,1,0,0,1,2,3,4,5];
m = -5; N = 12;
y = cirshftf(x,m,N); y = real(y)
y =
0 0 1 2 3 4 5 5 4 3 2 1
(b) x(n) = {5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4}, 0 ≤ n ≤ 10; m = 8, N = 15

x = [5,4,3,2,1,0,0,1,2,3,4,5];
m = 8; N = 15;
y = cirshftf(x,m,N); y = real(y)
y =
1 2 3 4 5 0 0 0 5 4 3 2
1 0 0

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
234 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.17 Parseval’s relation for the DFT:


−1 −1 −1
N −1


N 
N 
1 
N
∗ −nk
x∗ (n)
2
|x (n)| = x (n) x (n) = X (k) WN
N
n=0 n=0
−1
N −1n=0 k=0
N −1
N −1 ∗
1
N  1  
∗ −nk nk
= X (k) x (n) WN = X (k) x (n) WN
N n=0
N n=0
k=0 k=0

Therefore,

 −1 N −1 N −1
1  1 
N
X (k) X ∗ (k) =
2 2
|x (n)| = |X (k)|
n=0
N N
k=0 k=0

M ATLAB verification:

x = [5,4,3,2,1,0,0,1,2,3,4,5]; N = length(x);
% power of x(n) in the time-domain
power_x = sum(x.*conj(x))

power_x =
110

% Power in the frequency-domain


X = dft(x,N); power_X = (1/N)*sum(X.*conj(X))

power_X =
110

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 235

P5.18 Let X(k) and Y (k) be 10-point DFTs of two 10-point sequences x(n) and y(n), respectively where

X(k) = exp(j0.2πk), 0≤k≤9

Computation of Y (k) properties of the DFT.


1. y(n) = x((n − 5)))1 0: Circular shift by 5. M ATLAB script:
k = 0:9; X = exp(j*0.2*pi*k); N = length(X);
m = 5; WN = exp(-j*2*pi/N); Y = X.*WN.^(m*k)
% verification
x = real(idft(X,N)); y = cirshftt(x,m,N); Y1 = dft(y,N)
difference = abs(max(Y-Y1))
Y =
Columns 1 through 4
1.0000 -0.8090 - 0.5878i 0.3090 + 0.9511i 0.3090 - 0.9511i
Columns 5 through 8
-0.8090 + 0.5878i 1.0000 + 0.0000i -0.8090 - 0.5878i 0.3090 + 0.9511i
Columns 9 through 10
0.3090 - 0.9511i -0.8090 + 0.5878i
Y1 =
Columns 1 through 4
1.0000 -0.8090 - 0.5878i 0.3090 + 0.9511i 0.3090 - 0.9511i
Columns 5 through 8
-0.8090 + 0.5878i 1.0000 + 0.0000i -0.8090 - 0.5878i 0.3090 + 0.9511i
Columns 9 through 10
0.3090 - 0.9511i -0.8090 + 0.5878i
difference =
2.7756e-015
2. y(n) = x((n + 4)))1 0: Circular shift by −4. M ATLAB script:
k = 0:9; X = exp(j*0.2*pi*k); N = length(X);
m = -4; WN = exp(-j*2*pi/N); Y = X.*WN.^(m*k)
% verification
x = real(idft(X,N)); y = cirshftt(x,m,N); Y1 = dft(y,N)
difference = abs(max(Y-Y1))
Y =
Columns 1 through 4
1.0000 -1.0000 + 0.0000i 1.0000 - 0.0000i -1.0000 + 0.0000i
Columns 5 through 8
1.0000 - 0.0000i -1.0000 + 0.0000i 1.0000 - 0.0000i -1.0000 + 0.0000i
Columns 9 through 10
1.0000 - 0.0000i -1.0000 + 0.0000i
Y1 =
Columns 1 through 4
1.0000 -1.0000 - 0.0000i 1.0000 + 0.0000i -1.0000 - 0.0000i
Columns 5 through 8

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
236 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

1.0000 - 0.0000i -1.0000 - 0.0000i 1.0000 + 0.0000i -1.0000 - 0.0000i


Columns 9 through 10
1.0000 - 0.0000i -1.0000 + 0.0000i
difference =
2.2249e-015
3. y(n) = x((3 − n)))1 0: Circular-fold and circular-shift by 3. M ATLAB script:
k = 0:9; X = exp(j*0.2*pi*k); N = length(X);
Y = circfold(X,N); m = 3; WN = exp(-j*2*pi/N); Y = X.*WN.^(m*k)
% verification
x = real(idft(X,N)); y = circfold(x,N); y = cirshftt(x,m,N); Y1 = dft(y,N)
difference = abs(max(Y-Y1))
Y =
Columns 1 through 4
1.0000 0.3090 - 0.9511i -0.8090 - 0.5878i -0.8090 + 0.5878i
Columns 5 through 8
0.3090 + 0.9511i 1.0000 + 0.0000i 0.3090 - 0.9511i -0.8090 - 0.5878i
Columns 9 through 10
-0.8090 + 0.5878i 0.3090 + 0.9511i
Y1 =
Columns 1 through 4
1.0000 0.3090 - 0.9511i -0.8090 - 0.5878i -0.8090 + 0.5878i
Columns 5 through 8
0.3090 + 0.9511i 1.0000 + 0.0000i 0.3090 - 0.9511i -0.8090 - 0.5878i
Columns 9 through 10
-0.8090 + 0.5878i 0.3090 + 0.9511i
difference =
2.6790e-015
4. y(n) = x(n)ej3πn/5 : Circular shift in the freq-domain by 3. M ATLAB script:
k = 0:9; X = exp(j*0.2*pi*k); N = length(X); l = 3;
Y = cirshftt(X,l,N)
% verification
x = real(idft(X,N)); n = 0:9; WN = exp(-j*2*pi/N);
y = x.*WN.^(-l*n); Y1 = dft(y,N)
difference = abs(max(Y-Y1))
Y =
Columns 1 through 4
-0.3090 - 0.9511i 0.3090 - 0.9511i 0.8090 - 0.5878i 1.0000
Columns 5 through 8
0.8090 + 0.5878i 0.3090 + 0.9511i -0.3090 + 0.9511i -0.8090 + 0.5878i
Columns 9 through 10
-1.0000 + 0.0000i -0.8090 - 0.5878i

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 237

Y1 =
Columns 1 through 4
-0.3090 - 0.9511i 0.3090 - 0.9511i 0.8090 - 0.5878i 1.0000 + 0.0000i
Columns 5 through 8
0.8090 + 0.5878i 0.3090 + 0.9511i -0.3090 + 0.9511i -0.8090 + 0.5878i
Columns 9 through 10
-1.0000 -0.8090 - 0.5878i
difference =
3.3880e-015
5. y(n) = x(n)(10)x((−n))1 0: Circular convolution with circularly-folded sequence. M ATLAB script:
k = 0:9; X = exp(j*0.2*pi*k); N = length(X);
Y = circfold(X,N); Y = X.*Y
% verification
x = real(idft(X,N)); y = circfold(x,N); y = circonvt(x,y,N); Y1 = dft(y,N)
difference = abs(max(Y-Y1))
Y =
Columns 1 through 4
1.0000 - 0.0000i 1.0000 - 0.0000i 1.0000 + 0.0000i 1.0000 - 0.0000i
Columns 5 through 8
1.0000 - 0.0000i 1.0000 - 0.0000i 1.0000 - 0.0000i 1.0000 + 0.0000i
Columns 9 through 10
1.0000 1.0000 + 0.0000i
Y1 =
Columns 1 through 4
1.0000 + 0.0000i 1.0000 - 0.0000i 1.0000 - 0.0000i 1.0000 - 0.0000i
Columns 5 through 8
1.0000 + 0.0000i 1.0000 + 0.0000i 1.0000 - 0.0000i 1.0000 - 0.0000i
Columns 9 through 10
1.0000 - 0.0000i 1.0000 - 0.0000i
difference =
4.7761e-015

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
238 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.19 Let X(k) be an N -point DFT of an N -point sequence x(n). Let N = 2μν where μ and ν are integers.
1. It is given that x(n) = x(n + ν) for all n. Let n = m + pν; 0 ≤ m ≤ ν − 1, 0 ≤ p ≤ (2μ − 1), then
x(n) = x(n + ν) ⇒ x(m + pν) = x(m), 0 ≤ m ≤ ν − 1, 0 ≤ p ≤ (2μ − 1) (5.1)
Now the DFT X(k) can be written as


N −1  ν−1
2μ−1   ν−1
2μ−1 
[. .. (5.1)]
(m+pν)k
X(k) = x(n)WNnk = x(m + pν)WN = x(m) WNmk WNpνk
n=0 p=0 m=0 p=0 m=0


ν−1 
2μ−1 
ν−1 
2μ−1  " #
 p ν−1
1 − WNN k
= x(m) WNmk WNpνk = x(m) WNmk WNνk = x(m) WNmk
m=0 p=0 m=0 p=0 m=0
1 − WNνk
$ % 

ν−1
1 − WNN k Non-zero, k = (2μ) for 0 ≤  ≤ ν − 1;
= x(m) WNmk =
1 − WN
N (k/2μ) 0, k= (2μ) for 0 ≤  ≤ ν − 1.
m=0

Verification for x(n) = {1, −2, 3, 1, −2, 3, 1, −2, 3, 1, −2, 3, 1, −2, 3, 1, −2, 3}.
x = [1,-2,3,1,-2,3,1,-2,3,1,-2,3,1,-2,3,1,-2,3]; N = length(x); X = dft(x,N)
X =
12.0000 0.0000 - 0.0000i -0.0000 + 0.0000i 0.0000 + 0.0000i
0.0000 0.0000 + 0.0000i 3.0000 +25.9808i -0.0000 - 0.0000i
-0.0000 + 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i
3.0000 -25.9808i 0.0000 + 0.0000i 0.0000 0.0000 - 0.0000i
0.0000 - 0.0000i 0.0000 - 0.0000i
2. It is given that x(n) = −x(n + ν) for all n. Let n = m + pν; 0 ≤ m ≤ ν − 1, 0 ≤ p ≤ (2μ − 1), then
x(n) = −x(n + ν) ⇒ x(m + pν) = (−1)p x(m), 0 ≤ m ≤ ν − 1, 0 ≤ p ≤ (2μ − 1) (5.2)
Now the DFT X(k) can be written as


N −1  ν−1
2μ−1   ν−1
2μ−1 
[. .. (5.2)]
(m+pν)k
X(k) = x(n)WNnk = x(m + pν)WN = (−1)p x(m) WNmk WNpνk
n=0 p=0 m=0 p=0 m=0


ν−1 
2μ−1 
ν−1 &
2μ−1
−N/2
'p
−N/2
= x(m) WNmk (−1)p WNpνk = x(m) WNmk WN WNνk [. .. − 1 = WN ]
m=0 p=0 m=0 p=0
$ % 

ν−1
1 − WN
N (k−2)
= 0, k = 2μ + 2 = 2(μ + 1), 0 ≤  ≤ ν − 1;
= x(m) WNmk =
1−
N (k−2)/(2μ)
WN 0, k = 2μ + 2 = 2(μ + 1), 0 ≤  ≤ ν − 1.
m=0

Verification for x(n) = {1, −2, 3, −1, 2, −3, 1, −2, 3, −1, 2, −3, 1, −2, 3, −1, 2, −3}.
x = [1,-2,3,-1,2,-3,1,-2,3,-1,2,-3,1,-2,3,-1,2,-3]; N = length(x); X = dft(x,N)
X =
0 -0.0000 -0.0000 + 0.0000i -9.0000 - 5.1962i
0.0000 - 0.0000i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i
0.0000 - 0.0000i 36.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i
-0.0000 + 0.0000i -0.0000 + 0.0000i -0.0000 + 0.0000i -9.0000 + 5.1962i
-0.0000 - 0.0000i -0.0000 - 0.0000i

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 239

P5.20 Let X(k) be an N -point DFT of an N -point sequence x(n). Let N = 4ν where ν is an integer.
1. It is given that x(n) = x(n + ν) for all n. Let n = m + pν; 0 ≤ m ≤ ν − 1, 0 ≤ p ≤ 3, then

x(n) = x(n + ν) ⇒ x(m + pν) = x(m), 0≤m≤ν−1 (5.3)

Now the DFT X(k) can be written as


N −1  
3 ν−1  
3 ν−1
[. .. (5.3)]
(m+pν)k
X(k) = x(n)WNnk = x(m + pν)WN = x(m) WNmk WNpνk
n=0 p=0 m=0 p=0 m=0


ν−1 
3 
ν−1 
3  " #
 p ν−1
1 − WNN k
= x(m) WNmk WNpνk = x(m) WNmk WNνk = x(m) WNmk
m=0 p=0 m=0 p=0 m=0
1 − WNνk
$ % 

ν−1
1 − WNN k Non-zero, k = 4 for 0 ≤  ≤ ν − 1;
= x(m) WNmk =
1 − WN
N (k/4) 0, k= 4 for 0 ≤  ≤ ν − 1.
m=0

Verification for x(n) = {1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3}.


x = [1,2,3,1,2,3,1,2,3,1,2,3]; N = length(x); X = dft(x,N)
X =
24.0000 -0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 + 0.0000i
-6.0000 + 3.4641i 0.0000 - 0.0000i -0.0000 - 0.0000i -0.0000 - 0.0000i
-6.0000 - 3.4641i 0.0000 - 0.0000i 0.0000 - 0.0000i 0.0000 - 0.0000i
2. It is given that x(n) = −x(n + ν) for all n. Let n = m + pν; 0 ≤ m ≤ ν − 1, 0 ≤ p ≤ 3, then

x(n) = −x(n + ν) ⇒ x(m + pν) = (−1)p x(m), 0 ≤ m ≤ ν − 1, 0 ≤ p ≤ 3 (5.4)

Now the DFT X(k) can be written as


N −1  
3 ν−1  
3 ν−1
[. .. (5.4)]
(m+pν)k
X(k) = x(n)WNnk = x(m + pν)WN = (−1)p x(m) WNmk WNpνk
n=0 p=0 m=0 p=0 m=0


ν−1 
3 
ν−1 3 &
 'p
−N/2 −N/2
= x(m) WNmk (−1)p WNpνk = x(m) WNmk WN WNνk [. .. − 1 = WN ]
m=0 p=0 m=0 p=0
$ % 

ν−1 N (k−2)
1 − WN Non-zero, k = 4 + 2 for 0 ≤  ≤ ν − 1;
= x(m) WNmk =
ν(k−2)
1 − WN 0, k= 4 + 2 for 0 ≤  ≤ ν − 1.
m=0

Verification for x(n) = {1, 2, 3, −1, −2, −3, 1, 2, 3, −1, −2, −3}.
x = [1,2,3,-1,-2,-3,1,2,3,-1,-2,-3]; N = length(x); X = dft(x,N)
X =
0 0 2.0000 -17.3205i 0.0000 + 0.0000i
0 0 8.0000 + 0.0000i -0.0000 + 0.0000i
0 0 2.0000 +17.3205i -0.0000 - 0.0000i

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
240 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.21 Let X(k) be an N -point DFT of an N -point sequence x(n). Let N be an even integer.
1. Given that x(n) = x(n + N/2) for all n, consider


N −1 
N/2−1

N −1
X(k) = x(n)WNnk = x(n)WNnk + x(n)WNnk
n=0 n=0 n=N/2


N/2−1

N/2−1
[. .. n → n + N/2]
(n+N/2)k
= x(n)WNnk + x(n + N/2)WN
n=0 n=0


N/2−1

N/2−1
[. .. x(n) = x(n + N/2)]
N k/2
= x(n)WNnk + x(n)WNnk WN
n=0 n=0


N/2−1 
 0, k odd;
[. .. WN = −1] =
k N/2
= x(n) 1 + (−1) WNnk
Non-zero, k even.
n=0

Verification using x(n) = {1, 2, −3, 4, 5, 1, 2, −3, 4, 5}:


x = [1,2,-3,4,5,1,2,-3,4,5]; N = length(x); X = dft(x,N)
X =
18.0000 -0.0000 + 0.0000i 4.7082 +13.9353i -0.0000 + 0.0000i
-8.7082 - 9.7881i 0.0000 - 0.0000i -8.7082 + 9.7881i -0.0000 - 0.0000i
4.7082 -13.9353i 0.0000 - 0.0000i
2. Given that x(n) = −x(n + N/2) for all n, consider


N −1 
N/2−1

N −1
X(k) = x(n)WNnk = x(n)WNnk + x(n)WNnk
n=0 n=0 n=N/2


N/2−1

N/2−1
[. .. n → n + N/2]
(n+N/2)k
= x(n)WNnk + x(n + N/2)WN
n=0 n=0


N/2−1

N/2−1
[. .. x(n) = −x(n + N/2)]
N k/2
= x(n)WNnk − x(n)WNnk WN
n=0 n=0


N/2−1

[. .. WN
N/2
= x(n) 1 − (−1)k WNnk = −1]
n=0

0, k even;
=
Non-zero, k odd.

Verification using x(n) = {1, 2, −3, 4, 5, −1, −2, 3, −4, −5}.


x = [1,2,-3,4,5,-1,-2,3,-4,-5]; N = length(x); X = dft(x,N)
X =
0 -7.1803 -10.1311i -0.0000 - 0.0000i 15.1803 -12.1392i
0.0000 + 0.0000i -6.0000 - 0.0000i 0.0000 - 0.0000i 15.1803 +12.1392i
-0.0000 + 0.0000i -7.1803 +10.1311i

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 241

P5.22 Let 
A cos(2πn/N ), 0≤n≤N −1
x(n) = = A cos(2πn/N )RN (n)
0, elsewhere
where  is an integer. Notice that x(n) contains exactly  periods (or cycles) of the cosine waveform in N
samples. This is a windowed cosine sequence containing no leakage.
1. Consider the DFT X(k) of x(n) which is given by


N −1 
N −1  
2πn
x(n) e−j N kn = e−j N kn ,
2π 2π
X(k) = A cos 0≤k ≤N −1
n=0 n=0
N

A   j 2π n 
N −1
e N + e−j N n e−j N kn ,
2π 2π
= 0≤k ≤N −1
2 n=0
N −1 N −1
A  −j 2π (k−)n A  −j 2π (k+)n
= e N + e N , 0≤k ≤N −1
2 n=0 2 n=0
AN AN
= δ (k − ) + δ (k − N + ) ; 0 ≤ k ≤ (N − 1) , 0<<N
2 2
which is a real-valued sequence.
2. If  = 0, then the DFT X(k) is given by


N −1 
N −1
x(n) e−j N kn = A e−j N kn ,
2π 2π
X(k) = 0≤k ≤N −1
n=0 n=0
= AN δ(k); 0 ≤ k ≤ (N − 1)

3. If  < 0 or  > N , then we must replace it by (())N in the result of part 1., i.e.

AN AN
X(k) = δ [k − (())N ] + δ [k − N + (())N ] ; 0 ≤ k ≤ (N − 1)
2 2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
242 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

4. Verification of the results of parts 1., 2., and 3. above using M ATLAB and the following sequences:
(a) x1 (n) = 3 cos(0.04πn)R200 (n):
N = 200; n = 0:N-1; x1 = 3*cos(0.04*pi*n); l = 4;
k = 0:N-1; X1 = real(fft(x1,N));
Hf_1 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.22.4(a)’);
subplot(2,1,1); H_s1 = stem(n,x1,’g’,’filled’); set(H_s1,’markersize’,1);
title(’Sequence: {\itx}_1({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-4,4]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X1,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_1({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-10,310]); xlabel(’\itk’);
set(gca,’xtick’,[0,l,N-l],’ytick’,[0,300])
The sequence x1 (n) and its DFT X1 (k) are shown in Figure 5.14.

Sequence: x1(n)
4

2
Amplitude

−2

−4
0 20 40 60 80 100 120 140 160 180 200
n
DFT: X1(k)
300
Amplitude

0
04 196
k

Figure 5.14: The signal x1 (n) and its DFT X1 (k) in Problem P5.22.4(a)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 243

(b) x2 (n) = 5R50 (n):


N = 50; n = 0:N-1; x2 = 5*cos(0*pi*n); l = 0;
k = 0:N-1; X2 = real(fft(x2,N));
Hf_2 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_2,’NumberTitle’,’off’,’Name’,’P5.22.4(b)’);
subplot(2,1,1); H_s1 = stem(n,x2,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_2({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-1,6]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X2,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_2({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-10,260]); xlabel(’\itk’);
set(gca,’xtick’,[0,N-1],’ytick’,[0,250])
The sequence x2 (n) and its DFT X2 (k) are shown in Figure 5.15.

Sequence: x2(n)
6

4
Amplitude

0 5 10 15 20 25 30 35 40 45 50
n
DFT: X2(k)
250
Amplitude

0
0 49
k

Figure 5.15: The signal x2 (n) and its DFT X2 (k) in Problem P5.22.4(b)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
244 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

(c) x3 (n) = [1 + 2 cos(0.5πn) + cos(πn)]R100 (n):


N = 100; n = 0:N-1; x3 = 1+2*cos(0.5*pi*n)+cos(pi*n); l1 = 0; l2 = 25; l3 = 50;
k = 0:N-1; X3 = real(fft(x3,N));
Hf_3 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_3,’NumberTitle’,’off’,’Name’,’P5.22.4(c)’);
subplot(2,1,1); H_s1 = stem(n,x3,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_3({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-1,5]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X3,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_3({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-10,110]); xlabel(’\itk’);
set(gca,’xtick’,[l1,l2,l3,N-l2,N-1],’ytick’,[0,100])
The sequence x3 (n) and its DFT X3 (k) are shown in Figure 5.16.

Sequence: x3(n)
5
4
Amplitude

3
2
1
0
−1
0 10 20 30 40 50 60 70 80 90 100
n
DFT: X3(k)

100
Amplitude

0
0 25 50 75 99
k

Figure 5.16: The signal x3 (n) and its DFT X3 (k) in Problem P5.22.4(c)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 245

(d) x4 (n) = cos(25πn/16)R64 (n):


N = 64; n = 0:N-1; x4 = cos(25*pi*n/16); l = 50;
k = 0:N-1; X4 = real(fft(x4,N));
Hf_4 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_4,’NumberTitle’,’off’,’Name’,’P5.22.4(d)’);
subplot(2,1,1); H_s1 = stem(n,x4,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_4({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-1.1,1.1]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X4,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_4({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-5,35]); xlabel(’\itk’);
set(gca,’xtick’,[0,N-l,l,N-1],’ytick’,[0,32])
The sequence x4 (n) and its DFT X4 (k) are shown in Figure 5.17.

Sequence: x4(n)
1

0.5
Amplitude

−0.5

−1
0 10 20 30 40 50 60
n
DFT: X4(k)

32
Amplitude

0 14 50 63
k

Figure 5.17: The signal x4 (n) and its DFT X4 (k) in Problem P5.22.4(d)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
246 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

(e) x5 (n) = [cos(0.1πn) − 3 cos(1.9πn)]R40 (n):


N = 40; n = 0:N-1; x5 = 4*cos(0.1*pi*n)-3*cos(1.9*pi*n); l1 = 2; l2 = 38;
k = 0:N-1; X5 = real(fft(x5,N));
Hf_5 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_5,’NumberTitle’,’off’,’Name’,’P5.22.4(e)’);
subplot(2,1,1); H_s1 = stem(n,x5,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_5({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-1.1,1.1]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X5,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_5({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-5,25]); xlabel(’\itk’);
set(gca,’xtick’,[0,l1,l2,N],’ytick’,[0,20])
The sequence x5 (n) and its DFT X5 (k) are shown in Figure 5.18.

Sequence: x5(n)
1

0.5
Amplitude

−0.5

−1
0 5 10 15 20 25 30 35 40
n
DFT: X5(k)

20
Amplitude

0 2 38 40
k

Figure 5.18: The sample plot of various signals in Problem P5.22.4(e)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 247

P5.23 Let x(n) = A cos(ω0 n)RN (n), where ω0 is a real number.


1. Consider


N −1 
N −1    
−j ( 2π
N )nk
2π 2π
X(k) = x(n)e =A cos(ω0 n) cos nk − j sin nk
n=0 n=0
N N

N −1   
N −1  
2π 2π
XR (k) + jXI (k) = A cos(ω0 n) cos nk − jA cos(ω0 n) sin nk
n=0
N n=0
N

Hence


N −1  

XR (k) = A cos(ω0 n) cos nk (5.5)
n=0
N

N −1  

XI (k) = −A cos(ω0 n) sin nk (5.6)
n=0
N

Consider the real-part in (5.5),

 −1  N −1     
A 
N
2π 2π 2π
XR (k) = A cos(ω0 n) cos nkcos ω0 n −
= nk + cos ω0 n + nk
n=0
2 n=0N N N
N −1     
A  2π 2π
= cos 2πf0 n − nk + cos 2πf0 n + nk [. .. ω0 = 2πf0 ]
2 n=0 N N
N −1  " # " #
A  2π 2π
= cos (f0 N − k)n + cos (f0 N + k)n
2 n=0 N N
N −1  " # " #
A  2π 2π
= cos (k − f0 N )n + cos {k − (N − f0 N )}n , 0 ≤ k < N (5.7)
2 n=0 N N

To reduce the sum-of-cosine terms in (5.7), consider

 −1   N −1 N −1    
1  j ( 2π 1  −j ( 2π
N
2π 1 1 − ej2πv 1 1 − e−j2πv
cos vn = e N )vn + e N )vn = +
n=0
N 2 n=0 2 n=0 2 1 − ej 2π
N v 2 1 − e−j 2π
N v

1 −jπv( NN−1 ) sin(πv) 1 N −1 sin(πv)


= e + ejπn( N )
2 sin(πv/N ) 2 sin(πv/N )
 
πv(N − 1) sin(πn)
= cos (5.8)
N sin(πv/N )

Now substituting (5.8) in the first term of (5.7) with v = (k − f0 N ) and in the second term of (5.7) with
v = (k − [N − f0 N ]), we obtain the desired result
 
A π(N − 1) sin[π(f0 N − k)]
XR (k) = cos (k − f0 N )
2 N π
sin[ N (f0 N − k)]
 
A π(N − 1) sin{π(k − [N − f0 N ])}
+ cos (k − [N − f0 N ]) (5.9)
2 N π
sin[ N (f0 N − k)]

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
248 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

Similarly, we can show that

A   sin[π(f N − k)]
sin π(NN−1) (k − f0 N )
0
XI (k) = −
2 π
sin[ N (f0 N − k)]
A   sin{π(k − [N − f N ])}
− sin π(NN−1) (k − [N − f0 N ])
0
(5.10)
2 π
sin[ N (f0 N − k)]

2. The above result implies that the original frequency ω0 of the cosine waveform has leaked into other
frequencies that form the harmonics of the time-limited sequence and hence it is called the leakage prop-
erty of cosines. It is a natural result due to the fact that bandlimited periodic cosines are sampled over
noninteger periods. Due to this fact, the periodic extension of x(n) does not result in a continuation of the
cosine waveform but has a jump at every N interval. This jump results in the leakage of one frequency
into the abducent frequencies and hence the result of the Problem P5.22.1 do not apply.
3. Verification of the leakage property using x(n) = cos (5πn/99) R200 (n): The sequence x(n), the real-
part of its DFT XR (k), and the imaginary part of its DFT XI (k) are shown in Figure 5.19.

Sequence: x(n)
1

0.5
Amplitude

−0.5

−1
0 20 40 60 80 100 120 140 160 180 200
n
Real−part of the DFT: XR(k)
100
Amplitude

0
−10
0 5 100 195
k
Imaginary−part of the DFT: X (k)
I
20
Amplitude

−20
0 5 100 195
k

Figure 5.19: The leakage property of a cosine signal in Problem P5.23.3

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 249

P5.24 Let 
A sin(2πn/N ), 0≤n≤N −1
x(n) = = A sin(2πn/N )RN (n)
0, elsewhere
where  is an integer. Notice that x(n) contains exactly  periods (or cycles) of the sine waveform in N
samples. This is a windowed sine sequence containing no leakage.
1. Consider the DFT X(k) of x(n) which is given by


N −1 
N −1  
2πn
x(n) e−j N kn = e−j N kn ,
2π 2π
X(k) = A sin 0≤k ≤N −1
n=0 n=0
N

A   j 2π n 
N −1
e N − e−j N n e−j N kn ,
2π 2π
= 0≤k ≤N −1
j2 n=0
N −1 N −1
A  −j 2π (k−)n A  −j 2π (k+)n
= e N − e N , 0≤k ≤N −1
j2 n=0 2 n=0
AN AN
= δ (k − ) − δ(k − N + ); 0 ≤ k ≤ (N − 1), 0<<N
j2 j2
which is a purely imaginary-valued sequence.
2. If  = 0, then the DFT X(k) is given by


N −1 
N −1
x(n) e−j N kn = 0 e−j N kn ,
2π 2π
X(k) = 0 ≤ k ≤ (N − 1)
n=0 n=0
= 0; 0 ≤ k ≤ (N − 1)

3. If  < 0 or  > N , then we must replace it by (())N in the result of part 1., i.e.

AN AN
X(k) = δ [k − (())N ] − δ [k − N + (())N ] ; 0 ≤ k ≤ (N − 1)
j2 j2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
250 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

4. Verification of the results of parts 1., 2., and 3. above using M ATLAB and the following sequences:
(a) x1 (n) = 3 sin(0.04πn)R200 (n):
N = 200; n = 0:N-1; x1 = 3*sin(0.04*pi*n); l = 4;
k = 0:N-1; X1 = imag(fft(x1,N));
Hf_1 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.24.4(a)’);
subplot(2,1,1); H_s1 = stem(n,x1,’g’,’filled’); set(H_s1,’markersize’,1);
title(’Sequence: {\itx}_1({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-4,4]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X1,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_1({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-350,350]); xlabel(’\itk’);
set(gca,’xtick’,[0,l,N-l],’ytick’,[-300,0,300])
The sequence x1 (n) and its DFT X1 (k) are shown in Figure 5.20.

Sequence: x1(n)
4

2
Amplitude

−2

−4
0 20 40 60 80 100 120 140 160 180 200
n
DFT: X1(k)

300
Amplitude

−300
04 196
k

Figure 5.20: The signal x1 (n) and its DFT X1 (k) in Problem P5.24.4(a)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 251

(b) x2 (n) = 5 sin(10πn)R50 (n):


N = 50; n = 0:N-1; x2 = 5*sin(10*pi*n); l = 0;
k = 0:N-1; X2 = imag(fft(x2,N));
Hf_2 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_2,’NumberTitle’,’off’,’Name’,’P5.24.4(b)’);
subplot(2,1,1); H_s1 = stem(n,x2,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_2({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-1,1]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X2,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_2({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-1,1]); xlabel(’\itk’);
set(gca,’xtick’,[0,N-1],’ytick’,[-1,0,1])

The sequence x1 (n) and its DFT X1 (k) are shown in Figure 5.21.

Sequence: x2(n)
1

0.5
Amplitude

−0.5

−1
0 5 10 15 20 25 30 35 40 45 50
n
DFT: X2(k)
1
Amplitude

−1
0 49
k

Figure 5.21: The signal x1 (n) and its DFT X1 (k) in Problem P5.24.4(b)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
252 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

(c) x3 (n) = [2 sin(0.5πn) + sin(πn)]R100 (n):


N = 100; n = 0:N-1; x3 = 2*sin(0.5*pi*n)+0*sin(pi*n); l1 = 0; l2 = 25; l3 = 50;
k = 0:N-1; X3 = imag(fft(x3,N));
Hf_3 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_3,’NumberTitle’,’off’,’Name’,’P5.24.4(c)’);
subplot(2,1,1); H_s1 = stem(n,x3,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_3({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-3,3]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X3,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_3({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-120,120]); xlabel(’\itk’);
set(gca,’xtick’,[l1,l2,l3,N-l2,N-1],’ytick’,[-100,0,100])
The sequence x1 (n) and its DFT X1 (k) are shown in Figure 5.22.

Sequence: x3(n)
3
2
Amplitude

1
0
−1
−2
−3
0 10 20 30 40 50 60 70 80 90 100
n
DFT: X3(k)

100
Amplitude

−100
0 25 50 75 99
k

Figure 5.22: The signal x1 (n) and its DFT X1 (k) in Problem P5.24.4(c)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 253

(d) x4 (n) = sin(25πn/16)R64 (n):


N = 64; n = 0:N-1; x4 = sin(25*pi*n/16); l = 50;
k = 0:N-1; X4 = imag(fft(x4,N));
Hf_4 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_4,’NumberTitle’,’off’,’Name’,’P5.24.4(d)’);
subplot(2,1,1); H_s1 = stem(n,x4,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_4({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-1.1,1.1]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X4,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_4({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-40,40]); xlabel(’\itk’);
set(gca,’xtick’,[0,N-l,l,N-1],’ytick’,[-32,0,32])
The sequence x1 (n) and its DFT X1 (k) are shown in Figure 5.23.

Sequence: x4(n)
1

0.5
Amplitude

−0.5

−1
0 10 20 30 40 50 60
n
DFT: X4(k)

32
Amplitude

−32

0 14 50 63
k

Figure 5.23: The signal x1 (n) and its DFT X1 (k) in Problem P5.24.4(d)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
254 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

(e) x5 (n) = [4 sin(0.1πn) − 3 sin(1.9πn)]R20 (n):


N = 20; n = 0:N-1; x5 = 4*sin(0.1*pi*n)-3*sin(1.9*pi*n); l1 = 1; l2 = 19;
k = 0:N-1; X5 = imag(fft(x5,N));
Hf_5 = figure(’Units’,’inches’,’position’,[1,1,6,4],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,6,4]);
set(Hf_5,’NumberTitle’,’off’,’Name’,’P5.24.4(e)’);
subplot(2,1,1); H_s1 = stem(n,x5,’g’,’filled’); set(H_s1,’markersize’,2);
title(’Sequence: {\itx}_5({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-10,10]); xlabel(’\itn’);
subplot(2,1,2); H_s2 = stem(n,X5,’r’,’filled’); set(H_s2,’markersize’,2);
title(’DFT: {\itX}_5({\itk})’,’fontsize’,10);
ylabel(’Amplitude’); axis([-1,N,-80,80]); xlabel(’\itk’);
set(gca,’xtick’,[0,l1,l2,N],’ytick’,[-70,0,70])
The sequence x1 (n) and its DFT X1 (k) are shown in Figure 5.24.

Sequence: x5(n)
10

5
Amplitude

−5

−10
0 2 4 6 8 10 12 14 16 18 20
n
DFT: X5(k)
70
Amplitude

−70
0 1 19 20
k

Figure 5.24: The signal x1 (n) and its DFT X1 (k) in Problem P5.24.4(e)

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 255

P5.25 Let x(n) = A sin(ω0 n)RN (n), where ω0 is a real number.


1. Consider


N −1 
N −1     
−j ( 2π
N )nk
2π 2π
X(k) = x(n)e =A sin(ω0 n) cos nk − j sin nk
n=0 n=0
N N

N −1   
N −1  
2π 2π
XR (k) + jXI (k) = A sin(ω0 n) cos nk − jA sin(ω0 n) sin nk
n=0
N n=0
N

Hence


N −1  

XR (k) = A sin(ω0 n) cos nk (5.11)
n=0
N

N −1  

XI (k) = −A sin(ω0 n) sin nk (5.12)
n=0
N

Consider the real-part in (5.11),

 −1  
N −1     
A 
N
2π 2π 2π
XR (k) = A sin(ω0 n) cos nk sin ω0 n −
= nk + sin ω0 n + nk
n=0
N2 n=0 N N
N −1     
A  2π 2π
= sin 2πf0 n − nk + sin 2πf0 n + nk [. .. ω0 = 2πf0 ]
2 n=0 N N
N −1  " # " #
A  2π 2π
= sin (f0 N − k)n + sin (f0 N + k)n
2 n=0 N N
N −1  " # " #
A  2π 2π
= − sin (k − f0 N )n + sin {k − (N − f0 N )}n , 0 ≤ k < N (5.13)
2 n=0 N N

To reduce the sum-of-sine terms in (5.13), consider

 −1   N −1 N −1    
1  j ( 2π 1  −j ( 2π
N
2π 1 1 − ej2πv 1 1 − e−j2πv
sin vn = e N )vn − e N )vn = −
n=0
N j2 n=0 j2 n=0 j2 1 − ej 2π
N v j2 1 − e−j 2π
N v

1 jπv( NN−1 ) sin(πv) 1 N −1 sin(πv)


= e − e−jπn( N )
j2 sin(πv/N ) j2 sin(πv/N )
 
πv(N − 1) sin(πv)
= sin (5.14)
N sin(πv/N )

Now substituting (5.14) in the first term of (5.13) with v = (k − f0 N ) and in the second term of (5.13)
with v = (k − [N − f0 N ]), we obtain the desired result
 
A π(N − 1) sin[π(f0 N − k)]
XR (k) = − sin (k − f0 N )
2 N π
sin[ N (f0 N − k)]
 
A π(N − 1) sin{π(k − [N − f0 N ])}
+ sin (k − [N − f0 N ]) (5.15)
2 N π
sin{ N (f0 N − k)}

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
256 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

Similarly, we can show that


 
A π(N − 1) sin[π(f0 N − k)]
XI (k) = − sin (k − f0 N )
2 N π
sin[ N (f0 N − k)]
 
A π(N − 1) sin{π(k − [N − f0 N ])}
+ sin (k − [N − f0 N ]) (5.16)
2 N π
sin[ N (f0 N − k)]

2. The above result is the leakage property of sines. It implies that the original frequency ω0 of the sine
waveform has leaked into other frequencies that form the harmonics of the time-limited sequence. It is a
natural result due to the fact that bandlimited periodic sines are sampled over noninteger periods. Due to
this fact, the periodic extension of x(n) does not result in a continuation of the sine waveform but has a
jump at every N interval. This jump results in the leakage of one frequency into the abducent frequencies
and hence the result of Problem P5.24.1 do not apply.
3. Verification of the leakage property using x(n) = sin(5πn/99)R100 (n): The sequence x(n), the real-part
of its DFT XR (k), and the imaginary part of its DFT XI (k) are shown in Figure 5.25.

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 257

Sequence: x(n)
1

0.5
Amplitude

−0.5

−1
0 10 20 30 40 50 60 70 80 90 100
n
Real−part of the DFT: XR(k)
50
Amplitude

−50
0 5 50 95
k
Imaginary−part of the DFT: XI(k)
5
Amplitude

−5
0 5 50 95
k

Figure 5.25: The leakage property of a sine signal in Problem P5.25.3

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
258 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.26 An analog signal xa (t) = 2 sin(4πt) + 5 cos(8πt) is sampled at t = 0.01n for n = 0, 1, . . . , N − 1


to obtain an N -point sequence x(n). An N -point DFT is used to obtain an estimate of the magnitude
spectrum of xa (t).
1. Out of the given three values, N = 50 provides complete cycles of both the sine and the cosine compo-
nents. Thus N = 50 provides the most accurate estimate as shown in Figure 5.26.

Real Part of the DFT: XR(k)


150
Amplitude

0
−40
0 2 25 48 50

Imaginary Part of the DFT: XI(k)


60
Amplitude

−60
01 25 49
k

Figure 5.26: The accurate spectrum of the signal in Problem P5.26.1

2. Out of the given three values, N = 99 provides almost complete cycles of both the sine and the cosine
components. Thus N = 99 provides the least amount of leakage as shown in Figure 5.27.

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 259

Real Part of the DFT: XR(k)


300

Amplitude

0
−30
0 4 49.5 95 99

Imaginary Part of the DFT: XI(k)


100
Amplitude

−100
02 49.5 97
k

Figure 5.27: The least amount of leakage in the spectrum of the signal in Problem P5.26.2

P5.27 Using (5.49), determine and draw the signal flow graph for the N = 8 point, radix-2 decimation-in-
frequency FFT algorithm. Using this flow graph, determine the DFT of the sequence

x(n) = cos (πn/2) , 0 ≤ n ≤ 7.

Using N = 8, M = 2, and L = N/2 = 4, we have

n =  + 4m; 0 ≤  ≤ 3, 0 ≤ m ≤ 1
k = q + 2p; 0 ≤ p ≤ 3, 0 ≤ q ≤ 1

Then from (5.49), we obtain


3 
1
X(p, q) = W8q x(, m)W2mq W4p
=0 m=0

The sequence x(n) is organized into x(, m) as


" #
x(0) x(1) x(2) x(3)
x(4) x(5) x(6) x(7)

Thus we take initial 2-point DFTs of the columns of x(p, q) and then multiply by the twiddle factors and
continue this operations. The complete flow-graph is shown in Figure 5.28.
Figure 5.29 shows signal values (in red) for x(n) = cos(πn/2), 0 ≤ n ≤ 7. From it we obtain

X(2) = X(6) = 4 and X(k) = 0 for k = 0, 1, 3, 4, 5, 7

which is to be expected since x(n) = cos(2π2/8).

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
260 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

x [0] X [0]
0
W8
x [1] X [4]
–1
0
W8
x [2] X [2]
–1
2 0
W8 W8
x [3] X [6]
–1 –1
0
W8
x [4] X [1]
–1
1 0
W8 W8
x [5] X [5]
–1 –1
2 0
W8 W8
x [6] X [3]
–1 –1
3 2 0
W8 W8 W8
x [7] X [7]
–1 –1 –1

Figure 5.28: The flow-graph of the 8-point DIF-FFT in Problem P5.27

2 0
1 x [0] X [0] =0
0
0 0 W8
0 x [1] X [4] =0
–1
0
−2 W8 4
−1 x [2] X [2] =4
–1
2 0
0 W8 0 W8
0 x [3] X [6] =4
–1 –1
0
W8 0 0
1 x [4] X [1] =0
–1
1 0
W8 0 0 W8
0 x [5] X [5] =0
–1 –1
2 0
W8 0 W8 0
−1 x [6] X [3] =0
–1 –1
3 2 0
W8 0 W8 0 W8
0 x [7] X [7] =0
–1 –1 –1

Figure 5.29: The flow-graph of the 8-point DIF-FFT for x(n) = cos(πn/2) in Problem P5.27

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 261

P5.28 Using (5.49), determine and draw the signal flow graph for the N = 16 point, radix-4 decimation-in-time
FFT algorithm. Using this flow graph determine the DFT of the sequence

x(n) = cos (πn/2) , 0 ≤ n ≤ 15.

Using N = 16, L = 2, and M = N/2 = 8, we have

n =  + 2m; 0 ≤  ≤ 1, 0 ≤ m ≤ 7
k = q + 8p; 0 ≤ p ≤ 1, 0 ≤ q ≤ 7

Then from (5.49), we obtain


1
q

7
X(p, q) = W16 x(, m)W8mq W2p
=0 m=0

The sequence x(n) is organized into x(, m) as


" #
x(0) x(2) x(4) x(6) x(8) x(10) x(12) x(14)
x(1) x(3) x(5) x(7) x(9) x(11) x(13) x(15)

Thus we take initial 8-point DFTs of the rows of x(p, q) and then multiply by the twiddle factors and
continue this operations. The complete flow-graph is shown in Figure 5.30.
Figure 5.30 also shows signal values (in red) and signal flows (in heavy lines) for the computation of
X(4) when x(n) = cos(πn/2), 0 ≤ n ≤ 15. From it we obtain

X(4) = X(12) = 8 and X(k) = 0 for all other k

which is to be expected since x(n) = cos(2π4/16).

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
262 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

2 4
1 x[0] X[0] 0
0
W
1
16
x[8]
−1
X[1] 0
2
0
W
1 x[4]
16
X[2] 0
−1
W160 W162
1 x[12] X[3] 0
−1 −1
−2 −4 W160 8
−1 x[2] X[4] 8
−1
0 1
W W
−1 x[10]
16

−1
16
X[5] 0
−1
−2 W 0
W 2

−1
16
0
16
x[6] X[6]
−1 −1
0 2 3
W W W
−1 0
16 16 16
x[14] X[7]
−1 −1 −1
0 0 0 0 W160
x[1]
−1
X[8] 0
0 1
W W
0
16 16
x[9]
−1 −1
X[9] 0
0
0 2
W W
0
16 16
x[5]
−1 −1
X[10] 0
W160 W162 W163
0 x[13]
−1
X[11] 0
−1 −1
0 0 W160 0 W164
0 x[3] X[12] 8
−1 −1
W160 W161 W165
0 x[11]
−1 −1 −1
X[13] 0
0 W166
0 2
W W
0
16 16
x[7]
−1 −1 −1
X[14] 0
0 2 3 7
W W W W
0
16
0
16 16 16
x[15] X[15]
−1 −1 −1 −1

Figure 5.30: The flow-graph of the 16-point DIT-FFT in Problem P5.28

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 263

P5.29 Let x(n) be a uniformly distributed random number between [−1, 1] for 0 ≤ n ≤ 106 . Let

h(n) = sin(0.4πn), 0 ≤ n ≤ 100

1. Using the conv function, determine the output sequence y(n) = x(n) ∗ h(n).
M ATLAB script:
clc; close all;
N = 1000001; x = 2*rand(1,N)-1; h = cos(0.4*pi*(0:15));
%% 1. Use of the conv function
t = cputime; y1 = conv(x,h); t_conv = cputime-t
t_conv =
0.2500
y1 = y1(1:1000001);
2. Consider the overlap-and-save method of block convolution along with the FFT algorithm to implement
high-speed block convolution. Using this approach, determine y(n) with FFT sizes of 1024, 2048, and
4096.
M ATLAB script:
%% 2. Use of the hsolpsav function
% (a) FFT size = 1024
t = cputime; y2a = hsolpsav(x,h,1024); t_1024 = cputime-t
t_1024 =
0.1600
y2a = y2a(1:1000001); differencea = max(abs(y1-y2a))
differencea =
3.5527e-15
% (a) FFT size = 2048
t = cputime; y2b = hsolpsav(x,h,2048); t_2048 = cputime-t
t_2048 =
0.1300
y2b = y2b(1:1000001); differenceb = max(abs(y1-y2b))
differenceb =
3.5527e-15
% (a) FFT size = 4096
t = cputime; y2c = hsolpsav(x,h,4096); t_4096 = cputime-t
t_4096 =
0.1200
y2c = y2c(1:1000001); differencec = max(abs(y1-y2c))
differencec =
4.4409e-15
3. Compare the above approaches in terms of the convolution results and their execution times.
First, the difference between all four convolutions is negligible as indicated by the output of the M ATLAB
script. The conv function is the slowest in execution while the high-speed overlap-and-save method with
FFT size 4096 the fastest.

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
264 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.30 A 512-point DFT X(k) of a real-valued sequence x(n) has the following DFT values:

X(0) = 20 + jα; X(5) = 20 + j30; X(k1 ) = −10 + j15; X(152) = 17 + j23;


X(k2 ) = 20 − j30; X(k3 ) = 17 − j23; X(480) = −10 − j15; X(256) = 30 + jβ

and all other values are known to be zero.


1. The real-valued coefficients α and β: Since the sequence x(n) is real-valued, X(k) is conjugate sym-
metric which means that X(0) and X(N/2) are also real-valued. Since N = 512, X(0) and X(256) are
real-valued. Hence α = β = 0.
2. The values of the integers k1 , k2 , and k3 : Again using the conjugate symmetry property of the DFT, we
have X(k) = X ∗ (N − k). Thus

X(5) = 20 + j30 = X ∗ (512 − 5) = X ∗ (507) ⇒ X(507) = 20 − j30 ⇒ k2 = 507


X(480) = −10 − j15 = X ∗ (512 − 480) = X ∗ (32) ⇒ X(32) = −10 + j15 ⇒ k1 = 32
X(152) = 17 + j23 = X ∗ (512 − 152) = X ∗ (360) ⇒ X(360) = 17 − j23 ⇒ k3 = 360

3. The energy of the signal x(n): Using Parseval’s relation,



 ∞
1 
Ex = |x(n)|2 = |X(k)|2
n=−∞
N
k=−∞
1  
= |X(0)|2 + 2|X(5)|2 + 2|X(32)|2 + 2|X(152)|2 + |X(256)|2 = 12.082
512
4. Sequence x(n) in a closed form: The time-domain sequence x(n) is a linear combination of the harmon-
ically related complex exponential. Hence
1 
x(n) = X(0) + X(5)e−2π5n/512 + X ∗ (5)e2π5n/512 + X(32)e−2π32n/512 + X ∗ (32)e2π32n/512
512 
+X(152)e−2π152n/512 + X ∗ (152)e2π152n/512 + X(256)e−2π256n/512
1       
= X(0) + 2Re X(5)e−2π5n/512 + 2Re X(32)e−2π32n/512 + 2Re X(152)e−2π152n/512
512 
+ X(256)(−1)n
1
= [20 + 72.111 cos(0.019531πn − 56.32◦ ) + 36.056 cos(0.125πn − 123.69◦ )
512
+57.201 cos(0.59375πn − 53.531◦ ) + 30(−1)n ]

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 265

P5.31 Let x(n) be a finite length sequence given by


 
x(n) = . . . , 0, 0, 0, 1, 2, −3, 4, −5, 0, . . .

Then the sequence

x((−8 − n))7 R7 (n) = x((−[n + 8]))7 R7 (n) = x((−[n + 8 − 7]))7 R7 (n)


= x((−[n + 1]))7 R7 (n)

where

1, 0 ≤ n ≤ 6
R7 (n) =
0, else

is a circularly folded and circularly shifted-by-(−1) version of the 7-point sequence {1, 2, −3, 4, −5, 0, 0}.
Hence

x((−8 − n))7 R7 (n) = {0, 0, −5, 4, −3, 2, 1}

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
266 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.32 Circular convolution using circulant matrix operation.



x1 (n) = {1, 2, 2} , x2 (n) = {1, 2, 3, 4} , x3 (n) =x1 (n) 4jx2 (n)

1. Using the results from Example 5.13, we can express the above signals as
⎡ ⎤ ⎡ ⎤
1 1 4 3 2
⎢ 2 ⎥ ⎢ 2 1 4 3 ⎥
x1 = ⎢ ⎥ ⎢
⎣ 2 ⎦ , X2 = ⎣ 3 2 1 4 ⎦

0 4 3 2 1

The matrix X2 has the property that its every row or column can be obtained from the previous row
or column using circular shift. Such a matrix is called a circulant matrix. It is completely described by
the first column or the row.
2. Circular convolution:
⎡ ⎤⎡ ⎤ ⎡ ⎤
1 4 3 2 1 15
⎢ 2 1 4 3 ⎥ ⎢ 2 ⎥ ⎢ 12 ⎥
x 3 = X 2 x1 = ⎢ ⎥⎢ ⎥ ⎢
⎣ 3 2 1 4 ⎦⎣ 2 ⎦ = ⎣ 9 ⎦

4 3 2 1 0 14

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 267

P5.33 M ATLAB function circulnt:

function C = circulnt(x,N)
% Circulant matrix generation using vector data values
% ----------------------------------------------------
% function C = circulnt(h,N)
%
% C : Circulant matrix
% x : input sequence of length <= N
% N : size of the circular buffer
% Method: C = h((n-m) mod N);

Mx = length(x); % length of x
x = [x, zeros(N-Mx,1)]; % zero-pad x
C = zeros(N,N); % establish size of C
m = 0:N-1; % indices n and m
x = circfold(x,N); % Circular folding
C = cirshift(x,m,N); % Circular shifting

M ATLAB verification on sequences in Problem 5.32:

N = 4; x1 = [1,2,2,0]; x2 = [1,2,3,4]; X2 = circulnt(x2,N)

X2 =
1.0000 4.0000 3.0000 2.0000
2.0000 1.0000 4.0000 3.0000
3.0000 2.0000 1.0000 4.0000
4.0000 3.0000 2.0000 1.0000

x3 = X2*x1’; x3 = x3’

x3 =
15.0000 12.0000 9.0000 14.0000

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
268 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.34 M ATLAB function circonvf:

function y = circonvf(x1,x2,N)
%
%function y=circonvf(x1,x2,N)
%
% N-point circular convolution between x1 and x2: (freq domain)
% -------------------------------------------------------------
% y : output sequence containing the circular convolution
% x1 : input sequence of length N1 <= N
% x2 : input sequence of length N2 <= N
% N : size of circular buffer
%
% Method: y(n) = idft(dft(x1)*dft(x2))

% Check for length of x1


if length(x1) > N
error(’N must be >= the length of x1’)
end

% Check for length of x2


if length(x2) > N
error(’N must be >= the length of x2’)
end

x1=[x1 zeros(1,N-length(x1))];
x2=[x2 zeros(1,N-length(x2))];

X1=fft(x1); X2=fft(x2);
y=real(ifft(X1.*X2));

Circular convolution {4, 3, 2, 1} 4j{1, 2, 3, 4}:

x1 = [4,3,2,1]; x2 = [1,2,3,4];
x3 = circonvf(x1,x2,4)

x3 =
24 22 24 30

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 269

P5.35 The following four sequences are given:

x1 (n) = {1, 3, 2, −1}; x2 (n) = {2, 1, 0, −1}; x3 (n) = x1 (n) ∗ x2 (n); x4 (n) = x1 (n) 5jx2 (n)
↑ ↑

1. Linear convolution x3 (n):

x3 (n) = x1 (n) ∗ x2 (n) = {2, 7, 7, −1, −4, −2, 1}


2. Computation of x4 (n) using x3 (n) alone: The error in the two convolutions is given by

e(n)=x4 (n) − x3 (n) = x3 (n + N )

we have, for N = 5,

e(0) = x4 (0) − x3 (0) = x3 (5) ⇒ x4 (0) = x3 (0) + x3 (5) = 2 − 2 = 0


e(1) = x4 (1) − x3 (1) = x3 (6) ⇒ x4 (1) = x3 (1) + x3 (6) = 7 + 1 = 8
e(2) = x4 (2) − x3 (2) = x3 (7) ⇒ x4 (2) = x3 (2) + x3 (7) = 7 + 0 = 7
e(3) = x4 (3) − x3 (3) = x3 (8) ⇒ x4 (3) = x3 (3) + x3 (8) = −1 + 0 = −1
e(4) = x4 (4) − x3 (4) = x3 (9) ⇒ x4 (4) = x3 (4) + x3 (9) = −4 + 0 = −4

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
270 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.36 Computation and plotting of the N -point circular convolutions between two finite-length sequences.
1. x1 (n) = sin(πn/3)R6 (n), x2 (n) = cos(πn/4)R8 (n); N = 10: M ATLAB script:
N = 10; n = 0:N-1;n1 = 0:5; x1 = sin(pi*n1/3);
n2 = 0:7; x2 = cos(pi*n2/4); x3 = circonvt(x1,x2,N);
Hf_1 = figure(’Units’,’inches’,’position’,[1,1,5,2],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,5,2]);
set(Hf_1,’NumberTitle’,’off’,’Name’,’P5.36.1’);
H_s1 = stem(n,x3,’filled’); set(H_s1,’markersize’,3);
title(’Circular Convolution {\itx}_3({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); xlabel(’{\itn}’); axis([-1,N,min(x3)-1,max(x3)+1]);
The sample plot is shown in Figure 5.31.

Circular Convolution x3(n)

2
Amplitude

−2

−1 0 1 2 3 4 5 6 7 8 9 10
n
Figure 5.31: The sample plot in Problem P5.36.1

2. x1 (n) = cos (2πn/N ) RN (n), x2 (n) = sin (2πn/N ) RN (n); N = 32: M ATLAB script:
N = 32; n = 0:N-1;
x1 = cos(2*pi*n/N); x2 = sin(2*pi*n/N); x3 = circonvt(x1,x2,N);
Hf_2 = figure(’Units’,’inches’,’position’,[1,1,5,1.5],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,5,1.5]);
set(Hf_2,’NumberTitle’,’off’,’Name’,’P5.36.2’);
H_s2 = stem(n,x3,’filled’); set(H_s2,’markersize’,3);
title(’Circular Convolution {\itx}_3({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); xlabel(’{\itn}’); axis([-1,N,min(x3)-1,max(x3)+1]);
The sample plot is shown in Figure 5.32.

Circular Convolution x3(n)

10
Amplitude

−10

0 5 10 15 20 25 30
n

Figure 5.32: The sample plot in Problem P5.36.2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 271

n
3. x1 (n) = (0.8) RN (n), x2 (n) = (−0.8)n RN (n); N = 20: M ATLAB script:
N = 20; n = 0:N-1;
x1 = (0.8).^n; x2 = (-0.8).^n; x3 = circonvt(x1,x2,N);
Hf_3 = figure(’Units’,’inches’,’position’,[1,1,5,1.5],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,5,1.5]);
set(Hf_3,’NumberTitle’,’off’,’Name’,’P5.36.3’);
H_s3 = stem(n,x3,’filled’); set(H_s3,’markersize’,3);
title(’Circular Convolution {\itx}_3({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); xlabel(’{\itn}’); axis([-1,N,min(x3)-0.5,max(x3)+0.5]);
The sample plot is shown in Figure 5.33.

Circular Convolution x3(n)

1
Amplitude

0.5

−0.5
0 2 4 6 8 10 12 14 16 18 20
n

Figure 5.33: The sample plot in Problem P5.36.3

4. x1 (n) = nRN (n), x2 (n) = (N − n)RN (n); N = 10: M ATLAB script:


N = 10; n = 0:N-1;
x1 = n; x2 = (N-n); x3 = circonvt(x1,x2,N);
Hf_4 = figure(’Units’,’inches’,’position’,[1,1,5,1.5],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,5,1.5]);
set(Hf_4,’NumberTitle’,’off’,’Name’,’P5.36.4’);
H_s4 = stem(n,x3,’filled’); set(H_s4,’markersize’,3);
title(’Circular Convolution {\itx}_3({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); xlabel(’{\itn}’); axis([-1,N,min(x3)-10,max(x3)+10]);
The sample plot is shown in Figure 5.34.

Circular Convolution x3(n)


Amplitude

300

250

200
−1 0 1 2 3 4 5 6 7 8 9 10
n

Figure 5.34: The sample plot in Problem P5.36.4

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
272 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

5. x1 (n) = (0.8)n R20 ,x2 (n) = u(n) − u(n − 40); N = 50: M ATLAB script:
N = 50; n = 0:N-1; n1 = 0:19; x1 = (0.8).^n1;
n2 = 0:39; x2 = ones(1,40); x3 = circonvt(x1,x2,N);
Hf_5 = figure(’Units’,’inches’,’position’,[1,1,5,1.5],...
’color’,[0,0,0],’paperunits’,’inches’,’paperposition’,[0,0,5,1.5]);
set(Hf_5,’NumberTitle’,’off’,’Name’,’P5.36.5’);
H_s5 = stem(n,x3,’filled’); set(H_s5,’markersize’,3);
title(’Circular Convolution {\itx}_3({\itn})’,’fontsize’,10);
ylabel(’Amplitude’); xlabel(’{\itn}’); axis([-1,N,min(x3)-1,max(x3)+1]);

The sample plot is shown in Figure 5.35.

Circular Convolution x (n)


3
Amplitude

0
0 5 10 15 20 25 30 35 40 45 50
n

Figure 5.35: The sample plot in Problem P5.36.5

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 273

P5.37 Let x1 (n) and x2 (n) be two N -point sequences.



N −1
1. Since y(n) = x1 (n) Njx2 (n) = k=0 x1 (k) x2 ((n − k))N we have


N −1 
N −1 N
 −1 
N −1 
N −1
y(n) = x1 (k) x2 ((n − k))N = x1 (k) x2 ((n − k))N
n=0 n=0 k=0 k=0 n=0
−1
$k−1 −1
%

N  
N
= x1 (n) x2 (n − k + N ) + x2 (n − k)
n=0 n=0 n=k
−1
$ −1 −1−k
% −1
$N −k−1 −1
%

N 
N N 
N  
N
= x1 (n) x2 (n) + x2 (n) = x1 (n) x2 (n) + x2 (n)
n=0 n=N −k n=0 n=0 n=0 n=N −k
.N −1 / .N −1 /
 
= x1 (n) x2 (n)
n=0 n=0

2. Verification using the following sequences:

x1 (n) = {9, 4, −1, 4, −4, −1, 8, 3}; x2 (n) = {−5, 6, 2, −7, −5, 2, 2, −2}

Consider

7
x1 (n) = {9, 4, −1, 4, −4, −1, 8, 3} ⇒ x1 (n) = 22
n=0

7
x2 (n) = {−5, 6, 2, −7, −5, 2, 2, −2} ⇒ x2 (n) = −7
n=0

7
y(n) = x1 (n) 8jx2 (n) = {14, −9, −32, −74, −7, −16, −57, 27} ⇒ y(n) = −154
n=0

Hence
. /. /

7 
7 
7
y(n) = −154 = (22) × (−7) = x1 (n) x2 (n)
n=0 n=0 n=0

P5.38 Let X(k) be the 8-point DFT of a 3-point sequence x(n) = {5, −4, 3}. Let Y (k) be the 8-point DFT of

a sequence y(n) where Y (k) = W85k X((−k))8 . Then using the circular folding and the circular shifting
properties of the DFT, we have
 
y(n) = IDFT W85k X((−k))8 = IDFT [X((−k))8 ]n→(n−5)
 
= x((−n))8 |n→(n−5) R8 (n) = x((5 − n))8 R8 (n) = {0, 0, 0, 3, −4, 5, 0, 0}

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
274 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

P5.39 Computation of (i) the N -point circular convolution x3 (n) = x1 (n) Njx2 (n), (ii) the linear convolution
x4 (n) = x1 (n) ∗ x2 (n), and (iii) the error sequence e(n) = x3 (n) − x4 (n) for the following sequences:
1. x1 (n) = {1, 1, 1, 1}, x2 (n) = cos(πn/4)R6 (n); N = 8:
x1 = [1,1,1,1]; x2 = cos(pi*[0:5]/4); N = 8; n = 0:N-1;
x3 = circonvt(x1,x2,N);
x4 = conv(x1,x2); n4 = 0:length(x4)-1;
e1 = x3 - x4(1:N); e2 = x4(N+1:end);
The plots of various signals are shown in Figure 5.36.

Circular Convolution: x3(n)


2
1
Amplitude

0
−1
−2
−3
−1 0 1 2 3 4 5 6 7 8 9

Linear Convolution: x4(n)


2
1
Amplitude

0
−1
−2
−3
−1 0 1 2 3 4 5 6 7 8 9

Error: x3(n) − x4(n)


2
1
Amplitude

0
−1
−2
−3
−1 0 1 2 3 4 5 6 7 8 9

Error: x4(n+N)
2
1
Amplitude

0
−1
−2
−3
−1 0 1 2 3 4 5 6 7 8 9
n
Figure 5.36: The sample plot of various signals in Problem P5.39.1

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 275

2. x1 (n) = cos(2πn/N )R16 (n), x2 (n) = sin(2πn/N )R16 (n); N = 32:


N = 32; x1 = cos(2*pi*[0:15]/N); x2 = sin(2*pi*[0:15]/N);
x3 = circonvt(x1,x2,N); n3 = 0:N-1;
x4 = conv(x1,x2); n4 = 0:length(x4)-1;
e1 = x3 - [x4,0];
e2 = x4(N+1:end);
The plots of various signals are shown in Figure 5.37.

Circular Convolution: x3(n)

5
Amplitude

−5
0 5 10 15 20 25 30

Linear Convolution: x (n)


4
5
Amplitude

−5
0 5 10 15 20 25 30

Error: x (n) − x (n)


3 4
5
Amplitude

−5
0 5 10 15 20 25 30

Error: x4(n+N)

5
Amplitude

−5
0 5 10 15 20 25 30
n
Figure 5.37: The sample plot of various signals in Problem P5.39.2

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
276 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

3. x1 (n) = (0.8)n R10 (n), x2 (n) = (−0.8)n R10 (n); N = 15:


N = 15; x1 = (0.8).^[0:9]; x2 = (-0.8).^[0:9];
x3 = circonvt(x1,x2,N); n3 = 0:N-1;
x4 = conv(x1,x2); n4 = 0:length(x4)-1;
e1 = x3 - x4(1:N);
e2 = x4(N+1:end); Ne2 = length(e2);
The plots of various signals are shown in Figure 5.38.

Circular Convolution: x3(n)


1.5

1
Amplitude

0.5

−0.5
0 2 4 6 8 10 12 14 16 18

Linear Convolution: x4(n)


1.5

1
Amplitude

0.5

−0.5
0 2 4 6 8 10 12 14 16 18

Error: x3(n) − x4(n)


1.5

1
Amplitude

0.5

−0.5
0 2 4 6 8 10 12 14 16 18

Error: x4(n+N)
1.5

1
Amplitude

0.5

−0.5
0 2 4 6 8 10 12 14 16 18
n

Figure 5.38: The sample plot of various signals in Problem P5.39.3

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 277

4. x1 (n) = nR10 (n), x2 (n) = (N − n)R10 (n); N = 10:


N = 10; n = 0:N-1; x1 = n; x2 = N-n;
x3 = circonvt(x1,x2,N); n3 = 0:N-1;
x4 = conv(x1,x2); n4 = 0:length(x4)-1;
e1 = x3 - x4(1:N);
e2 = x4(N+1:end); Ne2 = length(e2);
The plots of various signals are shown in Figure 5.39.

Circular Convolution: x3(n)

300
Amplitude

200

100

0
0 2 4 6 8 10 12 14 16 18

Linear Convolution: x4(n)

300
Amplitude

200

100

0
0 2 4 6 8 10 12 14 16 18

Error: x3(n) − x4(n)

300
Amplitude

200

100

0
0 2 4 6 8 10 12 14 16 18

Error: x4(n+N)

300
Amplitude

200

100

0
0 2 4 6 8 10 12 14 16 18
n

Figure 5.39: The sample plot of various signals in Problem P5.39.4

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
278 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

5. x1 (n) = {1, −1, 1, −1}, x2 (n) = {1, 0, −1, 0}; N = 5:


N = 5; n = 0:N-1; x1 = [1,-1,1,-1]; x2 = [1,0,-1,0];
x3 = circonvt(x1,x2,N); n3 = 0:N-1;
x4 = conv(x1,x2); n4 = 0:length(x4)-1;
e1 = x3 - x4(1:N);
e2 = x4(N+1:end); Ne2 = length(e2);
The plots of various signals are shown in Figure 5.40.

Circular Convolution: x3(n)

2
Amplitude

1
0
−1
−2
−1 0 1 2 3 4 5 6 7

Linear Convolution: x4(n)

2
Amplitude

1
0
−1
−2
−1 0 1 2 3 4 5 6 7

Error: x3(n) − x4(n)

2
Amplitude

1
0
−1
−2
−1 0 1 2 3 4 5 6 7

Error: x4(n+N)

2
Amplitude

1
0
−1
−2
−1 0 1 2 3 4 5 6 7
n

Figure 5.40: The sample plot of various signals in Problem P5.39.5

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 279

P5.40 The overlap-add method of block convolution is an alternative to the overlap-save method. Let x(n) be a
long sequence of length M L where M, L 1. Divide x(n) into M segments {xm (n), m = 1, . . . , M }
each of length L
 
M −1
x(n), mL ≤ n ≤ (m + 1)L − 1
xm (n) = so that x(n) = xm (n)
0, elsewhere
m=0

Let h(n) be an L-point impulse response, then


M −1 
M −1

y(n) = x(n) ∗ h(n) = xm (n) ∗ h(n) = ym (n); ym (n) = xm (n) ∗ h(n)
m=0 m=0

Clearly, ym (n) is a (2L − 1)-point sequence. In this method we have to save the intermediate convolution
results and then properly overlap these before adding to form the final result y(n). To use DFT for this
operation we have to choose N ≥ (2L − 1).
1. M ATLAB function to implement the overlap-add method using the circular convolution operation:
function [y] = ovrlpadd(x,h,N)
% Overlap-Add method of block convolution
% ----------------------------------------
% [y] = ovrlpadd(x,h,N)
% y = output sequence
% x = input sequence
% h = impulse response
% N = DFT length >= 2*length(h)-1
%
Lx = length(x); L = length(h); L1 = L-1;
h = [h zeros(1,N-L)];
%
M = ceil(Lx/L); % Number of blocks
x = [x, zeros(1,M*L-Lx)]; % append (M*N-Lx) zeros
Y = zeros(M,N); % Initialize Y matrix
%
% convolution with succesive blocks
for m = 0:M-1
xm = [x(m*L+1:(m+1)*L),zeros(1,N-L)];
Y(m+1,:) = circonvt(xm,h,N);
end
%
% Overlap and Add
Y = [Y,zeros(M,1)]; Y = [Y;zeros(1,N+1)];
Y1 = Y(:,1:L); Y1 = Y1’; y1 = Y1(:);
Y2 = [zeros(1,L);Y(1:M,L+1:2*L)]; Y2 = Y2’; y2 = Y2(:);
y = y1+y2; y = y’; y = removetrailzeros(y);

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
280 S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E

2. The radix-2 FFT implementation for high-speed block convolution:


function [y] = hsolpadd(x,h)
% High-Speed Overlap-Add method of block convolution
% --------------------------------------------------
% [y] = hsolpadd(x,h)
% y = output sequence (real-valued)
% x = input sequence (real-valued)
% h = impulse response (real-valued)
%

Lx = length(x); L = length(h); N = 2^ceil(log2(2*L-1));


H = fft(h,N);
%
M = ceil(Lx/L); % Number of blocks
x = [x, zeros(1,M*L-Lx)]; % append (M*N-Lx) zeros
Y = zeros(M,N); % Initialize Y matrix
%
% convolution with succesive blocks
for m = 0:M-1
xm = [x(m*L+1:(m+1)*L),zeros(1,N-L)];
Y(m+1,:) = real(ifft(fft(xm,N).*H,N));
end
%
% Overlap and Add
Y = [Y,zeros(M,1)]; Y = [Y;zeros(1,N+1)];
Y1 = Y(:,1:L); Y1 = Y1’; y1 = Y1(:);
Y2 = [zeros(1,L);Y(1:M,L+1:2*L)]; Y2 = Y2’; y2 = Y2(:);
y = y1+y2; y = y’; y = removetrailzeros(y);
3. Verification using the following two sequences

x(n) = cos (πn/500) R4000 (n), h(n) = {1, −1, 1, −1}

n = 0:4000-1; x = cos(pi*n/500); h = [1,-1,1,-1];


y1 = ovrlpadd(x,h,7);
y2 = hsolpadd(x,h);
y3 = conv(x,h);
e1 = max(abs(y1-y3))
e2 = max(abs(y1-y2(1:end-1)))
e1 =
2.7756e-017
e2 =
3.6342e-016

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.
S OLUTIONS M ANUAL FOR E SSENTIALS OF D IGITAL S IGNAL P ROCESSING U SING MATLAB 3 E 281

P5.41 Given the sequences x1 (n) and x2 (n) shown below:

x1 (n) = {2, 1, 1, 2} , x2 (n) = {1, −1, −1, 1}

1. Circular convolutions x1 (n) Njx2 (n):


N = 4 : x1 (n) 4jx2 (n) = {0, 0, 0, 0}
N = 7 : x1 (n) 7jx2 (n) = {2, −1, 2, 0, −2, 1, −2}
N = 8 : x1 (n) 8jx2 (n) = {2, −1, 2, 0, −2, 1, −2, 0}
2. The linear convolution: x1 (n) ∗ x2 (n) = {2, −1, 2, 0, −2, 1, −2}.
3. From the results of the above two parts, the minimum value of N to make the circular convolution equal
to the linear convolution is 7.
4. If we make N equal to the length of the linear convolution which is equal to the length of x1 (n) plus the
length of x2 (n) minus one, then the desired result can be achieved. In this case then N = 4 + 4 − 1 = 7,
as expected.

© 2012 Cengage Learning. All Rights Reserved. This edition is intended for use outside of the U.S. only, with content that may be
different from the U.S. Edition. May not be scanned, copied, duplicated, or posted to a publicly accessible website, in whole or in part.

You might also like