0% found this document useful (0 votes)
86 views

DSP Matlab

The document defines and plots several discrete-time sequences: 1) x1(n) is defined as a summation and plotted from n=0 to 25. 2) x2(n) is defined using unit step functions, the Dirac delta function, and exponential terms, and plotted from n=-5 to 10. 3) x3(n) is defined using exponential and cosine terms and plotted from n=0 to 20. 4) x4(n) is defined as a noisy chirp signal, using cosine and random noise terms, and plotted from n=0 to 100. 5) x5(n) is a periodic sequence that is plotted for 5 periods from n=-
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

DSP Matlab

The document defines and plots several discrete-time sequences: 1) x1(n) is defined as a summation and plotted from n=0 to 25. 2) x2(n) is defined using unit step functions, the Dirac delta function, and exponential terms, and plotted from n=-5 to 10. 3) x3(n) is defined using exponential and cosine terms and plotted from n=0 to 20. 4) x4(n) is defined as a noisy chirp signal, using cosine and random noise terms, and plotted from n=0 to 100. 5) x5(n) is a periodic sequence that is plotted for 5 periods from n=-
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 46

Discrete-Time Signals and Systems

1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];

Page 1

Chapter 2

Discrete-Time Signals and Systems


1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));

end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5
10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

n
x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2

+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between


[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency
(or a noisy chirp signal).
(e) x5 (n) =
...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));
subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 1

Chapter 2

Discrete-Time Signals and Systems


1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];

set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5
10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

n
x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2
+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between
[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency
(or a noisy chirp signal).
(e) x5 (n) =
...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));

subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 3
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
5
0
10
20
30
40
50
60
70
80
90
100
10
5
0
5
10

n
x4(n)
Sequence x4(n)

Figure 2.2: Plot of the sequence x4 (n) in Problem P2.1d.


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x5(n) is shown in Figure 2.3.
5
4
3
2
1
0
1
2
3
4
5
6
7
8
9
10
0
5
10
15
20
25

n
x1(n)
Sequence x2(n)

Problem P2.1 : Sequences


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

n
x5(n)
Sequence x5(n)

Figure 2.3: Problem P2.1 Sequence Plots


2. Problem P2.2: The sequence x(n) =

f1, 2,4,6, 5,8,10gis given.

(a) x1(n) = 3x(n+2) +x(n 4) 2x(n).


clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2ab);

Page 1

Chapter 2

Discrete-Time Signals and Systems


1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5
10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4

5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

n
x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2
+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between
[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency
(or a noisy chirp signal).
(e) x5 (n) =
...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));
subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 3
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
5
0
10
20
30
40
50
60
70
80
90
100
10
5
0
5
10

n
x4(n)
Sequence x4(n)

Figure 2.2: Plot of the sequence x4 (n) in Problem P2.1d.


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)

The plots of x5(n) is shown in Figure 2.3.


5
4
3
2
1
0
1
2
3
4
5
6
7
8
9
10
0
5
10
15
20
25

n
x1(n)
Sequence x2(n)

Problem P2.1 : Sequences


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

n
x5(n)
Sequence x5(n)

Figure 2.3: Problem P2.1 Sequence Plots


2. Problem P2.2: The sequence x(n) =

f1, 2,4,6, 5,8,10gis given.

(a) x1(n) = 3x(n+2) +x(n 4) 2x(n).


clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2ab);

Page 4
6
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (a) x1(n) = 3*x(n+2) + x(n-4) - 2*x(n)
[x11,n11] = sigshift(3*x,n,-2);
% shift by -2 and scale by 3
[x12,n12] = sigshift(x,n,4);
% shift x(n) by 4
[x13,n13] = sigadd(x11,n11,x12,n12);
% add two sequences at time
[x1,n1] = sigadd(x13,n13,2*x,n);
% add two sequences
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):1:n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x1(n) is shown in Figure 2.4.
(b) x2(n) = 5x(5+n) +4x(n+4)+3x(n).
% (b) x2(n) = 5*x(5+n) + 4*x(n+4) +3*x(n)

[x21,n21] = sigshift(5*x,n,-5);
[x22,n22] = sigshift(4*x,n,-4);
[x23,n23] = sigadd(x21,n21,x22,n22);
[x2,n2] = sigadd(x23,n23,3*x,n);
subplot(2,1,2); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-0.5,max(x2)+0.5]);
xlabel(n); ylabel(x2(n)); title(Sequence x2(n));
ntick = [n2(1):1:n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)

Page 1

Chapter 2

Discrete-Time Signals and Systems


1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4

SOLUTIONS MANUAL FOR DSP USING MATLAB


APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5
10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

n
x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2
+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between
[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency
(or a noisy chirp signal).
(e) x5 (n) =
...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));
subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 3
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
5
0
10
20
30
40
50

60
70
80
90
100
10
5
0
5
10

n
x4(n)
Sequence x4(n)

Figure 2.2: Plot of the sequence x4 (n) in Problem P2.1d.


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x5(n) is shown in Figure 2.3.
5
4
3
2
1
0
1
2
3
4
5
6
7
8
9
10
0
5
10
15
20
25

n
x1(n)
Sequence x2(n)

Problem P2.1 : Sequences


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

n
x5(n)
Sequence x5(n)

Figure 2.3: Problem P2.1 Sequence Plots


2. Problem P2.2: The sequence x(n) =

f1, 2,4,6, 5,8,10gis given.

(a) x1(n) = 3x(n+2) +x(n 4) 2x(n).


clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2ab);

Page 4
6
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (a) x1(n) = 3*x(n+2) + x(n-4) - 2*x(n)
[x11,n11] = sigshift(3*x,n,-2);
% shift by -2 and scale by 3
[x12,n12] = sigshift(x,n,4);

% shift x(n) by 4
[x13,n13] = sigadd(x11,n11,x12,n12);
% add two sequences at time
[x1,n1] = sigadd(x13,n13,2*x,n);
% add two sequences
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):1:n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x1(n) is shown in Figure 2.4.
(b) x2(n) = 5x(5+n) +4x(n+4)+3x(n).
% (b) x2(n) = 5*x(5+n) + 4*x(n+4) +3*x(n)
[x21,n21] = sigshift(5*x,n,-5);
[x22,n22] = sigshift(4*x,n,-4);
[x23,n23] = sigadd(x21,n21,x22,n22);
[x2,n2] = sigadd(x23,n23,3*x,n);
subplot(2,1,2); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-0.5,max(x2)+0.5]);
xlabel(n); ylabel(x2(n)); title(Sequence x2(n));
ntick = [n2(1):1:n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x2(n) is shown in Figure 2.4.
6
5
4
3
2
1
0
1
2
3
4
5
6
0
10
20
30

n
x1(n)
Sequence x1(n)

Homework1 : Problem 2
9
8
7
6
5
4
3
2
1
0
1
2
0
20
40
60

n
x2(n)
Sequence x2(n)

Figure 2.4: Problem P2.2 Sequence Plots


(c) x3(n) = x(n+4)x(n 1) +x(2 n)x(n).

Page 5
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
7
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2cd);
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%

% (c) x3(n) = x(n+4)*x(n-1) + x(2-n)*x(n)


[x31,n31] = sigshift(x,n,-4);
% shift x(n) by -4
[x32,n32] = sigshift(x,n,1);
% shift x(n) by 1
[x33,n33] = sigmult(x31,n31,x32,n32); % multiply two sequences
[x34,n34] = sigfold(x,n);
% fold x(n)
[x34,n34] = sigshift(x34,n34,2);
% shift x(-n) ny 2
[x34,n34] = sigmult(x34,n34,x,n);
% shift x(-n) ny 2
[x3,n3] = sigadd(x33,n33,x34,n34);
% add two sequences
subplot(2,1,1); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,min(x3)-2,max(x3)+2]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):1:n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plots of x3(n) is shown in Figure 2.5.
(d) x4(n) = 2e0:5nx(n) +cos(0.1n)x(n+2), 10 n 10.
% (d) x4(n) = 2*exp(0.5*n)*x(n)+cos(0.1*pi*n)*x(n+2); -10 <= n <= 10
n4 = [-10:10]; x41 = 2*exp(0.5*n4); x412 = cos(0.1*pi*n4);
[x42,n42] = sigmult(x41,n4,x,n);
[x43,n43] = sigshift(x,n,-2);
[x44,n44] = sigmult(x412,n4,x43,n43);
[x4,n4] = sigadd(x42,n42,x44,n44);
subplot(2,1,2); stem(n4,x4);
axis([min(n4)-1,max(n4)+1,min(x4)-0.5,max(x4)+0.5]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):1:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x4(n) is shown in Figure 2.5.
(e) x5 (n) = 5

k) where x(n) = 1, 2,4,6, 5,8,10 .


clear; close all;
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
% (e) x5(n) = sum_{k=1}{5}n*x(n-k);
[x51,n51] = sigshift(x,n,1); [x52,n52] = sigshift(x,n,2);
[x5,n5] = sigadd(x51,n51,x52,n52);
[x53,n53] = sigshift(x,n,3); [x5,n5] = sigadd(x5,n5,x53,n53);
[x54,n54] = sigshift(x,n,4); [x5,n5] = sigadd(x5,n5,x54,n54);
[x55,n55] = sigshift(x,n,5); [x5,n5] = sigadd(x5,n5,x55,n55);
[x5,n5] = sigmult(x5,n5,n5,n5);
subplot(2,1,2); stem(n5,x5); axis([min(n5)-1,max(n5)+1,min(x5)-2,max(x5)+2]);
xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):1:n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x5(n) is shown in Figure 2.6.
3. Problem P2.3: A sequence x(n) is periodic if x(n+N) = x(n) for all n. Consider a complex exponential sequence
ej0n = ej2f0n.
k=1 nx(n

Page 1

Chapter 2

Discrete-Time Signals and Systems

1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5
10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2
+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between
[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency
(or a noisy chirp signal).
(e) x5 (n) =
...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));
subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 3
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
5
0
10
20
30
40
50
60
70
80
90
100
10
5
0
5
10

n
x4(n)
Sequence x4(n)

Figure 2.2: Plot of the sequence x4 (n) in Problem P2.1d.


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x5(n) is shown in Figure 2.3.
5
4
3
2
1
0
1
2
3
4

5
6
7
8
9
10
0
5
10
15
20
25

n
x1(n)
Sequence x2(n)

Problem P2.1 : Sequences


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

n
x5(n)
Sequence x5(n)

Figure 2.3: Problem P2.1 Sequence Plots


2. Problem P2.2: The sequence x(n) =

f1, 2,4,6, 5,8,10gis given.

(a) x1(n) = 3x(n+2) +x(n 4) 2x(n).


clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2ab);

Page 4
6
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (a) x1(n) = 3*x(n+2) + x(n-4) - 2*x(n)
[x11,n11] = sigshift(3*x,n,-2);
% shift by -2 and scale by 3
[x12,n12] = sigshift(x,n,4);
% shift x(n) by 4
[x13,n13] = sigadd(x11,n11,x12,n12);
% add two sequences at time
[x1,n1] = sigadd(x13,n13,2*x,n);
% add two sequences
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):1:n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x1(n) is shown in Figure 2.4.
(b) x2(n) = 5x(5+n) +4x(n+4)+3x(n).
% (b) x2(n) = 5*x(5+n) + 4*x(n+4) +3*x(n)
[x21,n21] = sigshift(5*x,n,-5);
[x22,n22] = sigshift(4*x,n,-4);
[x23,n23] = sigadd(x21,n21,x22,n22);
[x2,n2] = sigadd(x23,n23,3*x,n);
subplot(2,1,2); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-0.5,max(x2)+0.5]);
xlabel(n); ylabel(x2(n)); title(Sequence x2(n));

ntick = [n2(1):1:n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x2(n) is shown in Figure 2.4.
Figure 2.4: Problem P2.2 Sequence Plots
(c) x3(n) = x(n+4)x(n 1) +x(2 n)x(n).

Page 5
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
7
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2cd);
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (c) x3(n) = x(n+4)*x(n-1) + x(2-n)*x(n)
[x31,n31] = sigshift(x,n,-4);
% shift x(n) by -4
[x32,n32] = sigshift(x,n,1);
% shift x(n) by 1
[x33,n33] = sigmult(x31,n31,x32,n32); % multiply two sequences
[x34,n34] = sigfold(x,n);
% fold x(n)
[x34,n34] = sigshift(x34,n34,2);
% shift x(-n) ny 2
[x34,n34] = sigmult(x34,n34,x,n);
% shift x(-n) ny 2
[x3,n3] = sigadd(x33,n33,x34,n34);
% add two sequences
subplot(2,1,1); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,min(x3)-2,max(x3)+2]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):1:n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plots of x3(n) is shown in Figure 2.5.
(d) x4(n) = 2e0:5nx(n) +cos(0.1n)x(n+2), 10 n 10.
% (d) x4(n) = 2*exp(0.5*n)*x(n)+cos(0.1*pi*n)*x(n+2); -10 <= n <= 10
n4 = [-10:10]; x41 = 2*exp(0.5*n4); x412 = cos(0.1*pi*n4);
[x42,n42] = sigmult(x41,n4,x,n);
[x43,n43] = sigshift(x,n,-2);
[x44,n44] = sigmult(x412,n4,x43,n43);
[x4,n4] = sigadd(x42,n42,x44,n44);
subplot(2,1,2); stem(n4,x4);
axis([min(n4)-1,max(n4)+1,min(x4)-0.5,max(x4)+0.5]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):1:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x4(n) is shown in Figure 2.5.
(e) x5 (n) = 5

k) where x(n) = 1, 2,4,6, 5,8,10 .


clear; close all;
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
% (e) x5(n) = sum_{k=1}{5}n*x(n-k);
[x51,n51] = sigshift(x,n,1); [x52,n52] = sigshift(x,n,2);
[x5,n5] = sigadd(x51,n51,x52,n52);
[x53,n53] = sigshift(x,n,3); [x5,n5] = sigadd(x5,n5,x53,n53);
[x54,n54] = sigshift(x,n,4); [x5,n5] = sigadd(x5,n5,x54,n54);
[x55,n55] = sigshift(x,n,5); [x5,n5] = sigadd(x5,n5,x55,n55);
[x5,n5] = sigmult(x5,n5,n5,n5);
k=1 nx(n

subplot(2,1,2); stem(n5,x5); axis([min(n5)-1,max(n5)+1,min(x5)-2,max(x5)+2]);


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):1:n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x5(n) is shown in Figure 2.6.
3. Problem P2.3: A sequence x(n) is periodic if x(n+N) = x(n) for all n. Consider a complex exponential sequence
ej0n = ej2f0n.

Page 6
8
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
Problem P2.2 : Sequences
Figure 2.5: Problem P2.2 Sequence Plots
(a) Analytical proof: The above sequence is periodic if
ej2f0 n+N
= ej2f0n
or
ej2f0N = 1 f0N = K (an integer)
which proves the result.
(b) x1 (n) = cos(0.3n), 20 n 20.
% (b) x1(n) = cos(0.3*pi*n)
x1 = cos(0.3*pi*n);
subplot(2,1,1); stem(n,x1);
axis([min(n)-1,max(n)+1,-1.1,1.1]);

Page 1

Chapter 2

Discrete-Time Signals and Systems


1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)

x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5
10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

n
x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2
+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between
[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency
(or a noisy chirp signal).
(e) x5 (n) =

...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));
subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 3
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
5
0
10
20
30
40
50
60
70
80
90
100
10
5
0
5
10

n
x4(n)
Sequence x4(n)

Figure 2.2: Plot of the sequence x4 (n) in Problem P2.1d.


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x5(n) is shown in Figure 2.3.
5
4
3
2
1
0
1
2
3
4
5
6
7
8
9
10
0
5
10
15
20
25

n
x1(n)
Sequence x2(n)

Problem P2.1 : Sequences


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

n
x5(n)
Sequence x5(n)

Figure 2.3: Problem P2.1 Sequence Plots

2. Problem P2.2: The sequence x(n) =

f1, 2,4,6, 5,8,10gis given.

(a) x1(n) = 3x(n+2) +x(n 4) 2x(n).


clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2ab);

Page 4
6
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (a) x1(n) = 3*x(n+2) + x(n-4) - 2*x(n)
[x11,n11] = sigshift(3*x,n,-2);
% shift by -2 and scale by 3
[x12,n12] = sigshift(x,n,4);
% shift x(n) by 4
[x13,n13] = sigadd(x11,n11,x12,n12);
% add two sequences at time
[x1,n1] = sigadd(x13,n13,2*x,n);
% add two sequences
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):1:n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x1(n) is shown in Figure 2.4.
(b) x2(n) = 5x(5+n) +4x(n+4)+3x(n).
% (b) x2(n) = 5*x(5+n) + 4*x(n+4) +3*x(n)
[x21,n21] = sigshift(5*x,n,-5);
[x22,n22] = sigshift(4*x,n,-4);
[x23,n23] = sigadd(x21,n21,x22,n22);
[x2,n2] = sigadd(x23,n23,3*x,n);
subplot(2,1,2); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-0.5,max(x2)+0.5]);
xlabel(n); ylabel(x2(n)); title(Sequence x2(n));
ntick = [n2(1):1:n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x2(n) is shown in Figure 2.4.
6
5
4
3
2
1
0
1
2
3
4
5
6
0
10
20
30

n
x1(n)
Sequence x1(n)

Homework1 : Problem 2
9
8
7
6
5
4
3
2
1
0
1
2

0
20
40
60

n
x2(n)
Sequence x2(n)

Figure 2.4: Problem P2.2 Sequence Plots


(c) x3(n) = x(n+4)x(n 1) +x(2 n)x(n).

Page 5
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
7
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2cd);
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (c) x3(n) = x(n+4)*x(n-1) + x(2-n)*x(n)
[x31,n31] = sigshift(x,n,-4);
% shift x(n) by -4
[x32,n32] = sigshift(x,n,1);
% shift x(n) by 1
[x33,n33] = sigmult(x31,n31,x32,n32); % multiply two sequences
[x34,n34] = sigfold(x,n);
% fold x(n)
[x34,n34] = sigshift(x34,n34,2);
% shift x(-n) ny 2
[x34,n34] = sigmult(x34,n34,x,n);
% shift x(-n) ny 2
[x3,n3] = sigadd(x33,n33,x34,n34);
% add two sequences
subplot(2,1,1); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,min(x3)-2,max(x3)+2]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):1:n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plots of x3(n) is shown in Figure 2.5.
(d) x4(n) = 2e0:5nx(n) +cos(0.1n)x(n+2), 10 n 10.
% (d) x4(n) = 2*exp(0.5*n)*x(n)+cos(0.1*pi*n)*x(n+2); -10 <= n <= 10
n4 = [-10:10]; x41 = 2*exp(0.5*n4); x412 = cos(0.1*pi*n4);
[x42,n42] = sigmult(x41,n4,x,n);
[x43,n43] = sigshift(x,n,-2);
[x44,n44] = sigmult(x412,n4,x43,n43);
[x4,n4] = sigadd(x42,n42,x44,n44);
subplot(2,1,2); stem(n4,x4);
axis([min(n4)-1,max(n4)+1,min(x4)-0.5,max(x4)+0.5]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):1:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x4(n) is shown in Figure 2.5.
(e) x5 (n) = 5

k) where x(n) = 1, 2,4,6, 5,8,10 .


clear; close all;
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
% (e) x5(n) = sum_{k=1}{5}n*x(n-k);
[x51,n51] = sigshift(x,n,1); [x52,n52] = sigshift(x,n,2);
[x5,n5] = sigadd(x51,n51,x52,n52);
[x53,n53] = sigshift(x,n,3); [x5,n5] = sigadd(x5,n5,x53,n53);
[x54,n54] = sigshift(x,n,4); [x5,n5] = sigadd(x5,n5,x54,n54);
[x55,n55] = sigshift(x,n,5); [x5,n5] = sigadd(x5,n5,x55,n55);
k=1 nx(n

[x5,n5] = sigmult(x5,n5,n5,n5);
subplot(2,1,2); stem(n5,x5); axis([min(n5)-1,max(n5)+1,min(x5)-2,max(x5)+2]);
xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):1:n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x5(n) is shown in Figure 2.6.
3. Problem P2.3: A sequence x(n) is periodic if x(n+N) = x(n) for all n. Consider a complex exponential sequence
ej0n = ej2f0n.

Page 6
8
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
8
7
6
5
4
3
2
1
0
1
2
3
4
5
6
40
20
0
20
40
60

n
x3(n)
Sequence x3(n)

Problem P2.2 : Sequences


10 9 8 7 6 5 4 3 2 1
0
1
2
3
4
5
6
7
8
9
10
0
10
20
30
40
50

n
x4(n)
Sequence x4(n)

Figure 2.5: Problem P2.2 Sequence Plots


(a) Analytical proof: The above sequence is periodic if
ej2f0 n+N
= ej2f0n
or
ej2f0N = 1 f0N = K (an integer)
which proves the result.
(b) x1 (n) = cos(0.3n), 20 n 20.
% (b) x1(n) = cos(0.3*pi*n)
x1 = cos(0.3*pi*n);
subplot(2,1,1); stem(n,x1);
axis([min(n)-1,max(n)+1,-1.1,1.1]);
3
2
1
0
1
2
3
4
5
6

7
0
20
40
60
80
100

n
x5(n)
Sequence x5(n)

Figure 2.6: Plot of the sequence x5 (n) in Problem P2.5e.

Page 7
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
9
ylabel(x1(n)); title(Sequence cos(0.3*pi*n));
ntick = [n(1):5:n(length(n))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
Since f0 = 0.3/2 = 3/20 the sequence is periodic. From the plot in Figure 2.7 we see that in one period of 20
samples x1 (n) exhibits three cycles. This is true whenever K and N are relatively prime.
(c) x2 (n) = cos(0.3n), 20 n 20.
% (b) x2(n) = cos(0.3*n)
x2 = cos(0.3*n);
subplot(2,1,2); stem(n,x2);
axis([min(n)-1,max(n)+1,-1.1,1.1]);
ylabel(x2(n)); title(Sequence cos(0.3*n));
ntick = [n(1):5:n(length(n))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
In this case f0 is not a rational number and hence the sequence x2 (n) is not periodic. This can be clearly seen from
the plot of x2 (n) in Figure 2.7.

Page 1

Chapter 2

Discrete-Time Signals and Systems


1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);

%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5
10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

n
x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2
+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between
[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency

(or a noisy chirp signal).


(e) x5 (n) =
...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));
subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 3
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
5
0
10
20
30
40
50
60
70
80
90
100
10
5
0
5
10

n
x4(n)
Sequence x4(n)

Figure 2.2: Plot of the sequence x4 (n) in Problem P2.1d.


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x5(n) is shown in Figure 2.3.
5
4
3
2
1
0
1
2
3
4
5
6
7
8
9
10
0
5
10
15
20
25

n
x1(n)
Sequence x2(n)

Problem P2.1 : Sequences


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

n
x5(n)

Sequence x5(n)

Figure 2.3: Problem P2.1 Sequence Plots


2. Problem P2.2: The sequence x(n) =

f1, 2,4,6, 5,8,10gis given.

(a) x1(n) = 3x(n+2) +x(n 4) 2x(n).


clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2ab);

Page 4
6
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (a) x1(n) = 3*x(n+2) + x(n-4) - 2*x(n)
[x11,n11] = sigshift(3*x,n,-2);
% shift by -2 and scale by 3
[x12,n12] = sigshift(x,n,4);
% shift x(n) by 4
[x13,n13] = sigadd(x11,n11,x12,n12);
% add two sequences at time
[x1,n1] = sigadd(x13,n13,2*x,n);
% add two sequences
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):1:n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x1(n) is shown in Figure 2.4.
(b) x2(n) = 5x(5+n) +4x(n+4)+3x(n).
% (b) x2(n) = 5*x(5+n) + 4*x(n+4) +3*x(n)
[x21,n21] = sigshift(5*x,n,-5);
[x22,n22] = sigshift(4*x,n,-4);
[x23,n23] = sigadd(x21,n21,x22,n22);
[x2,n2] = sigadd(x23,n23,3*x,n);
subplot(2,1,2); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-0.5,max(x2)+0.5]);
xlabel(n); ylabel(x2(n)); title(Sequence x2(n));
ntick = [n2(1):1:n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x2(n) is shown in Figure 2.4.
6
5
4
3
2
1
0
1
2
3
4
5
6
0
10
20
30

n
x1(n)
Sequence x1(n)

Homework1 : Problem 2
9
8
7
6
5
4
3
2
1

0
1
2
0
20
40
60

n
x2(n)
Sequence x2(n)

Figure 2.4: Problem P2.2 Sequence Plots


(c) x3(n) = x(n+4)x(n 1) +x(2 n)x(n).

Page 5
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
7
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2cd);
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (c) x3(n) = x(n+4)*x(n-1) + x(2-n)*x(n)
[x31,n31] = sigshift(x,n,-4);
% shift x(n) by -4
[x32,n32] = sigshift(x,n,1);
% shift x(n) by 1
[x33,n33] = sigmult(x31,n31,x32,n32); % multiply two sequences
[x34,n34] = sigfold(x,n);
% fold x(n)
[x34,n34] = sigshift(x34,n34,2);
% shift x(-n) ny 2
[x34,n34] = sigmult(x34,n34,x,n);
% shift x(-n) ny 2
[x3,n3] = sigadd(x33,n33,x34,n34);
% add two sequences
subplot(2,1,1); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,min(x3)-2,max(x3)+2]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):1:n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plots of x3(n) is shown in Figure 2.5.
(d) x4(n) = 2e0:5nx(n) +cos(0.1n)x(n+2), 10 n 10.
% (d) x4(n) = 2*exp(0.5*n)*x(n)+cos(0.1*pi*n)*x(n+2); -10 <= n <= 10
n4 = [-10:10]; x41 = 2*exp(0.5*n4); x412 = cos(0.1*pi*n4);
[x42,n42] = sigmult(x41,n4,x,n);
[x43,n43] = sigshift(x,n,-2);
[x44,n44] = sigmult(x412,n4,x43,n43);
[x4,n4] = sigadd(x42,n42,x44,n44);
subplot(2,1,2); stem(n4,x4);
axis([min(n4)-1,max(n4)+1,min(x4)-0.5,max(x4)+0.5]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):1:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x4(n) is shown in Figure 2.5.
(e) x5 (n) = 5

k) where x(n) = 1, 2,4,6, 5,8,10 .


clear; close all;
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
% (e) x5(n) = sum_{k=1}{5}n*x(n-k);
[x51,n51] = sigshift(x,n,1); [x52,n52] = sigshift(x,n,2);
[x5,n5] = sigadd(x51,n51,x52,n52);
[x53,n53] = sigshift(x,n,3); [x5,n5] = sigadd(x5,n5,x53,n53);
k=1 nx(n

[x54,n54] = sigshift(x,n,4); [x5,n5] = sigadd(x5,n5,x54,n54);


[x55,n55] = sigshift(x,n,5); [x5,n5] = sigadd(x5,n5,x55,n55);
[x5,n5] = sigmult(x5,n5,n5,n5);
subplot(2,1,2); stem(n5,x5); axis([min(n5)-1,max(n5)+1,min(x5)-2,max(x5)+2]);
xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):1:n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x5(n) is shown in Figure 2.6.
3. Problem P2.3: A sequence x(n) is periodic if x(n+N) = x(n) for all n. Consider a complex exponential sequence
ej0n = ej2f0n.

Page 6
8
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
8
7
6
5
4
3
2
1
0
1
2
3
4
5
6
40
20
0
20
40
60

n
x3(n)
Sequence x3(n)

Problem P2.2 : Sequences


Figure 2.5: Problem P2.2 Sequence Plots
(a) Analytical proof: The above sequence is periodic if
ej2f0 n+N
= ej2f0n
or
ej2f0N = 1 f0N = K (an integer)
which proves the result.
(b) x1 (n) = cos(0.3n), 20 n 20.
% (b) x1(n) = cos(0.3*pi*n)
x1 = cos(0.3*pi*n);
subplot(2,1,1); stem(n,x1);
axis([min(n)-1,max(n)+1,-1.1,1.1]);
Figure 2.6: Plot of the sequence x5 (n) in Problem P2.5e.

Page 7
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
9
ylabel(x1(n)); title(Sequence cos(0.3*pi*n));
ntick = [n(1):5:n(length(n))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
Since f0 = 0.3/2 = 3/20 the sequence is periodic. From the plot in Figure 2.7 we see that in one period of 20
samples x1 (n) exhibits three cycles. This is true whenever K and N are relatively prime.
(c) x2 (n) = cos(0.3n), 20 n 20.
% (b) x2(n) = cos(0.3*n)
x2 = cos(0.3*n);
subplot(2,1,2); stem(n,x2);

axis([min(n)-1,max(n)+1,-1.1,1.1]);
ylabel(x2(n)); title(Sequence cos(0.3*n));
ntick = [n(1):5:n(length(n))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
In this case f0 is not a rational number and hence the sequence x2 (n) is not periodic. This can be clearly seen from
the plot of x2 (n) in Figure 2.7.
4. Problem P2.5: Even-odd decomposition of complex-valued sequences.
(a) MATLAB function evenodd:
function [xe, xo, m] = evenodd(x,n)
% Complex-valued signal decomposition into even and odd parts
% ----------------------------------------------------------% [xe, xo, m] = evenodd(x,n)
%
[xc,nc] = sigfold(conj(x),n);
[xe,m] = sigadd(0.5*x,n,0.5*xc,nc);
[xo,m] = sigadd(0.5*x,n,-0.5*xc,nc);

(b) Even-odd decomposition of x(n) = 10e 0:4n , 0 n 10.


n = 0:10; x = 10*exp(-0.4*pi*n);
[xe,xo,neo] = evenodd(x,n);
Re_xe = real(xe); Im_xe = imag(xe);
Re_xo = real(xo); Im_xo = imag(xo);
% Plots of the sequences
subplot(2,2,1); stem(neo,Re_xe);
ylabel(Re{xe(n)}); title(Real part of Even Seq.);
subplot(2,2,3); stem(neo,Im_xe);
xlabel(n); ylabel(Im{xe(n)}); title(Imag part of Even Seq.);
subplot(2,2,2); stem(neo,Re_xo);
ylabel(Re{xo(n)}); title(Real part of Odd Seq.);
subplot(2,2,4); stem(neo,Im_xo);
xlabel(n); ylabel(Im{xo(n)}); title(Imag part of Odd Seq.);

5. Problem P2.12: Properties of linear convolution.


x1 (n) x2 (n) = x2 (n) x1 (n)
: Commutation

[x1 (n) x2 (n)] x3 (n) = x1 (n) [x2 (n) x3 (n)]


: Association
x1 (n) [x2 (n) +x3 (n)] = x1 (n) x2 (n) +x1 (n) x3 (n) : Distribution
x(n) (n n0) = x(n n0)
: Identity
(a) Commutation:
x1 (n) x2 (n) =

k=

x1 (k)x2(n k

| {z }
=m
)=


m=

x1 (n m)x2 (m

Page 1

Chapter 2

Discrete-Time Signals and Systems


1. Problem P2.1:
(a) x1 (n) = 10
m=0 (m+1)[(n 2m 1) (n 2m)], 0 n 25.
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1ac);
%
% x1(n) = sum_{m=0}{10} (m+1)*[delta(n-2*m)-delta(n-2*m-1)]
n1 = [0:25]; x1 = zeros(1,length(n1));
for m = 0:10
x1 = x1 + (m+1)*(impseq(2*m,0,25) - impseq(2*m+1,0,25));
end
subplot(2,1,1); stem(n1,x1);
axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x1(n) is shown in Figure 2.1.
(b) x2 (n) = n2 [u(n+5) u(n 6)] +10(n) +20(0.5)n [u(n 4) u(n 10)].
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.1be);
%
% (b) x2(n) = (n2)*[u(n+5)-u(n-6)]+10*delta(n)+20*(0.5)n*[u(n-4)-u(n-10)]
n2 = -5:10; % Overall support of x2(n)
x2 = (n2.2).*(stepseq(-5,-5,10)-stepseq(6,-5,10))+10*impseq(0,-5,10)+...
20*((0.5).n2).*(stepseq(4,-5,10)-stepseq(10,-5,10));
subplot(2,1,1); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-2,max(x2)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x2(n));
ntick = [n2(1):n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x2(n) is shown in Figure 2.3.
(c) x3 (n)=(0.9)n
cos(0.2n+/3), 0 n 20.
% x3(n) = (0.9)n*cos(0.2*pi*n+pi/3); 0<=n<=20
n3 = [0:20];
3

Page 2
4
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
10
5
0
5

10

n
x1(n)
Sequence x1(n)

Homework1 : Problem 1
0
1
2
3
4
5
6
7
8
9
10 11 12 13 14 15 16 17 18 19 20
1
0.5
0
0.5
1

n
x3(n)
Sequence x3(n)

Figure 2.1: Problem P2.1 Sequence Plots


x3 = ((0.9).n3).*cos(0.2*pi*n3+pi/3);
subplot(2,1,2); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,-1,1]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x3(n) is shown in Figure 2.1.
(d) x4 (n) = 10cos 0.0008n2
+w(n), 0 n 100 where w(n) is a random sequence uniformly distributed between
[ 1,1].
clear; close all;
% (d) x4(n) = 10*cos(0.0008*pi*n.2)+w(n); 0 <= n <= 100; w(n)uniform[-1,1]
w = 2*(rand(1,101)-0.5);
n4 = [0:100]; x4 = 10*cos(0.0008*pi*n4.2)+w;
subplot(2,1,2); stem(n4,x4); axis([min(n4)-1,max(n4)+1,min(x4)-2,max(x4)+2]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):10:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x4(n) is shown in Figure 2.2 from which we observe that it is a noisy sinusoid with increasing frequency
(or a noisy chirp signal).
(e) x5 (n) =
...,1,2,3,2"
,1,2,3,2,1,...
. Plot 5 periods.
% (e) x5(n) = {...,1,2,3,2,1,2,3,2,1,...}periodic. 5 periods
n5 = [-8:11]; x5 = [2,1,2,3];
x5 = x5*ones(1,5); x5 = (x5(:));
subplot(2,1,2); stem(n5,x5);
axis([min(n5)-1,max(n5)+1,0,4]);

Page 3
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
5
0
10
20
30
40
50
60
70
80
90
100
10
5
0
5

10

n
x4(n)
Sequence x4(n)

Figure 2.2: Plot of the sequence x4 (n) in Problem P2.1d.


xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x5(n) is shown in Figure 2.3.
5
4
3
2
1
0
1
2
3
4
5
6
7
8
9
10
0
5
10
15
20
25

n
x1(n)
Sequence x2(n)

Problem P2.1 : Sequences


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

n
x5(n)
Sequence x5(n)

Figure 2.3: Problem P2.1 Sequence Plots


2. Problem P2.2: The sequence x(n) =

f1, 2,4,6, 5,8,10gis given.

(a) x1(n) = 3x(n+2) +x(n 4) 2x(n).


clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2ab);

Page 4
6
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (a) x1(n) = 3*x(n+2) + x(n-4) - 2*x(n)
[x11,n11] = sigshift(3*x,n,-2);
% shift by -2 and scale by 3
[x12,n12] = sigshift(x,n,4);
% shift x(n) by 4
[x13,n13] = sigadd(x11,n11,x12,n12);
% add two sequences at time
[x1,n1] = sigadd(x13,n13,2*x,n);
% add two sequences
subplot(2,1,1); stem(n1,x1);

axis([min(n1)-1,max(n1)+1,min(x1)-2,max(x1)+2]);
xlabel(n); ylabel(x1(n)); title(Sequence x1(n));
ntick = [n1(1):1:n1(length(n1))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x1(n) is shown in Figure 2.4.
(b) x2(n) = 5x(5+n) +4x(n+4)+3x(n).
% (b) x2(n) = 5*x(5+n) + 4*x(n+4) +3*x(n)
[x21,n21] = sigshift(5*x,n,-5);
[x22,n22] = sigshift(4*x,n,-4);
[x23,n23] = sigadd(x21,n21,x22,n22);
[x2,n2] = sigadd(x23,n23,3*x,n);
subplot(2,1,2); stem(n2,x2);
axis([min(n2)-1,max(n2)+1,min(x2)-0.5,max(x2)+0.5]);
xlabel(n); ylabel(x2(n)); title(Sequence x2(n));
ntick = [n2(1):1:n2(length(n2))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plot of x2(n) is shown in Figure 2.4.
6
5
4
3
2
1
0
1
2
3
4
5
6
0
10
20
30

n
x1(n)
Sequence x1(n)

Homework1 : Problem 2
9
8
7
6
5
4
3
2
1
0
1
2
0
20
40
60

n
x2(n)
Sequence x2(n)

Figure 2.4: Problem P2.2 Sequence Plots


(c) x3(n) = x(n+4)x(n 1) +x(2 n)x(n).

Page 5
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
7
clear; close all;
Hf_1 = figure(Units,normalized,position,[0.1,0.1,0.8,0.8],color,[0,0,0]);
set(Hf_1,NumberTitle,off,Name,P2.2cd);
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
%
% (c) x3(n) = x(n+4)*x(n-1) + x(2-n)*x(n)
[x31,n31] = sigshift(x,n,-4);
% shift x(n) by -4
[x32,n32] = sigshift(x,n,1);
% shift x(n) by 1
[x33,n33] = sigmult(x31,n31,x32,n32); % multiply two sequences

[x34,n34] = sigfold(x,n);
% fold x(n)
[x34,n34] = sigshift(x34,n34,2);
% shift x(-n) ny 2
[x34,n34] = sigmult(x34,n34,x,n);
% shift x(-n) ny 2
[x3,n3] = sigadd(x33,n33,x34,n34);
% add two sequences
subplot(2,1,1); stem(n3,x3);
axis([min(n3)-1,max(n3)+1,min(x3)-2,max(x3)+2]);
xlabel(n); ylabel(x3(n)); title(Sequence x3(n));
ntick = [n3(1):1:n3(length(n3))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plots of x3(n) is shown in Figure 2.5.
(d) x4(n) = 2e0:5nx(n) +cos(0.1n)x(n+2), 10 n 10.
% (d) x4(n) = 2*exp(0.5*n)*x(n)+cos(0.1*pi*n)*x(n+2); -10 <= n <= 10
n4 = [-10:10]; x41 = 2*exp(0.5*n4); x412 = cos(0.1*pi*n4);
[x42,n42] = sigmult(x41,n4,x,n);
[x43,n43] = sigshift(x,n,-2);
[x44,n44] = sigmult(x412,n4,x43,n43);
[x4,n4] = sigadd(x42,n42,x44,n44);
subplot(2,1,2); stem(n4,x4);
axis([min(n4)-1,max(n4)+1,min(x4)-0.5,max(x4)+0.5]);
xlabel(n); ylabel(x4(n)); title(Sequence x4(n));
ntick = [n4(1):1:n4(length(n4))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10)
The plots of x4(n) is shown in Figure 2.5.
(e) x5 (n) = 5

k) where x(n) = 1, 2,4,6, 5,8,10 .


clear; close all;
n = [-4:2]; x = [1,-2,4,6,-5,8,10]; % given seq x(n)
% (e) x5(n) = sum_{k=1}{5}n*x(n-k);
[x51,n51] = sigshift(x,n,1); [x52,n52] = sigshift(x,n,2);
[x5,n5] = sigadd(x51,n51,x52,n52);
[x53,n53] = sigshift(x,n,3); [x5,n5] = sigadd(x5,n5,x53,n53);
[x54,n54] = sigshift(x,n,4); [x5,n5] = sigadd(x5,n5,x54,n54);
[x55,n55] = sigshift(x,n,5); [x5,n5] = sigadd(x5,n5,x55,n55);
[x5,n5] = sigmult(x5,n5,n5,n5);
subplot(2,1,2); stem(n5,x5); axis([min(n5)-1,max(n5)+1,min(x5)-2,max(x5)+2]);
xlabel(n); ylabel(x5(n)); title(Sequence x5(n));
ntick = [n5(1):1:n5(length(n5))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
The plot of x5(n) is shown in Figure 2.6.
3. Problem P2.3: A sequence x(n) is periodic if x(n+N) = x(n) for all n. Consider a complex exponential sequence
ej0n = ej2f0n.
k=1 nx(n

Page 6
8
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
8
7
6
5
4
3
2
1
0
1
2
3
4
5
6

40
20
0
20
40
60

n
x3(n)
Sequence x3(n)

Problem P2.2 : Sequences


10 9 8 7 6 5 4 3 2 1
0
1
2
3
4
5
6
7
8
9
10
0
10
20
30
40
50

n
x4(n)
Sequence x4(n)

Figure 2.5: Problem P2.2 Sequence Plots


(a) Analytical proof: The above sequence is periodic if
ej2f0 n+N
= ej2f0n
or
ej2f0N = 1 f0N = K (an integer)
which proves the result.
(b) x1 (n) = cos(0.3n), 20 n 20.
% (b) x1(n) = cos(0.3*pi*n)
x1 = cos(0.3*pi*n);
subplot(2,1,1); stem(n,x1);
axis([min(n)-1,max(n)+1,-1.1,1.1]);
3
2
1
0
1
2
3
4
5
6
7
0
20
40
60
80
100

n
x5(n)
Sequence x5(n)

Figure 2.6: Plot of the sequence x5 (n) in Problem P2.5e.

Page 7
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB
9
ylabel(x1(n)); title(Sequence cos(0.3*pi*n));
ntick = [n(1):5:n(length(n))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
Since f0 = 0.3/2 = 3/20 the sequence is periodic. From the plot in Figure 2.7 we see that in one period of 20
samples x1 (n) exhibits three cycles. This is true whenever K and N are relatively prime.
(c) x2 (n) = cos(0.3n), 20 n 20.
% (b) x2(n) = cos(0.3*n)
x2 = cos(0.3*n);
subplot(2,1,2); stem(n,x2);

axis([min(n)-1,max(n)+1,-1.1,1.1]);
ylabel(x2(n)); title(Sequence cos(0.3*n));
ntick = [n(1):5:n(length(n))];
set(gca,XTickMode,manual,XTick,ntick,FontSize,10);
In this case f0 is not a rational number and hence the sequence x2 (n) is not periodic. This can be clearly seen from
the plot of x2 (n) in Figure 2.7.
20
15
10
5
0
5
10
15
20
1
0.5
0
0.5
1

x1(n)
Sequence cos(0.3*pi*n)

Problem 2.3
20
15
10
5
0
5
10
15
20
1
0.5
0
0.5
1

x2(n)
Sequence cos(0.3*n)

Figure 2.7: Problem P2.3 Sequence Plots


4. Problem P2.5: Even-odd decomposition of complex-valued sequences.
(a) MATLAB function evenodd:
function [xe, xo, m] = evenodd(x,n)
% Complex-valued signal decomposition into even and odd parts
% ----------------------------------------------------------% [xe, xo, m] = evenodd(x,n)
%
[xc,nc] = sigfold(conj(x),n);
[xe,m] = sigadd(0.5*x,n,0.5*xc,nc);
[xo,m] = sigadd(0.5*x,n,-0.5*xc,nc);

Page 8
10
SOLUTIONS MANUAL FOR DSP USING MATLAB
APRIL 98
(b) Even-odd decomposition of x(n) = 10e 0:4n , 0 n 10.
n = 0:10; x = 10*exp(-0.4*pi*n);
[xe,xo,neo] = evenodd(x,n);
Re_xe = real(xe); Im_xe = imag(xe);
Re_xo = real(xo); Im_xo = imag(xo);
% Plots of the sequences
subplot(2,2,1); stem(neo,Re_xe);
ylabel(Re{xe(n)}); title(Real part of Even Seq.);
subplot(2,2,3); stem(neo,Im_xe);
xlabel(n); ylabel(Im{xe(n)}); title(Imag part of Even Seq.);
subplot(2,2,2); stem(neo,Re_xo);
ylabel(Re{xo(n)}); title(Real part of Odd Seq.);
subplot(2,2,4); stem(neo,Im_xo);
xlabel(n); ylabel(Im{xo(n)}); title(Imag part of Odd Seq.);
The MATLAB verification plots are shown in Figure 2.8.
10
5
0
5

10
0
2
4
6
8
10
Re{xe(n)}
Real part of Even Seq.
10
5
0
5
10
1
0.5
0
0.5
1
n
Im{xe(n)}
Imag part of Even Seq.
10
5
0
5
10
1.5
1
0.5
0
0.5
1
1.5
Re{xo(n)}
Real part of Odd Seq.
10
5
0
5
10
1
0.5
0
0.5
1
n
Im{xo(n)}
Imag part of Odd Seq.

Figure 2.8: Plots in Problem P2.5


5. Problem P2.12: Properties of linear convolution.
x1 (n) x2 (n) = x2 (n) x1 (n)
: Commutation

[x1 (n) x2 (n)] x3 (n) = x1 (n) [x2 (n) x3 (n)]


: Association
x1 (n) [x2 (n) +x3 (n)] = x1 (n) x2 (n) +x1 (n) x3 (n) : Distribution
x(n) (n n0) = x(n n0)
: Identity
(a) Commutation:
x1 (n) x2 (n) =

k=

x1 (k)x2(n k

| {z }
=m
)=

m=

x1 (n m)x2 (m)

Page 9
APRIL 98
SOLUTIONS MANUAL FOR DSP USING MATLAB

k) = 1 for k = n n0 and zero elsewhere.


(b) Verification using MATLAB:
n1 = -10:20; x1 = n1;
n2 = 0:30; x2 = cos(0.1*pi*n2);
n3 = -5:10; x3 = (1.2).n3;
% Commutative Property
[y1,ny1] = conv_m(x1,n1,x2,n2);
[y2,ny2] = conv_m(x2,n2,x1,n1);
ydiff = max(abs(y1-y2))
ydiff =

4.2633e-014
ndiff = max(abs(ny1-ny2))
ndiff =
0
% Associative Property
[y1,ny1] = conv_m(x1,n1,x2,n2);
[y1,ny1] = conv_m(y1,ny1,x3,n3);
[y2,ny2] = conv_m(x2,n2,x3,n3);
[y2,ny2] = conv_m(x1,n1,y2,ny2);
ydiff = max(abs(y1-y2))

ydiff =
6.8212e-013
ndiff = max(abs(ny1-ny2))
ndiff =
0
% Distributive Property
[y1,ny1] = sigadd(x2,n2,x3,n3);
[y1,ny1] = conv_m(x1,n1,y1,ny1);
[y2,ny2] = conv_m(x1,n1,x2,n2);
[y3,ny3] = conv_m(x1,n1,x3,n3);
[y2,ny2] = sigadd(y2,ny2,y3,ny3);
ydiff = max(abs(y1-y2))
ydiff =
1.7053e-013
ndiff = max(abs(ny1-ny2))
ndiff =
0
% Identity Property
n0 = fix(100*(rand(1,1)-0.5));
[dl,ndl] = impseq(n0,n0,n0);
[y1,ny1] = conv_m(x1,n1,dl,ndl);
[y2,ny2] = sigshift(x1,n1,n0);
ydiff = max(abs(y1-y2))
ydiff =
0
ndiff = max(abs(ny1-ny2))
ndiff =
0

Ppalitan ng w

C3.2nd page

You might also like