# Chapter 5

The Discrete Fourier Transform
1. Problem P 5.1  

(a) Periodic sequence: x˜1 (n) =

:::;

2 0; 2; 0; 2; 0; 2; 0; 2; 0; : : : . Now,

"

;

N 1

X˜1 (k) =

∑ x˜1 (n) WNnk ; N = 4; W4 = e

j2π=4

=

j

=

4
0
4
0

n =0

Hence,

X˜1 (0)
X˜1 (1)
X˜1 (2)
X˜1 (3)

=
=
=
=

2 (1) + 0 (1) + 2 (1) + 0 (1)
2 (1 ) + 0 ( j ) + 2 ( 1 ) + 0 ( j )
2 (1) + 0 ( 1) + 2 (1) + 0 ( 1)
2 (1 ) + 0 ( j ) + 2 ( 1 ) + 0 ( j )

=
=
=

M ATLAB verification:
xtilde1 = [2,0,2,0]; N = length(xtilde1);
[Xtilde1] = dft(xtilde1,N)
Xtilde1 =
4.0000
0 - 0.0000i
4.0000 + 0.0000i 

(b) Periodic sequence: x˜2 (n) =

0 - 0.0000i 

:::;

0; 0; 1; 0; 0; 0; 0; 1; 0; 0; : : : . Now,

"

N 1

X˜2 (k) =

∑ x˜2 (n) WNnk ; N = 5; W5 = e

j2π=5

= 0:3090

j0:9511

n=0

Hence,

X˜2 (0)
X˜2 (1)
X˜2 (2)
X˜2 (3)
X˜2 (4)

=
=
=
=
=

0 + 0 + 1 (1) + 0 + 0
0 + 0 + 1 (0:3090 j0:9511)2 + 0 + 0
0 + 0 + 1 (0:3090 j0:9511)4 + 0 + 0
0 + 0 + 1 (0:3090 j0:9511)6 + 0 + 0
0 + 0 + 1 (0:3090 j0:9511)8 + 0 + 0

=

1

=

0:8090 j0:5878
0:3090 + j0:9511
0:3090 j0:9511
0:8090 + j0:5878

=
=
=

M ATLAB verification:
xtilde2 = [0,0,1,0,0]; N = length(xtilde2);
[Xtilde2] = dft(xtilde2,N)
Xtilde2 =
Columns 1 through 4
1.0000
-0.8090 - 0.5878i
0.3090 + 0.9511i
Column 5
-0.8090 + 0.5878i
45

0.3090 - 0.9511i

46

S OLUTIONS M ANUAL

FOR

DSP

USING 

M ATLAB

A PRIL 98 

(c) Periodic sequence: x˜3 (n) =

:::;

3; 3; 3; 3; 3; 3; 3; 3; : : : . Now,

"

N 1

X˜3 (k) =

∑ x˜3 (n) WNnk ; N = 4; W4 = e

j2π=4

=

j

n=0

Hence,

X˜3 (0)
X˜3 (1)
X˜3 (2)
X˜3 (3)

=

3 (1 )
3 (1 )
3 (1 )
3 (1 )

=
=
=

3 (1) + 3 (1) 3 (1)
3 ( j ) + 3 ( 1) 3 ( j )
3 ( 1) + 3 (1) 3 ( 1)
3 ( j ) + 3 ( 1) 3 ( j )

=

0
0
12
0

=
=
=

M ATLAB verification:
xtilde = [3,-3,3,-3]; N = length(xtilde);
[Xtilde] = dft(xtilde,N)
Xtilde =
0
0.0000 - 0.0000i 12.0000 + 0.0000i
(

(d) Periodic sequence: x˜4 (n) =

)

j; j;

:::;

"

j;

j; j; j;

j;

j; : : : . Now,

N 1

X˜4 (k) =

0.0000 - 0.0000i

∑ x˜4 (n) WNnk ; N = 4; W4 = e

j2π=4

j (1) + j (1) j (1) j (1)
j ( 1) + j ( j ) j ( 1) j ( j )
j (1) + j ( 1) j (1) j ( 1)
j ( 1) + j ( j ) j ( 1) j ( j )

=

=

j

n=0

Hence,

X˜4 (0)
X˜4 (1)
X˜4 (2)
X˜4 (3)

=
=
=
=

0
2 + j2
0
2 + j2

=
=
=

M ATLAB verification:
xtilde = [j,j,-j,-j]; N = length(xtilde4);
[Xtilde4] = dft(xtilde4,N)
Xtilde4 =
0
2.0000 + 2.0000i 

(e) Periodic sequence: x˜5 (n) = 

:::;

0

-2.0000 + 2.0000i

1; j; j; 1; 1; j; j; 1; j; j; : : : . Now,

"

N 1

X˜5 (k) =

∑ x˜5 (n) WNnk ; N = 4; W4 = e

j2π=4

=

j

n=0

Hence,

X˜5 (0)
X˜5 (1)
X˜5 (2)
X˜5 (3)

=
=
=
=

1 (1) + j (1) + j (1) + 1 (1)
1 (1 ) + j ( j ) + j ( 1 ) + 1 ( j )
1 (1 ) + j ( 1 ) + j (1 ) + 1 ( 1 )
1 (1 ) + j ( j ) + j ( 1 ) + 1 ( j )

=
=
=
=

2+2j
2
0
2j

M ATLAB verification:
xtilde5 = [1,j,j,1]; N5 = length(xtilde5);
[Xtilde5] = dft(xtilde5,N5)
Xtilde5 =
2.0000 + 2.0000i
2.0000 + 0.0000i
0.0000 - 0.0000i
2. Problem P 5.2

0.0000 - 2.0000i

Now. 3.1625i Column 5 -0.5000 .4.6882i -0.-2*j.N)) xtilde2 = -0.5000 (b) Periodic DFS sequence: X˜2 (k) = f4. x˜1 (n) = 1N 1˜ X1 (k) WN nk .0. x˜2 (0) x˜2 (1) x˜2 (2) x˜2 (3) = [4 (1) = [4 (1) = [4 (1) = [4 (1) 5 (1) + 3 (1) 5 (1)] =4 5 ( j) + 3 ( 1) 5 ( j)] =4 5 ( 1) + 3 (1) 5 ( 1)] =4 5 ( j) + 3 ( 1) 5 ( j)] =4 = 0:75 0:25 4:25 0:25 = = = M ATLAB verification: Xtilde2 = [4. x˜3 (0) x˜3 (1) x˜3 (2) x˜3 (3) x˜3 (4) = = = = = 1N 1˜ X3 (k) WNnk .-5]. 5.5000 + 0. Now. [xtilde3] = idfs(Xtilde3. W4 = e N k∑ =0 j2π=4 = j Hence.3. [xtilde1] = real(idfs(Xtilde1. W4 N k∑ =0 1 =e j2π=4 = j Hence.0.0000 -0.5].2500 0.2500 4.0000 -0. N = length(Xtilde2). 2 j. 3. N = length(Xtilde3). N = 4.N1)) xtilde1 = 2. x˜3 (n) = Hence. N = 4. 5g.2. 4. N1 = length(Xtilde1).5000 + 0.5000 2.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 47 (a) Periodic DFS sequence: X˜1 (k) = f5. 5g. 2 jg. 3. N = 4.2500 (c) Periodic DFS sequence: X˜3 (k) = f1.2*j].0000 1.1625i . N = 5. Now.N) xtilde3 = Columns 1 through 4 3. x˜2 (n) = 1N 1˜ X2 (k) WNnk . 2.-5. W5 = e N k∑ =0 j2π=5   0 0 0 0 0 1W50 + 2W51 + 3W52 + 4W53 + 5W54  =5 1W50 + 2W52 + 3W54 + 4W56 + 5W58  =5 1W50 + 2W53 + 3W56 + 4W59 + 5W512 =5 1W50 + 2W54 + 3W58 + 4W512+ 5W5 16 =5 1W5 + 2W5 + 3W5 + 4W5 + 5W5 5 = = 0:3090 = = = = = j0:9511 3 0:5000 j0:6882 0:5000 j0:1625 0:5000 + j0:1625 0:5000 + j0:6882 M ATLAB verification: Xtilde3 = [1.5000 .3.6882i -0. [xtilde2] = real(idfs(Xtilde2.7500 0.3. x˜1 (0) x˜1 (1) x˜1 (2) x˜1 (3) = [5 (1) = [5 (1) = [5 (1) = [5 (1) 2 j (1) + 3 (1) + 2 j (1)] =4 2 j ( j) + 3 ( 1) + 2 j ( j)] =4 2 j ( 1) + 3 (1) + 2 j ( 1)] =4 2 j ( j) + 3 ( 1) + 2 j ( j)] =4 = = = = 2 1:5 2 0:5 M ATLAB verification: Xtilde1 = [5.

W4 N k∑ =0 1 =e j2π=4 = j Hence. N = 4. N = 4.0. x˜ (n) = 1N 1˜ X (k) WNnk .5000 + 0. [xtilde5] = real(idfs(Xtilde5.2.3 Periodic x˜1 (n) with fundamental period N = 50  x˜1 (n) = ne 0:3n .N)) xtilde4 = 0. N = 4. 0g.0].0. W4 = e N k∑ =0 j2π=4 = j Hence.5000i (d) Periodic DFS sequence: X˜ (k) = f0.2500i 0. x˜5 (n) = DSP USING M ATLAB A PRIL 98 jg. 0.0. [xtilde4] = real(idfs(Xtilde4.5000 -0.5000i 0. j. 2 j.5000 -0. Now.5000 3.0000 .-2*j. N5 = length(Xtilde5). x˜5 (0) x˜5 (1) x˜5 (2) x˜5 (3) = [0 (1) + j (1) = = [0 (1) + j ( j) 2 j (1) j (1)] =4 2 j ( 1) j ( j)] =4 1) 2 j (1) 2 j ( 1)] =4 j) 2 j ( 1) j ( j)] =4 = = [0 (1) + j ( = = [0 (1) + j ( j0:5 0:5 + j0:5 j0:25 0:5 + j0:5 = M ATLAB verification: Xtilde5 = [0.5000 0. 1N 1˜ X5 (k) WN nk . N = length(Xtilde4). Problem P 5.48 S OLUTIONS M ANUAL FOR (e) Periodic DFS sequence: X˜5 (k) = f0. x˜ (0) x˜ (1) x˜ (2) x˜ (3) = [0 (1) + 0 (1) + 2 (1) + 0 (1)] =4 = = [0 (1) + 0 ( = = = j) + 2 ( 1) + 0 ( j)] =4 [0 (1) + 0 ( 1) + 2 (1) + 0 ( 1)] =4 [0 (1) + 0 ( j) + 2 ( 1) + 0 ( j)] =4 = = 0:5 0:5 0:5 0:5 M ATLAB verification: Xtilde4 = [00.j.5000i -0.-j]. 2. Now.5000 + 0.N1)) xtilde1 = 0 .

0. 0  n  25 . .

.

26  n  49 .

[Xtilde1] = dft(xtilde1.’NumberTitle’.8.0. n1 = [0:49].’P5.’off’.1.3*n1(1:26)).’normalized’. close all. 0. pha_Xtilde1 = angle(Xtilde1)*180/pi.0. xtilde1 = [n1(1:26).’Name’. zei = find(mag_Xtilde1 < 1000*eps). % (a) DFS Xtilde1(k) Hf_1 = figure(’Units’.1. mag_Xtilde1 = abs(Xtilde1).length(zei)).3a’). k1 = n1.0. 0  n  25 26  n  99  PERIODIC (a) Computation of X˜1 (k) using M ATLAB: clear.PERIODIC Periodic x˜2 (n) with fundamental period N = 100  x˜2 (n) = ne 0:3n .’position’.’color’. .*exp(-0.[0.0]). N1 = length(n1).8].0.N1).[0.zeros(1. pha_Xtilde1(zei) = zeros(1. set(Hf_1.24)].

’XTickMode’.5 0 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 Magnitude of Xtilde1(k) |Xtilde1| 10 8 6 4 2 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 Phase of Xtilde1(k) Angle in Deg 180 90 0 −90 −180 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 k Figure 5. pha_Xtilde2 = angle(Xtilde2)*180/pi.90. ylabel(’|Xtilde1|’) ktick = [k1(1):2:k1(N1).0.min(xtilde1). axis([-1.’position’.’XTickMode’. n2 = [0:99].N1. mag_Xtilde2 = abs(Xtilde2). set(gca.’normalized’. axis([-1.10) subplot(3.1.50)].max(mag_Xtilde1) title(’Magnitude of Xtilde1(k)’).N1]’.1.xtilde1). N2 = length(n2).ntick) . [Xtilde2] = dft(xtilde2.’XTick’.[0.10) set(gca.N1.N2.[-180.N1]’.8].’off’.’XTick’. k2 = n2.1).1.’YTickMode’.pha_Xtilde1).3a (b) Computation of X˜2 (k) using M ATLAB: % (b) DFS Xtilde2(k) Hf_2 = figure(’Units’. xlabel(’k’).’manual’.’manual’. ntick = [n1(1):2:n1(N1). zeros(1.0. ylabel(’xtilde2’).0. stem(n2.N2]’.’FontSize’.ntick. title(’One period of the periodic sequence xtilde2(n)’). xtilde2 = [xtilde1.1: Plots of x˜1 (n) and X˜1 (k) in Problem 5.min(xtilde2).’P5.’YTick’.’manual’.3b’).-180. stem(k1. ylabel(’xtilde1’).’color’. ntick = [n2(1):5:n2(N2).0]).1. pha_Xtilde2(zei) = zeros(1. subplot(3.’FontSize’.min(mag_Xtilde1).ktick.N2).10) subplot(3.N1]’. title(’One period of the periodic sequence xtilde1(n)’).A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 49 subplot(3.’manual’.ktick. title(’Phase of Xtilde1(k)’). axis([-1.[0.’XTickMode’.2).0. stem(n1.’XTickMode’.’XTick’.max(xtilde2)]).’NumberTitle’.1).8. axis([-1.xtilde2).0. set(gca. zei = find(mag_Xtilde2 < 1000*eps).1. Problem 3a Plots One period of the periodic sequence xtilde1(n) xtilde1 1 0. set(gca.-90. ylabel(’Angle in Deg’) ktick = [k1(1):2:k1(N1). set(Hf_2.’FontSize’.’Name’.1.max(xtilde1)]).length(zei)). stem(k1.180]) Plots of x˜1 (n) and X˜1 (k) are shown in Figure 5.’manual’.3).N1. set(gca.’XTick’.mag_Xtilde1).180]).1.

close all. set(Hf_1.’manual’.0.5 |Xtilde2| 0 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Magnitude of Xtilde2(k) 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Phase of Xtilde2(k) 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 k 10 8 6 4 2 Degrees 180 90 0 −90 −180 Figure 5.max(mag_Xtilde2)]).1.3). xtilde3 = [xtilde1. 4. set(gca.N2]’.0. k3 = n3.2: Plots of Magnitude and Phase of X˜2 (k) in Problem 5. Problem 3b Plots One period of the periodic sequence xtilde2(n) xtilde2 1 0. N3 = length(n3). Problem P 5.. N1 = length(n1). axis([-1.3b (c) Changing the period from N = 50 to N = 100 resulted in a lower frequency sampling interval (higher frequency resolution) ω1 . The shape of the DTFT begins to fill in with N = 100.’position’. stem(k2.zeros(1.’normalized’.’XTick’.’XTick’. i.N2.8].’NumberTitle’. Hence there are more terms in the DFS expansion of x˜2 (n). n3 = [0:99]. [Xtilde3] = dft(xtilde3.’P5.mag_Xtilde2).N2]’.’YTickMode’.0]).0. mag_Xtilde3 = abs(Xtilde3).2. title(’Magnitude of Xtilde2(k)’).min(mag_Xtilde2). stem(k2.[0.4 New periodic sequence x˜3 (n) with period N = 100 x˜3 (n) = [x˜1 (n) . xtilde1]. % (a) DFS Xtilde3(k) Hf_1 = figure(’Units’.N3). ylabel(’|Xtilde2|’) ktick = [k2(1):5:k2(N2).’XTickMode’. in (3a) ω1 = π=25 and in (3b) ω2 = π=50.’XTickMode’.180]).’YTick’.e.ktick) subplot(3.50 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 subplot(3.180]) Plots of x˜2 (n) and X˜2 (k) are shown in Figure 5.90.’manual’.-90. .3*n1(1:26)).1.4a’).0. title(’Phase of Xtilde2(k)’).24)].1. xlabel(’k’). n1 = [0:49].[0. set(gca.2).N2.-180.ktick) set(gca.1. x˜1 (n)]PERIODIC (a) Computation of X˜3 (k) using M ATLAB: clear. xtilde1 = [n1(1:26). ylabel(’Degrees’) ktick = [k2(1):5:k2(N2). axis([-1.0.8.*exp(-0.’Name’.’color’.[-180.’manual’.’off’. pha_Xtilde3 = angle(Xtilde3)*180/pi.pha_Xtilde2).

ylabel(’Degrees’) ktick = [k3(1):5:k3(N3).N3]’. ylabel(’xtilde3’). pha_Xtilde3(zei) = zeros(1.’XTick’. (c) We can now generalize this argument.0. subplot(3. for phase plots. The effect of periodicity doubling is in the doubling of magnitude of each sample. look exactly same.1. ylabel(’|Xtilde3|’) ktick = [k3(1):5:k3(N3). axis([-1. If 8 > < x˜M (n) = 9 > = x˜1 (n) .’manual’.’XTick’.min(xtilde3). (In general.2).’XTickMode’. stem(n3.max(mag_Xtilde3) title(’Magnitude of Xtilde3(k)’). axis([-1.180]) Plots of x˜3 (n) and X˜3 (k) are shown in Figure 5. we observe that these plots are essentially similar.pha_Xtilde3).180]). set(gca.’YTickMode’.’YTick’. x˜1 (n) .90.’XTick’. title(’One period of the periodic sequence xtilde3(n)’). Clearly these phase values have no meaning and should be ignored. when viewed over ∞ < n < ∞ interval.N3.5 0 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Magnitude of Xtilde3(k) 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 Phase of Xtilde3(k) 0 5 10 15 20 25 30 35 40 45 50 55 60 65 70 75 80 85 90 95 100 k |Xtilde3| 20 15 10 5 Degrees 180 90 0 −90 −180 Figure 5.’manual’.’XTickMode’.-90. Problem 4 Plots One period of the periodic sequence xtilde3(n) xtilde3 1 0. ntick = [n3(1):5:n3(N3).1.’manual’. set(gca.N3. set(gca. I avoided this problem by using the find function.’XTickMode’.3. PERIODIC .xtilde3). we do get non-zero phase values when the magnitudes are zero.’manual’.1).-180. x˜1 (n) > :| {z M times }> .max(xtilde3)]).3: Plots of x˜3 (n) and X˜3 (k) in Problem 5. : : : . title(’Phase of Xtilde3(k)’) xlabel(’k’).1.00001). This happens because of a particular algorithm used by M ATLAB.4a (b) Comparing the magnitude plot above with that of X˜1 (k) in Problem (3a).ktick) subplot(3.) This makes sense because sequences x˜1 (n) and x˜3 (n).N3]’.[-180.min(mag_Xtilde3).length(zei)).N3]’.ntick) subplot(3.N3. stem(k3.mag_Xtilde3).ktick) set(gca.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 51 zei = find(mag_Xtilde3 < 0. Plots of X˜3 (k) have one zero between every sample of X˜1 (k).3). stem(k3. axis([-1.

6.6.w).’HS020500’). % Set phase values to pha_Xk(zei) = zeros(1.6.X(28*pi/20)} N = 20.N)) y1 = 0.0. close all.0000 0. 5 + ( 2) + ( 3) . 5.N).5.X(2*pi/3). y2 = real(idfs(Y2.0000 6.n. 6. % given signal x(n) Xk = dft(xn.’NumberTitle’.1.0.2. % zero when mag is zero Hf_1 = figure(’Units’.5.0000 -4.0. 3.0000 0.’Name’.N. y1 = real(idfs(Y1. close all.N)) y2 = Columns 1 through 7 2. 4.-4.4.0000 0... 0. 3.0000 Columns 8 through 14 -3.0.[0. Thus y2 (n) = f2. .6 A 12-point sequence x (n) = f1.’position’.52 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 then there will be (M 1) zeros between samples of X˜M (k).4.00001). 1.1. k = 0:N-1. 2.  (a) Since y1 (n) is a 3-point IDFS of three samples of X e jω on the unit circle.0000 2. axis([0. 1. 0.. N 1 k 6= 0.0000 0. 5.0000 0.5  X e jω is a DTFT of a 10-point sequence x (n) = f2. i. 2. 2g.3.. 2. 3 + 6 + ( 3)g = f0.1.’color’. 0. 1g. (a) DFT X (k): clear.0000 -3.0000 0. 3.-2.0000 0.0000 0.2]. k = 0:N-1.mag_Xk). [Y1] = dtft(x. w = 2*pi*k/N. 2. 6gperiodic M ATLAB verification: clear.40]) . 3.3. 0. x = [2.3.0000 6. 0. The magnitudes of non-zero samples of X˜M (k) will be M times the magnitudes of the samples of X˜1 (k). N = length(xn).0000  (b) Since y2 (n) is a 20-point IDFS of twenty samples of X e jω on the unit circle.0]).0000 Columns 15 through 20 0. 4. k = 0:N-1.n. 5. [Y2] = dtft(x. 0. Problem P 5. 3. 5. stem(k. it can be obtained as a 3-point aliasing operation on x (n). 3.0000 6.0000 0.0000 0. w = 2*pi*k/N.0000 5. Thus y1 (n) = f2 + ( 4) + 0 + 2. 0.X(4*pi/3)} N = 3. % Mag and Phase of X(k) zei = find(mag_Xk < 0.2. 0. : : : . MN 5. 0. 4. 6. k = 0. 0. % xn = [1.. subplot(2. 3.’normalized’.0000 -2. X˜M (Mk) X˜M (k) = = M X˜1 (k) 0 .[0.1].w).e.0000 3. 0. 2.’off’.X(2*pi/20). % (a) y1(n) = 3-point IDFS{X(0). 4.-3. 0gperiodic M ATLAB verification: % (b) y1(n) = 20-point IDFS{X(0). set(Hf_1.length(zei)). 3. Problem P 5. pha_Xk = angle(Xk)*180/pi.5. n = 0:9. % DFT of x(n) mag_Xk = abs(Xk). 6. then from the frequency sampling theorem there will not be any aliasing of x (n) and y2 (n) will be a zero-padded version of x (n).8.1).-3. : : : .0000 0. 0.8].0. 6.0.

20.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 53 set(gca. title(’Phase plots of DFT and DTFT’) hold on The stem plot of X (k) is shown in 5.mag_X).4.1000.1. Plots in Problem P2. xlabel(’k’).180]).’YTickMode’. grid hold off subplot(2. (d) 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).’XTickMode’. Dw = (2*pi)/N.’YTick’.180]) set(gca. stem(k. subplot(2.[0. plot(w/Dw.2).’YTick’.’manual’.[-180.’manual’.’XTick’.’XTickMode’. set(gca. ylabel(’Degrees’). ylabel(’magnitude’). pha_X = angle(X)*180/pi.6  (b) DTFT X e jω : [X.1. set(gca.1. axis([0.’YTickMode’.-90.[0:1:N]). mag_X = abs(X).-180.w] = freqz(xn.  (c) Clearly.’whole’).40]).’manual’. plot(w/Dw. title(’Magnitude plots of DFT and DTFT’) hold on subplot(2. xlabel(’k’).4.’manual’.’XTick’.2).0.6 Magnitude plots of DFT and DTFT magnitude 40 20 0 0 1 2 3 4 5 6 7 8 9 10 11 12 8 9 10 11 12 Phase plots of DFT and DTFT 180 Degrees 90 0 −90 −180 0 1 2 3 4 5 6 k 7 Figure 5. We can reconstruct using the complex interpolation formula X e jω  N 1 = ∑ k=0  X (k) φ ω 2πk N  .N. grid hold off % DTFT of xn % mag and phase of DTFT % frequency resolution  The continuous plot of X e jω is also shown in Figure 5.90.1. the DFT in part (6a) is the sampled version of X e jω .[0:1:N]). where φ (ω) = e jω(N 1)=2 sin (ωN =2) N sin (ω=2) .pha_Xk).1).4: Plots of DTFT and DFT of signal in Problem 5.pha_X).

’P5.’Name’.1 0. subplot(2.0.’normalized’.N-N2)].mag_X1).6 frequency in pi units 0.8].0]). N = 300.’XTick’.1.45*pi*n)*sin(0. subplot(2. set(Hf_2. x1 = 2*cos(0.’position’. w = (0:N/2)*2*pi/N.[0.7a’).’P5. mag_X1 = abs(X1(1:N/2+1)).54 S OLUTIONS M ANUAL For N = 12. 0 <= n <= 50 Hf_2 = figure(’Units’. .55*pi*n2).1.5. zeros(1.min(x1). n2 = [0:50].0.3 0.7 This problem is done using M ATLAB. 0  n  50. % (a) x1(n) = 2*cos(0.0.8.2).max(mag_X1)]).N1]’. axis([0. N = 100.1.2*pi*n)*[u(n)-u(n-10)] Hf_1 = figure(’Units’.’position’. ylabel(’|X1|’).7a Plots Sequence x1(n) 2 x1 1 0 −1 −2 0 5 10 n Magnitude of DTFT X1(omega) 10 |X1| 8 6 4 2 0 0 0.4 0. xlabel(’frequency in pi units’).8 0.0.0.5 0.55*pi*n).N-N1)]. % (b) x2(n) = sin(0.2*pi*n1).’Name’.’manual’.N). x2 = sin(0.45*pi*n2). xlabel(’n’). [X2] = dft([x2.7a Plots’).’off’.7b’).1.N).N1. n1 = [0:9].[0. N1 = length(n1). stem(n1.’color’. The plots are shown in Figure 5.x1). set(Hf_1.*sin(0. we have X e jω  FOR DSP USING 11 = ∑ X (k) e M ATLAB j (5:5)ω k=0 A PRIL 98 sin (6ω) 12 sin (ω=2) 7.0. Problem P 5. set(gca.0. % Length of DFT [X1] = dft([x1.2 0.8.1.ntick).1.[0.’NumberTitle’.1). axis([-1.5: Sequence and its DTFT magnitude plots in Problem P5.9 1 Figure 5. ntick = [n1(1):5:n1(N1).’XTickMode’. (a) x1 (n) = 2 cos (0:2πn) [u (n) u (n 10)].’NumberTitle’. title(’Magnitude of DTFT X1(omega)’).’off’.7a (b) x2 (n) = sin (0:45πn) sin (0:55πn) . plot(w/pi.0]). ylabel(’x1’).1. Problem P 5. suptitle(’Problem P 5.max(x1)]).0. zeros(1.[0.0.7 0.’color’.’normalized’.8]. N2 = length(n2). title(’Sequence x1(n)’).

ylabel(’x3’).1).2).6: Sequence and its DTFT magnitude plots in Problem P5.min(x3).8]. x3 = 3*(2).5 0 −0.N).0.9 1 Figure 5.min(x2). plot(w/pi.6 frequency in pi units 0. stem(n3. w = (0:N/2)*2*pi/N. The plots are shown in Figure 5.7c’).8]. % Length of DFT [X3] = dft([x3. suptitle(’Problem P 5. zeros(1.8 0. suptitle(’Problem P 5. title(’Magnitude of DTFT X2(omega)’).11.1.’Name’.’normalized’. subplot(2.N-N3)]. set(Hf_1. set(gca. (e) x5 (n) = 5 0:9e jπ=4 n u (n).’normalized’.[. title(’Sequence x2(n)’). axis([-11.’XTick’.mag_X2).’off’.x3).’XTickMode’.9*exp(j*pi/4)).’XTickMode’.0]). stem(n2.0. % (c) x3(n) = 3*(2)ˆn*[u(n+10)-u(n-11)] Hf_1 = figure(’Units’.3 0. Problem P 5.2 0.ntick). 10  n  10. xlabel(’n’).0. set(gca.1.1.’P5..7c Plots’).’XTick’. xlabel(’frequency in pi units’).6. ntick = [n3(1):5:n3(N3)..1.’manual’.8.’NumberTitle’.1. .1 0.[0.0.0]).8.mag_X3). xlabel(’frequency in pi units’).’position’.ntick).max(mag_X2)]). title(’Sequence x3(n)’). The plots are shown in Figure 5. subplot(2.1.7. w = (0:N/2)*2*pi/N. ntick = [n2(1):10:n2(N2)]’.0.1).1.7 0.7b Plots Sequence x2(n) x2 0.N3]’. ylabel(’x2’).’color’.x2). N3 = length(n3). ylabel(’|X3|’). axis([0.1.7b (c) x3 (n) = 3 (2)n . This problem is done using M ATLAB. plot(w/pi. ylabel(’|X2|’).[0. N = 100.’manual’.’position’. n3 = [-10:10].7b Plots’). title(’Magnitude of DTFT X3(omega)’).’P5. subplot(2.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 55 mag_X2 = abs(X2(1:N/2+1)).5 0.7e’).max(x2)]).’Name’.ˆn3.’off’. axis([0. subplot(2.4 0.ˆn*u(n) Hf_1 = figure(’Units’.N2. % (e) x5(n) = 5*(0.0.1.max(x3)]).’color’. axis([-1.5 −1 0 10 20 30 40 50 n Magnitude of DTFT X2(omega) 25 |X2| 20 15 10 5 0 0 0.’NumberTitle’.1.0.[0. mag_X3 = abs(X3(1:N/2+1)).max(mag_X3)]).2).. set(Hf_1. xlabel(’n’).

7c n5 = [0:99]. set(gca.8 The impulse response h (n) is causal and real-valued. 8. 0k5 else  e jω dω = 0.  (a) It is known that Re H e jω  Re H e  jω k = ∑5k=0 (0:5) cos ωk.9*exp(j*pi/4)). subplot(2.max(x5)]). stem(n5.1.2). %axis([-11.6 frequency in pi units 0.0.2 0. x5 = real(x5). % Length of DFT [X5] = dft(x5.N5]’. Problem P 5.x5).  ( = Re Consider ) ∞ ∑ h (k) e jωk n ∞ = k =0 ∑ h (k) Re e k =0 jωk o ∞ = ∑ h (k) cos ωk k=0 Comparing with the given expression.ntick). N5 = length(n5).56 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 Problem P 5. axis([0.max(mag_X5)]).’XTick’. ylabel(’|X5|’).min(x5). title(’Magnitude of DTFT X5(omega)’). w = (0:N5/2)*2*pi/N5. subplot(2. Rπ πH  .11.1.’manual’. mag_X5 = abs(X5(1:N5/2+1)). suptitle(’Problem P 5. ntick = [n5(1):10:n5(N5).8 0. x5 = 5*(0.mag_X5).5 0.1). plot(w/pi.4 0. title(’Sequence real(x5(n))’). The plots are shown in Figure 5.7 0.’XTickMode’.1 0. From the second condition H e jω dω = h (0) = 0 .8.7c Plots Sequence x3(n) 3000 2500 x3 2000 1500 1000 500 −10 −5 0 n Magnitude of DTFT X3(omega) 5 10 6000 |X3| 4000 2000 0 0 0.ˆn5. we obtain  h (n) =  (b) It is known that Im H e jω  5 = ∑`=0 2` sin ω` Z π π and k (0:5) 0. xlabel(’frequency in pi units’).7e Plots’).N5).7: Plots in Problem P5. xlabel(’n’).3 0.1. ylabel(’real(x5)’).9 1 Figure 5.

5 0. Consider  Im H e jω  ( ) ∞ ∑ h (`) e = Im `= = ∑ h (`) Im e `= 0 Comparing with the given expression.1 0.9 An N-point sequence x (n): N 1 N 1 (a) The N-point DFT of x (n): X (k) = ∑ x (m) WNmk .8: DTFT plot in Problem P5. 0  `  5 0. else 9.7 Figure 5.8 0. . Hence. 0 n N 1 r= ∞ k=0 N 1 = k=0 ) ∑ ∑ ∑ ∑ 1 rN ) . if we take two more DFTs of x (n) then x ( n) ! N-point DFT ! N-point DFT ! N-point DFT ! N-point DFT ! N 2 x (n) Therefore. we obtain  h (n ) = n ∞ jω` jω` o ∞ = ∑ h ( ) sin ω ` ` `= 0 0 2`. This approach can be used to verify a DFT function.4 0.9 1 |X5| 40 30 20 10 0 0 0. The N-point DFT of X (k): y (n) = ∑ X (k) WNkn .6 frequency in pi units 80 90 100 0. Continuing further.2 0. N 1 y (n) = m=0 ( N 1 ∑ ∑ x (m) WNmk = N 1 WNkn = N 1 ∑ x (m) ∑ WNmkWNkn 0  n  N .3 0.7e. m=0 m=0 k =0 N 1 N 1 ∞ (m+n)k x ( m) WN = x ( m) Nδ (m + n r= ∞ m=0 m=0 k=0 ∞ N x ( n + rN ) = Nx (( n))N .7e Plots Sequence real(x5(n)) 6 real(x5) 4 2 0 −2 −4 0 10 20 30 40 50 60 70 n Magnitude of DTFT X5(omega) 0.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 57 Problem P 5. 0  n  N 1   ∑ This means that y (n) is a “circularly folded and amplified (by N)” version of x (n). Problem P 5. 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 ).

5*(x + conj(x(mod(-n.N) y = Columns 1 through 7 1. . 10.N))/N. (c) M ATLAB verification: % (c) Matlab Verification n = 0:19.9*exp(j*pi/3)).0000 Columns 8 through 12 6.5. (c) M ATLAB verification: x = [1.0000 3.6.0000 4.2.0000 3.0000 2.10.ˆn. xoc = 0. the circular folding of the sequence is evident. N = length(x).0000 2. where X˜ (k) = DFT [x (( n))N ] 2 1  = fX (k) + X (k)g = Re [X (k)] = Re [X (( k))N ] 2 similarly.1]. N = length(x). x = 1 2 3 4 5 6 6 5 y = circfold(x. xoc] = circevod(x).5*(x .conj(x(mod(-n.4. we can show that DFT [xoc (n)] = j Im [X (k)] = j Im [X (( k))N ] (b) The modified circevod function: function [xec.N)+1))).N). 1  [x (n) + x (( n))N ] 2 1 xoc (n) .5. Circular even-odd decomposition of a complex sequence. we obtain DFT [xec (n)] = = 1 fDFT [x (n)] + DFT [x (( n))N ]g 2 1 X (k) + X˜  (( k))N .3.4.3.0000 1. x = (0. [xec. xec = 0. Problem P 5.2.N) % x2(n) = x1((-n) mod N) % x2 = real(dft(dft(x1.N) % Circular folding with respect to N % ---------------------------------% function x2 = circfold(x1.0000 4 3 5.0000 4. n = 0:(N-1). xec (n) .0000 2 1 6.0000 Clearly.58 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 (b) M ATLAB function for circular folding: function x2 = circfold(x1. xoc] = circevod(x) % Complex-valued signal decomposition into circular-even and circular-odd parts % ---------------------------------------------------------------------------% [xec.N)+1))).0000 5. xoc] = circecod(x) % N = length(x).6. [x (n) + x (( n))N ] 2 (a) Using the DFT properties of conjugation and circular folding.

axis([-0. axis([-0. M ATLAB script: clear. X = [0. suptitle(’Problem P 5.1250 . 0.conj(X(4:-1:2))] % Reconstruct the entire X(k) X = Columns 1 through 4 0.5.125-j*0.0]).-1.3).N).’off’. Hf_1 = figure(’Units’.5]). stem(n. Xec = dft(xec.20.5.1.5]).0. its DFT is conjugate symmetric. axis([-0.1).3000i 0 0. 0:125 + j0:3g: From this we can compute the 8-point sequence x (n). Xoc = dft(xoc.20.5].[0. stem(n.’NumberTitle’.1.0. title(’DFT[xoc(n)]’).9. title(’Imag{DFT[x(n)]}’). 0. ylabel(’Xec(k)’). ylabel(’Im{X(k)}’).8. Problem P 5.125-j*0. 0:5.11 Since x (n) is a real-valued sequence.10 Plots Real{DFT[x(n)]} Imag{DFT[x(n)]} 5 Im{X(k)} Re{X(k)} 6 4 2 0 0 0 5 10 15 −5 20 0 5 DFT[xec(n)] 10 15 20 15 20 DFT[xoc(n)] 5 4 Xoc(k) Xec(k) 6 2 0 0 0 5 10 k 15 20 −5 0 5 10 k Figure 5.0. subplot(2.2500 0.5.2.2. The plots are shown in Figure 5.imag(X)).7]).5. 0:125 j0:3.8].1250 . subplot(2.0.25. subplot(2. axis([-0.0600i Columns 5 through 8 .2). ylabel(’Re{X(k)}’).-5.’position’.10’).10 Plots’).N).3.20.real(X)). stem(n.N). xlabel(’k’).0.0. Problem P 5. N = 8.[0.5. set(Hf_1.0.imag(Xoc)).06.5. title(’Real{DFT[x(n)]}’). stem(n.2.5.’P5.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 59 X = dft(x.0.2.7]). close all. X = [X.5. subplot(2.-5. Thus X (k) = f0:25.0.4). 0:125 j0:06.9: Plots in Problem P5.10 11.real(Xec)).’color’.20.’normalized’.0.’Name’. 0:125 + j0:06. xlabel(’k’). ylabel(’Xoc(k)’).-1. title(’DFT[xec(n)]’).

3000 + 0.0000i -0.0000i 0.0324 0.0324 Column 8 -0.5000 + 0.0.0600 .N).1250 + 0.0000i -0.2500 -0.1250 + 0.*dft([x.0.0000i 0.0.0176 .3000 .0000 Columns 5 through 8 0.0000 Columns 5 through 8 0.5000 0.1250 .0949 0.0600 + 0.0600i x = real(idft(X.0.0.1250i .1250i mk be the 10-point DFT of x n .1538 0. Hence using properties of the DFT X1 (k) = DFT [x ((2 n))8 ] = W8 2k X m 8 (( k))8 : M ATLAB script: % (a) x1(n) = x((2-n))_8. X2 = (WN.1368i . k = 0:N-1. X12 = dft(x1.0.0000 difference = max(abs(X1-X12)) difference = 4.0000i -0.1250 .0000 X1 = (WN. WN = exp(-j*2*pi/N).0600i .0.m.1250i + 0.2500 + 0.0000i 0.0. x1 = cirshftt(x1.1250 + 0.1250i 0.1250i 0.60 S OLUTIONS M ANUAL FOR DSP 0.5000 + 0.3000i 0.0000i 0. m = -5.0487i Columns 5 through 8 -0. WN = exp(-j*2*pi/N).0600 .2916 + 0.1250i 0. k = 0:N-1.2500 + 0.0600 + 0.5000 + 0.N) X12 = Columns 1 through 4 0.0000i 0.N).1250 + 0.0863 .3000i 0. shifted to the left by 5 samples. X1 = circfold(X.*X1 X1 = Columns 1 through 4 0.0312 -0.N) X2 = Columns 1 through 4 0.0000i -0.ˆ(m*k)).1250i + 0.0000i 0.2500 + 0. It is obtained by first circular folding and then circular shifting by 2 of x (n).0000 Columns 5 through 8 0.0600i 0.3000i + 0. M ATLAB script: % (b) x2(n) = x((n+5))_{10} N = 10.0000i 0.3000 .3000 + 0.7692e-016 (b) Let X by circ shifting by 2 .0.2848i 0.0000 % Matlab verification x1 = circfold(x. Then 10 ( ) ( ) 5k DFT [x ((n + 5))10 ] = W10 X mk 10 ( ) Note that x ((n + 5))10 is 10-point circularly shifted sequence of x (n).0000i 0.N) X1 = Columns 1 through 4 0. m = 2.0.1250i 0.0.N)) x = Columns 1 through 7 0.0337 (a) Consider x1 (n) = x ((2 n))8 = x (( [n 2]))8 .0.ˆ(m*k)).1562 0.0949 USING M ATLAB A PRIL 98 0 0. Circ folding followed N = 8.0].

0.1250 .5103e-017 (d) Let X mk be the 10-point DFT of x n .1250 .3.0949 0.0176 .0000i Columns 9 through 10 0.0487i -0.0863 + 0. Then 10 ( ) ( )  m DFT x (n) 8 x (( n))8  = X (k) X (( k))8 Note that x (( n))8 and X (( k))8 are the 8-point circular foldings of their respective sequences.0324 0.0.1562 0.0176 + 0.N)+1).25.0108 + 0.5000 0.0.5].0108 . X3 = circonvf(X.0.0487i -0.A PRIL 98 S OLUTIONS M ANUAL FOR DSP 0.0047i -0.2848i Columns 5 through 8 0.1368i (c) Consider x3 (n) = x2 (n) = x (n) x (n).2916 .0600i 0 0.N) X22 = Columns 1 through 4 0.1368i 0.2848i difference = max(abs(X2-X22)) difference = 8. Hence the DFT of x3 (n) is given by X3 (k) = m 1 X (k) N X (k) . N = 8. M ATLAB script: clear. close all.0863 + 0. N = 8.0.X. X32 = dft(x3.125-j*0. k = 0:N-1.2916 + 0.m.0. n = k.N)/N.0108 + 0.0949 % % (d) x4(n) = x(n)(8)x((-n))_8 X0 = X(mod(-k.2500 0.2916 .0337 Column 8 -0.1250 + 0.0047i -0.0108 .N)) x = Columns 1 through 7 0.N).1368i 0.0487i -0.2500 -0. X = [0.0312 -0.0.0.2848i % Matlab verification x2 = cirshftt(x.*x. % Matlab verification x3 = x. X = [X.0.N).0600i Columns 5 through 8 0.3000i x = real(idft(X.5000 .06.2523e-016 USING M ATLAB 61 0. % DFT of x((-n))_8 .conj(X(4:-1:2))] % Reconstruct the entire X(k) X = Columns 1 through 4 0.0176 + 0.0047i -0.0.1250 + 0. N N = 8: M ATLAB script: % (c) x3(n) = x(n)*x(n).0.5000 + 0.0047i -0. difference = max(abs(X3-X32)) difference = 4.1538 0.0324 0.0. X22 = dft(x2.3000i 0 0.0863 .0.0000i Columns 9 through 10 0.125-j*0.

X2 = X2/j. jXoc .62 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 X4 = X .2500 0.N-N2)]. xR (n) and xI (n) are real sequences Then xR (n) = jxI (n) = (a) Consider XR (k) def = = 1 fx (n) + x (n)g .12 (Two real DFTs using one complex DFT) x (n) = xR (n) + jxI (n) . x1 = [x1 zeros(1. x = x1 + j*x2. x2 = [x2 zeros(1.* X0 % DFT of x(n) (8) x((-n))_8 X4 = Columns 1 through 7 0.N).1056 % Verification x4 = circonvt(x.x2.0625 0. X = dft(x. [X1. X44 = dft(x4.N) % DFTs of two real sequences % [X1.x(mod(-n.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).N).1056 0 0. ) XI = Xjoc = (b) M ATLAB function real2dft: function [X1.N-N1)].X2] = real2dft(x1.X2] = real2dft(x1.x2. Problem P 5. N2 = length(x2). 2 1 fx (n) x (n)g 2 and 1 DFT [xR (n)] = fDFT [x (n)] + DFT [x (n)]g 2 1 def f X (k) + X  (( k))N g = Xec 2 Similarly jXI (k) def = = 1 DFT [ jxI (n)] = fDFT [x (n)] DFT [x (n)]g 2 1 def f X (k) X  (( k))N g = Xoc 2 9 > = > .0192 0.N). difference = max(abs(X4-X44)) difference = 2.1330e-016 0 12.0192 Column 8 0. X2] = circevod(X).N)+1).

if Rm > Cm m = m’. Problem P 5.25*pi*n). xec = 0.m to implement circular shift is written using the frequency-domain property 4 y (n) = x ((n h m))N = IDFT X (k) WNmk i This routine will be used in the next problem to generate a circulant matrix and has the following features. n = 0:(N-1). close all. difference = max(abs(X1-X11)) difference = 1. If m is a vector then y (n) is a matrix. xoc] = circecod(x) % N = length(x).4914e-013 13.N)+1))).m.m. % make sure that m is a row vector .conj(x(mod(-n. each row of which is a circular shift in x (n) corresponding to entries in the vector m.N). function y = cirshftf(x. or matrix [Rm. n = 0:N-1. This can be obtained from the one given in the text by two simple changes.N)+1))). X21 = dft(x2. 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.5*(x .5*(x + conj(x(mod(-n. function [xec. (c) M ATLAB verification: clear. If m is a scaler then y (n) is circularly shifted sequence (or array).A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 63 We will also need the circevod function for complex sequences (see Problem P5.75*pi*n).N) % Circular shift of m samples wrt size N in sequence x: (freq domain) % ------------------------------------------------------------------% function y=cirshift(x. x2 = sin(0. vector. xoc] = circevod(x) % Complex signal decomposition into circular-even and circular-odd parts % ---------------------------------------------------------------------% [xec.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.N).x2. x1 = cos(0.X2] = real2dft(x1.N).10). [X1. N = 64.Cm] = size(m).13 Circular shifting: (a) The M ATLAB routine cirshftf.4918e-013 difference = max(abs(X2-X21)) difference = 1. X11 = dft(x1. xoc = 0.

1]. Problem P 5. y = cirshftf(x.6.0000 2. or matrix [Rx.0000 8. vector.0000 0.10.4. (b) M ATLAB verification: n = [0:1:10].0000 Columns 8 through 14 0.15) y = Columns 1 through 7 6.Cx] = size(x).N)))/N.0000 11. if Rx > Cx x = x’.2. k=[0:1:N-1].5. N = length(x).0000 14. X=dft(x. X=ones(Cm.0000 1.length(n))-n.1)*X. N 1 ) N 1 x (n) WNnk . x = 11*ones(1.14 Parseval’s relation for the DFT: N 1 ∑ jx (n)j 2 N 1 = n=0 = N 1 ( x (n) x (n) = n =0 n=0 ( ) N 1 1N 1 nk  X (k) x (n) WN = N k=0 n =0 ∑ ∑ ∑ ) 1N 1 X (k) WN nk x (n) N k∑ =0 ∑ 1N 1 X (k ) N k∑ =0 ( N 1 N 1 ∑ jx (n)j2 = N ∑ X (k) X  (k) = N ∑ jX (k)j2 n =0 1 k=0 M ATLAB verification: x = [1.0000 3. Y=(WN.0000 10. 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 x=[x zeros(1. WN=exp(-2*j*pi/N).*X. % power of x(n) in the time-domain power_x = sum(x.5. if Rm > 1 error(’*** m must be a vector ***’) % stop if m is a matrix end % Check whether x is scalar.N).3. % make sure that x is a row vector end [Rx.*conj(x)) 1 k=0 ∑ n=0 Therefore.64 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 end [Rm.6.3.0000 5.N-length(x))].Cx] = size(x).2. y=real(conj(dfs(conj(Y).0000 4.ˆ(m’ * k)).0000 9.4.0000 0.Cm] = size(m).0000 Column 15 7.0000 0.

*conj(X)) power_X = 182.x2. m x1 (n) = f1.N-length(x1))].N). x1 (n) 4 x2 (n) (a) Using the results from Example 5. 2. X1=fft(x1). Circular convolution using circulant matrix operation. X2=fft(x2). x2 (n) = f1.N) % %function y=circonvf(x1.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 65 power_x = 182 X = dft(x. 16. Such a matrix is called a circulant matrix.*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. . x3 (n) . 0 2 1 6 2 X2 = 6 4 3 4 4 1 2 3 3 4 1 2 3 2 3 7 7 4 5 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.15 M ATLAB function circonvf: function y = circonvf(x1. x2=[x2 zeros(1. 2. It is completely described by the first column or the row. Problem P 5. power_X = (1/N)*sum(X.N-length(x2))]. we can express the above signals as 2 3 1 6 2 7 7 x1 = 6 4 2 5.x2. The following M ATLAB function circulnt uses the mod function to generate a circulant matrix.0000 15.16. y=real(ifft(X1.13. 4g . 2g . Problem P 5. 3.

16: Circular convolution using Circulant matrix clear.1)].4].2. h = reshape(h.2.17.3.N) % % C : Circulant matrix % h : input sequence of length <= N % N : size of the circular buffer % Method: C = h((n-m) mod N). n : col vec. zeros(N-Mh. x1 = [1. [h. (b) Circular convolution: 2 1 6 2 x 3 = X2 x 1 = 6 4 3 4 4 1 2 3 3 4 1 2 % % % % % % reshape h into column vector zero-pad h establish size of C indices n and m (n-m) mod N in matrix form h((n-m) mod N) 32 3 2 2 1 6 2 7 6 3 7 76 7=6 4 54 2 5 4 1 0 3 15 12 7 7 9 5 14 M ATLAB script: % Chapter 5: Problem P5.Mh. n=m’.N) % % C : Circulant matrix % x : input sequence of length <= N % N : size of the circular buffer % Method: C = h((n-m) mod N).N) % Circulant matrix generation using vector data values % ---------------------------------------------------% function C = circulnt(h. h(nm+1).N)-ones(N. Mx = length(x).N). m : row vec Mh h C m nm C(:) = = = = = = length(h). zeros(N. Problem P 5.2. close all. x2 = [1.0].N).66 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 function C = circulnt(h. 0:N-1.1).N) X2 = 1 4 3 2 1 4 3 2 1 4 3 2 2 3 4 1 % (b) Circular Convolution x3 = X2*x1’. M ATLAB function circulnt: function C = circulnt(x. % length of x . mod((n*ones(1.1)*m).N) % Circulant matrix generation using vector data values % ---------------------------------------------------% function C = circulnt(h. x3 = x3’ x3 = 15 12 9 14 17. N = 4. % (a) Circulant matrix X2 = circulnt(x2.

N).1.0000 -1. m x 3 (n ) = x 1 (n ) N x 2 (n ) Circular convolutions using M ATLAB: clear. zeros(N.0000 4.0000 Columns 8 through 10 250. x2 (n) = (N n) RN (n) .0000 1.1. %(a) x1(n) = [1.0000 225.N) x3 = Columns 1 through 7 1.0000 Column 8 -1. close all. x1 = [1.N).1.0000 3.0000 2.0000 9.0000 210.1. N = 4. x3 = x3’ x3 = 15.2. x2 = (N-n).4142 2. circfold(x.4142 m x3 (n) = x1 (n) N x2 (n) Circular convolutions using M ATLAB: N = 10.0.2.0000 210.0000 % (b) Circular Convolution x3 = X2*x1’.m.0.0000 205. N = 8.0000 4. cirshift(x.*dft(x2. x2 = [1. zeros(N-Mx.0000 (d) Circular convolution: x1 (n) = nRN . 1. % (a) Circulant matrix X2 = circulnt(x2.0000 .0000 2.0000 12.N)) x3 = Columns 1 through 7 285.0000 250.0000 3.1)].x2.0000 2.16 (or Example 5.N) X2 = 1. 1.0.0000 1. n = 0:N-1.0000 18.N).13): clear.N).0000 14. x2 = cos(pi*n/4).0000 4.1]. x3 = real(idft(dft(x1. x2(n) = cos(pi*n/4). N = 8.0000 330.4142 -2. x1 = n. 0:N-1.0000 225. N = 10.0000 3. Problem P 5. close all. -2. % % % % % DSP USING M ATLAB 67 zero-pad x establish size of C indices n and m Circular folding Circular shifting M ATLAB verification on sequences in Problem 5.4142 1. x3 = circonvt(x1.0000 2.18 (a) Circular convolution: x1 (n) = f1. x1 = [1. 1g . n = [0:N-1].0000 3.A PRIL 98 S OLUTIONS M ANUAL x C m x C = = = = = FOR [x.0]. x2 (n) = cos (πn=4) RN (n) .0].0000 2.0000 4.N). N = 8.4].2.1.0000 1.0000 285.3.

19 (b) Error between Linear and Circular Convolutions: x1 (n) = cos (2πn=N ) R16 (n) .5000 -2.x2.4944 3.1951 0.1575 -3.4874 -3. x4 = [x4.5962 3.9424 -2.8701 1.3656 -2.68 S OLUTIONS M ANUAL FOR DSP USING M ATLAB A PRIL 98 19. x1 = cos(2*pi*n/N).2336 Columns 8 through 14 3. Problem P 5. N4 = length(x4).0607 -0. N = 32.x2).8891 Columns 22 through 28 -4.9424 -2.7678 2.1111 1.3334 -3.7678 2. x2 = sin(2*pi*n/N).4874 -3.3656 -2.5556 -0.9231 4. n = 0:15.9231 -3.N) x3 = Columns 1 through 7 0. 1g .4944 3.1913 0. x4 = Columns 1 through 7 0 0.6629 Columns 29 through 31 -1.9888 4.5000 4. x2 (n) = f1.0000 x4 = conv(x1. 0.5962 3.9231 -3.2336 Columns 8 through 14 3.5556 -0. N = 32.1573 -4. N = 32 M ATLAB script: % (b) x1(n) = cos(2*pi*n/N)*R16. 0g .0000 0.1951 0.5607 0.5740 1.x4(1:N)) e = Columns 1 through 12 0 0 0 0 0 0 0 0 0 0 0 0 Columns 13 through 24 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 32 0 0 0 0 0 0 0 0 x4(N+1:N4) ans = Columns 1 through 12 0 0 0 0 0 0 0 0 0 0 0 0 Columns 13 through 24 0 0 0 0 0 0 0 0 0 0 0 0 Columns 25 through 32 0 0 0 0 0 0 0 0 (e) Error between Linear and Circular Convolutions: x1 (n) = f1.5607 0.1111 1. zeros(1.5000 4.5740 1.8890 Columns 15 through 21 2.8891 Columns 22 through 28 -4.3334 -3.8701 1.0813 4. 1. x3 = circonvf(x1.3097 -1.1575 -3.8890 Columns 15 through 21 2.0000 -1.9231 4.1573 -4. 1.1913 e = round(x3 .33)].5000 -2.9039 5. M ATLAB script: N =5 . x2(n) = cos(2*pi*n/N)*R16.9888 4.3097 -1.0000 -1.0813 4.0607 -0.6629 Columns 29 through 32 -1. 1. x2 (n) = sin (2πn=N ) R16 (n) .9039 5.

the minimum length should be 4 + 4 1 = 7.-1}. (d) Since x1 (n) and x2 (n) are 4-point sequences. Problem P 5.0000 0.x2. N = 5 x1 = [1.2]. N = 5. N4 = length(x4).0}.x2) y_l = 2 -1 2 0 -2 1 -2 (c) The minimum value of N should be 7. x1 = [2.x2.21.0000 0. x2(n) = {1. 1. 1.-1. M ATLAB script: clear. close all.-1.0000 0.-1. 8.0. 1. m x1 (n) = f2. % (a) Circular Convolution for N = 4.7)) y_7 = 2 -1 2 0 -2 1 -2 y_8 = round(circonv(x1.8)) y_8 = 2 -1 2 0 -2 1 -2 0 (b) Linear convolution x1 (n)  x2 (n). x2 = [1. 1g (a) Circular convolution x1 (n) N x2 (n) for N = 4. x3 = circonvf(x1.1.x4(1:N) e = 1.A PRIL 98 S OLUTIONS M ANUAL FOR DSP USING M ATLAB 69 % (e) x1(n) = {1.7.x2.-1].1.-1.x2. x2 = [1.0000 -1.0000 0.0000 x4(N+1:N4) ans = 1 0 20.1.8 y_4 = round(circonv(x1.0].1.0000 0.0000 x4 = conv(x1. 7.-1.1. 1.N) x3 = 2.0000 0.0.0000 -1. . x2 (n) = f1.-1].4)) y_4 = 0 0 0 0 y_7 = round(circonv(x1. M ATLAB script: % (b) linear Convolution y_l = conv(x1.x2). x4 = 1 -1 0 0 -1 1 0 e = x3 . 2g .