0% found this document useful (0 votes)
117 views6 pages

Solution To Homework 1

The document contains a homework assignment on digital signal processing using MATLAB. It asks the student to generate and plot various sequences by manipulating impulse and step sequences. It provides code to generate sequences like x1(n) = 3δ(n+2) + 2δ(n) - δ(n-3) + 5δ(n-7) and x2(n) = 10u(n) - 5u(n-5) - 10u(n-10) + 5u(n-15). It also asks the student to generate and plot sequences based on manipulating an input sequence x(n) = {2, 4, -3, 1, -5, 4,

Uploaded by

Rani Purbasari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
117 views6 pages

Solution To Homework 1

The document contains a homework assignment on digital signal processing using MATLAB. It asks the student to generate and plot various sequences by manipulating impulse and step sequences. It provides code to generate sequences like x1(n) = 3δ(n+2) + 2δ(n) - δ(n-3) + 5δ(n-7) and x2(n) = 10u(n) - 5u(n-5) - 10u(n-10) + 5u(n-15). It also asks the student to generate and plot sequences based on manipulating an input sequence x(n) = {2, 4, -3, 1, -5, 4,

Uploaded by

Rani Purbasari
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

Digital Signal Processing using MATLAB

Homework Assignment #1
1.

Generate and plot the following sequences using the basic MATLAB signal
functions and the basic MATLAB signal operations discussed in Chapter 2.
(a) x1 (n) = 3 (n + 2) + 2 (n) (n 3) + 5 (n 7), 5 n 15.
n = -5:15; n1 = min(n); n2 = max(n);
x1 = 3*impseq(-2,n1,n2) + 2*impseq(0,n1,n2) - impseq(3,n1,n2) +
5*impseq(7,n1,n2);
figure; subplot(2,1,1); plot(n,0.*n); hold on; stem(n,x1);
xlabel('n'); ylabel('x1(n)'); axis([n1-1 n2+1 min(x1)-1

max(x1)+1]);
title('Sequence in Problem 2.1.1');

(b)

x2 (n) = 10u (n) 5u (n 5) 10u (n 10) + 5u (n 15),

5 n 20.

n = -5:20; n1 = min(n); n2 = max(n);


x2 = 10*stepseq(0,n1,n2) - 5*stepseq(5,n1,n2) 10*stepseq(10,n1,n2) + 5*stepseq(15,n1,n2);
subplot(2,1,2); plot(n,0.*n); hold on; stem(n,x2);
xlabel('n'); ylabel('x2(n)'); axis([n1-1 n2+1 min(x2)-1
max(x2)+1]);
title('Sequence in Problem 2.1.3');

(c)

x3 (n) = 5[ cos(0.49n) + cos(0.51n)],

200 n 200. Comment on

the waveform shape.


n = -200:200; n1 = min(n); n2 = max(n);
x3 = 5*(cos(0.49*pi*n)+cos(0.51*pi*n));
figure; subplot(2,1,1); plot(n,0.*n); hold on; stem(n,x3);
xlabel('n'); ylabel('x3(n)'); axis([n1-1 n2+1 min(x3)-1
max(x3)+1]);
title('Sequence in Problem 2.1.5'); % period 200

(d)

x4 (n) = e 0.05 n sin(0.1n + 3), 0 n 100. Comment on the waveform

shape.
n = 0:100; n1 = min(n); n2 = max(n);
x4 = exp(-0.05*n).*sin(0.1*pi*n+pi/3);
subplot(2,1,2); plot(n,0.*n); hold on; stem(n,x4);
xlabel('n'); ylabel('x4(n)'); axis([n1-1 n2+1 -1 +1]);
title('Sequence in Problem 2.1.7');

Sequence in Problem 2.1.1


6

x1(n)

-2
-6

-4

-2

10

12

14

16

n
Sequence in Problem 2.1.3
10

x2(n)

-5
-5

10
n

15

20

Sequence in Problem 2.1.5


10

x3(n)

5
0
-5
-10
-200

-150

-100

-50

0
n

50

100

150

200

Sequence in Problem 2.1.7


1

x4(n)

0.5

-0.5

-1
0

2.

10

20

30

40

50
n

60

70

80

90

Let x(n) = {2, 4, -3, 1, -5, 4, 7}. Generate and plot the following sequences.
(a) x1 (n) = 2 x( n 3) + 3 x( n + 4) x(n).
(b) x2 (n) = 4 x(4 + n) + 5 x (n + 5) + 2 x (n).
(c)
(d)

x3 ( n) = x(n + 3) x (n 2) + x (1 n) x( n +1).

x4 (n) = 2e 0.5 n x(n) + cos(0.1 n) x(n + 2),

10 n 10.

% P2.4
clear;
n = -3:3;
x = [2 4 -3 1 -5 4 7];
% P2.4.1
% x1(n) = 2*x(n-3)+3*x(n+4)-x(n);
[x11,n11] = sigshift(x,n,3);
[x12,n12] = sigshift(x,n,-4);
[x13,n13] = sigadd(2*x11,n11,3*x12,n12);
[x1,n1] = sigadd(x13,n13,-1*x,n);
figure; subplot(2,1,1); plot(n1,0.*n1); hold on; stem(n1,x1);

100

xlabel('n'); ylabel('x1(n)'); axis([min(n1)-1 max(n1)+1 min(x1)-1


max(x1)+1]);
title('Sequence in Problem 2.4.1');
% P2.4.2
% x2(n) = 4*x(n+4)+5*x(n+5)+2*x(n);
[x21,n21] = sigshift(x,n,-4);
[x22,n22] = sigshift(x,n,-5);
[x23,n23] = sigadd(4*x21,n21,5*x22,n22);
[x2,n2] = sigadd(x23,n23,2*x,n);
subplot(2,1,2); plot(n2,0.*n2); hold on; stem(n2,x2);
xlabel('n'); ylabel('x2(n)'); axis([min(n2)-1 max(n2)+1 min(x2)-1
max(x2)+1]);
title('Sequence in Problem 2.4.2');
% P2.4.3
% x3(n) = x(n+3)*x(n-2)+x(1-n)*x(n+1);
[x31,n31] = sigshift(x,n,-3);
[x32,n32] = sigshift(x,n,2);
[x33,n33] = sigmult(x31,n31,x32,n32);
[x34,n34] = sigfold(x,n);
[x35,n35] = sigshift(x34,n34,1);
[x36,n36] = sigshift(x,n,-1);
[x37,n37] = sigmult(x35,n35,x36,n36);
[x3,n3] = sigadd(x33,n33,x37,n37);
figure; subplot(2,1,1); plot(n3,0.*n3); hold on; stem(n3,x3);
xlabel('n'); ylabel('x3(n)'); axis([min(n3)-1 max(n3)+1 min(x3)-1
max(x3)+1]);
title('Sequence in Problem 2.4.3');
% P2.4.4
% x4(n) = 2*exp(0.5*n)*x(n)+cos(0.1*pi*n)*x(n+2); -10 <= n <= 10
n = -10:10; x = zeros(1,length(n));
x(8:14) = [2 4 -3 1 -5 4 7];
x41 = 2*exp(0.5*n).*x;
[x42,n42] = sigshift(x,n,-2);
[x43,n43] = sigmult(cos(0.1*pi*n),n,x42,n42);
[x4,n4] = sigadd(x41,n,x43,n43);

subplot(2,1,2); plot(n4,0.*n4); hold on; stem(n4,x4);


xlabel('n'); ylabel('x4(n)'); axis([min(n4)-1 max(n4)+1 min(x4)-1
max(x4)+1]);
title('Sequence in Problem 2.4.4');

Sequence in Problem 2.4.1


20

x1(n)

10
0
-10
-8

-6

-4

-2

n
Sequence in Problem 2.4.2
60

x2(n)

40
20
0
-20
-8

-6

-4

-2
n

Sequence in Problem 2.4.3

x3(n)

40

20
0

-20
-6

-4

-2

n
Sequence in Problem 2.4.4
60

x4(n)

40

20

0
-10

-5

0
n

10

You might also like