Sei sulla pagina 1di 27

18-290

Signals and Systems


Profs. Aswin Sankaranarayanan and Richard Stern

Spring 2016

Homework 3 Solutions
1. (6pts) Consider the signal
 n1
1
h[n] =
{u[n + 3] u[n 10]}
2
Express A and B in terms of n so that the following equation holds:
( nk1
1
, AkB
2
.
h[n k] =
0,
elsewhere
Solution:

 nk1
1
h[n k] =
{u[n k + 3] u[n k 10]}
2
The interval being non-zero is:
3 n k
3 n k
n9k

A = n 9, B = 3 + n.

9
9n
3+n

Homework 3 Solutions
2. (12pts) Prove the following two properties of convolution.
(a) (6pts) x[n] h[n + c] = x[n + c] h[n], c Z
(b) (6pts) If y[n] = x[n] h[n], then x[n] h[n + c] = y[n + c]
Note: the above two properties can be used to explain the results that you obtained
in Problem 3.
Hint: Use the definition of convolution and substitute variables.
y[n] =

x[k]h[n k]

k=

Solution:
(a)
x[n] h[n + c] =

x[k]h[n k + c]

k=

If we substitute k 0 = k c,

X
x[k 0 + c]h[n k 0 ]
=
=

k0 =

x[k + c]h[n k]

k=

= x[n + c] h[n]
(b) y[n] = x[n] h[n] =

k=

x[k]h[n k]

x[n] h[n + c] =

x[k]h[n + c k]

k=

If we substitute n0 = n + c

X
=
x[k]h[n0 k]
k=
0

= y[n ]
= y[n + c]

Homework 3 Solutions

3. (11pts) Let
x[n] = [n] + 2[n 1] [n 3]
h[n] = 2[n + 1] + 2[n 1]
Compute and plot each of the following convolutions:
(a) (5pts) y1 [n] = x[n] h[n]
(b) (3pts) y2 [n] = x[n + 2] h[n]
(c) (3pts) y3 [n] = x[n] h[n + 2]
(Hint: use result from problem 2 in part(b) and (c).) Solution:

x[k]h[n k]
P
For n 2, y1 [n] =
k= x[k]h[n k] = 0.
P
y1 [1] = k= x[k]h[1 k] = x[0]h[1 0] = 1 2 = 2
P
y1 [0] =
k= x[k]h[k] = x[1]h[1] = 2 2 = 4
P
y1 [1] = k= x[k]h[1 k] = x[0]h[1 0] = 1 2 = 2
P
y1 [2] =
k= x[k]h[2 k] = x[1]h[2 1] + x[3]h[2 3] = 2 2 + (1) 2 = 2
P
y1 [3] = k= x[k]h[1 k] = 0
P
y1 [4] =
k= x[k]h[4 k] = x[3]h[4 3] = 1 2 = 2
P
For n 5, y1 [n] =
k= x[k]h[n k] = 0.

(a) y[n] =

k=

y[n] = 2[n + 1] + 4[n] + 2[n 1] + 2[n 2] 2[n 4]

Homework 3 Solutions

(b) y2 [n] = y1 [n + 2] .
Use 2(b) and plug in c = 2, we get y2 [n] = y1 [n + 2].

(c) y3 [n] = y2 [n].


Use 2(b) and plug in c = 2, we get y3 [n] = y2 [n] = y1 [n + 2].

Homework 3 Solutions

Homework 3 Solutions
4. (10pts) Consider an input x[n] and a unit impulse response h[n] given by
 n2
1
x[n] =
u[n 2]
2
h[n] = u[n + 2].
Determine and plot the output y[n] = x[n] h[n]. You should obtain a closed-form
solution (i.e. no sums or integrals) using the relationships developed in class for finite
and/or infinite geometric series.

X
Solution:
x[k]h[n k]
y[n] =
=

k=

X
k=

1
2

k2
u[k 2]u[n k + 2]

u[k 2]u[n k + 2] = 1 for 2 k n + 2. To make the inequality hold, n 0.


Therefore,
y[n] =

n+2  k2
X
1
k=2

2
n+1

u[n]

1(1 21 )
u[n]
=
1 12


1 n+1
u[n]
=2 1
2

Homework 3 Solutions

5. (18 points) Evaluate all expressions without using any property of convolution.
(a) (8 points) Consider the discrete-time signals x[n] and h[n]:
x[n] = (1/2)n3 u[n 3]
h[n] = (3)n+2 u[(n + 2)]
Evaluate the following convolution sums:
i. y1 [n] = x[n] h[n]
ii. y2 [n] = h[n] x[n]
(b) (8 points) Consider the discrete time signals x[n] and h[n]:

+1 n = 0
x[n] = 1 n = 1

0
otherwise
(
n2
h[n] =
0

4 n 4
otherwise

Evaluate the following convolution sums:


i. y3 [n] = x[n] h[n]
ii. y4 [n] = h[n] x[n]
(c) (2 points) What is the relationship between y1 [n] and y2 [n]? What is the relationship between y3 [n] and y4 [n]?
Solution:
(a)

i.
y1 [n] = x[n] h[n]
y1 [n] =

x[k]h[n k]

k=
 
X
1 k3
u[k 3] 3n+2k u[(n + 2 k)]
=
2
k=


u[k (n + 2)] =

1,
0,

if k n + 2
if k < n + 2

(1)
(2)

Homework 3 Solutions

1,
0,

u[k 3] =

if k 3
if k < 3

(3)
(4)

Intersection region when both the unit step functions are 1, would lie between
> k max(3, n + 2)
Hence, there would be 2 cases
Case 1:

3n+2n1
 
X
1 k3 n+2k
y[n] =
3
2
k=n+2

 1 3
2

n+2

n+2

=2 3
"
= 8 9 3n

"

 
X
1 k
6
k=n+2

 
X
1 k
k=0

= 72 3n

 
X
1 k k
3
2
k=n+2

n+1  
X
1 k
k=0

 n+2 #
1
1

6
1

 

1 16
1 16

"
#
72 3n  1 n+2
=  
5
6
6

72 3n 6
5 6n 62

12 3n
1
n n
5
3
2
 12 
=
2n
;n 1
5
=

Homework 3 Solutions
Case 2:

9
3>n+2n<1
y1 [n] =

 
X
1 k3
k=3

= 23 3n+2

3n+2k

   
X
1 k 1 k

k=3

= 72 3n

 
X
1 k
k=3

!#
1
1

+
+1
= 72 3
6
6 62
k=0
#
"
6
+
1
+
36
1

= 72 3n 
36
1 16
"
#
43
n 6
= 72 3

5 36
"
#
36

43

5
= 72 3n
36 5
"

 
X
1 k

2
5

3n

;n < 1

 
12 n

2 ,
5
y1 [n] =  

2 3n ,
5

if n 1

(5)

if n < 1

(6)

ii.
y2 [n] = h[n] x[n]
y2 [n] =

h[k]x[n k]

k=

X
k=

3k+2 u[(k + 2)]

 1 n3k
2

u[n 3 k]

10

Homework 3 Solutions

=3 2

3 u[(k + 2)]

 1 nk

k=

u[n 3 k]

Putting k = k
=

32 23 X  1 k
u[k 2]u[k (3 n)]
2n k= 6

= 72 2

 
X
1 k
u[k 2]u[k (3 n)]
6
k=

Intersection region when both the unit step functions are 1, would lie between
> k max(2, 3 n)
Hence, there would be 2 cases
Case 1:

3n>2n<1
y2 [n] = 72 2n
"
y2 [n] = 72 2n

 
X
1 k
6
k=3n

 
X
1 k

k=0

2n  
X
1 k
k=0

 3n #
1
1

6
1
n
 


= 72 2
1
1
1 6
1 6
"
#
 1 3n
6
= 72 2n
5 6
"

Case 2:

2
3n
5

;n < 1

3n2n1
n

y2 [n] = 72 2

 
X
1 k
k=2

Put k = k + 2
y2 [n] =

72 2n X  1 k
36
6
k=0

Homework 3 Solutions

11

72
1

2n 
1
36
1 6
= 2 2n

12
2n
5

6
5

;n 1

3n ,
5
y2 [n] =

12 2n ,
5

if n < 1

(7)

if n 1

(8)

Alternative Solution to 5(a):

Let
x1 [n] =

 1 n

u[n]
2
h1 [n] = 3n u[n)]

m1 [n] = x1 [n] h1 [n]


m1 [n] =

x1 [k].h1 [n k]

k=
 
X
1 k
=
u[k]3nk u[k n]
2
k=
 
X
1 k
=3
u[k]u[k n]
6
k=
n

u[k] = 1 k 0
u[k n] = 1 k n 0
Intersection region of both unit step functions will be 1 in the
> k max(0, n)
Case 1: n 0
m1 [n] = 3n

 
X
1 k
k=n

12

Homework 3 Solutions
Put k 0 = k n in the equation.
  0
X
1 k +n

m1 [n] = 3n

k0 =0

3n
1

n
6
1

= 2n
Case 2: n < 0
n

m1 [n] = 3

1
6

6
5

 
X
1 k
k=0

= 3n

6
5

Overall

2n ,
5
m1 [n] =
6

3n ,
5

if n 0
if n < 0

From time shifted property of convolution:


y[n + c] = x[n + c] h[n]
We can write
y1 [n] = x1 [n 3] h1 [n + 2]
Applying the above stated property twice
y1 [n] = m1 [n 1]

2 2n ,
5
y1 [n] =

6 31 3n ,
5

12

2n ,
5
y1 [n] =
2

3n ,
5

if n 1
if n < 1

if n 1
if n < 1

Homework 3 Solutions

13

(b)

y3 [n] = x[n] h[n]

X
=
x[k]h[n k]
k=

0
n 5

Pn+4

n = 4
Pk=0 x[k]h[n k]
1
=
h[k]x[n k]
3 n 4

P1k=0

k=n4 x[k]h[n k] n = 5

0
n6

0
n 5

n = 4
x[4]
= h[0]x[n] + h[1]x[n 1] 3 n 4

x[4]
n=5

0
n6

0
n 5

n = 4
16
= x[n] x[n 1] 3 n 4

16
n=5

0
n6

14

Homework 3 Solutions

y4 [n] = h[n] x[n]

X
=
h[k]x[n k]
k=

0
n 5

k=4 x[k]h[n k] n = 4

Pn
=
x[k]h[n k] 3 n 4

Pk=n1

k=n1 x[k]h[n k] n = 5

0
n6

0
n 5

n = 4
x[4]
= x[n 1]h[1] + x[n]h[0] 3 n 4

x[5]
n=5

0
n6

0
n 5

n = 4
16
= x[n] x[n 1] 3 n 4

16
n=5

0
n6

(c) y1 [n] = y2 [n] and y3 [n] = y4 [n]. The signals are equal, which illustrates that
convolution has the property of commutativity.

Homework 3 Solutions

15

6. (12 points) Determine and explain the following properties of convolution.


y[n] = x[n] h[n]
(a) (4 points) If x[n] is an even function and h[n] is an even function, is y[n]
even,odd, or neither?
(b) (4 points) If x[n] is an odd function and h[n] is an odd function, is y[n] even,odd,
or neither?
(c) (4 points) If x[n] is an even function and h[n] is an odd function, is y[n]
even,odd, or neither?
Hint: Use the definition of the convolution and also use the properties of even/odd
functions.
Solution:

y[n] =

x[k]h[n k]

k=

Even function: f (x) = f (x)


Odd function: f (x) = f (x)

(a) Even function

y[n] =

x[k]h[n k]

k=

x[n] is an even function

X
=
x[k]h[n k]
k=

substitute -k = k

X
=
x[k 0 ]h[n + k 0 ]
k0 =

h[n] is an even function

X
=
x[k 0 ]h[n k 0 ]
k0 =

= y[n]
(b) Even function

16

Homework 3 Solutions

y[n] =

x[k]h[n k]

k=

x[n] is an odd function

X
=
x[k]h[n k]
k=

substitute -k = k

X
=
x[k 0 ]h[n + k 0 ]
k0 =

h[n] is an odd function

X
=
x[k 0 ]h[n k 0 ]
k0 =

= y[n]
(c) Odd function

y[n] =

x[k]h[n k]

k=

x[n] is an even function

X
=
x[k]h[n k]
k=

substitute -k = k

X
=
x[k 0 ]h[n + k 0 ]
k0 =

h[n] is an odd function

X
=
x[k 0 ](h[n k 0 ])
k0 =

= y[n]

Homework 3 Solutions

17

7. (20 points) Convolution Sum (MATLAB question)


In this problem, you will implement your own convolution sum function, and compare
it to MATLABs stock convolution sum function.
(a) (3 points) Two discrete-time signals are given below:
x[n] = 2(u[n + 10] u[n 10])
h[n] = (3 |n 10|)(u[n 8] u[n 13])
If y[n] = x[n] h[n], by using the definition of convolution sum, find the two
indices n0 and n1 such that y[n] = 0, n < n0 , n > n1 . In other words, n0 and n1
are the minimum and maximum indices on which y[n] is non-zero. (Note: solve
this part by hand.)
(b) (3 points) Now, consider the more general case where
x[n] = 0, n < n0 , n > n1
h[n] = 0, n < n2 , n > n3
If y[n] = x[n] h[n], express the minimum and maximum indices, nmin and nmax ,
on which y[n] is non-zero in terms of n0 , n1 , n2 , n3 . (Note: solve this part by
hand.)
(c) (10 points) Without using MATLABs built-in function conv, complete a convolution sum function. Your function should exactly follow the signature given
below.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

function [ny,y] = convolve(nx,x,nh,h)


% CONVOLVE: Perform a convolution sum: X[n] * H[n] = Y[n]
% nx - A contiguous integer sequence representing the discrete%
time index of signal X[n]. X[n] should all be 0 outside
%
the range nx.
% x - A sequence of real numbers so that X[nx(i)] = x(i),
%
for 1 <= i <= N
% (ny,y) and (nh,h) are defined the same as the (nx,x) pair.
%
% Example: if X[n] = delta[n+1]+delta[n-2] and H[n] = delta[n-1],
% then your input to the function should be:
%
nx = [-1,0,1,2], x = [1,0,0,1], nh = [1], h = [1].
% The expected output is:
%
ny = [0,1,2,3], y = [1,0,0,1]
%

Hint: You should use the result from part (b) as a starting point.
(d) (2 points) Using your convolution sum function, compute y[n] in part (a). Plot
x[n], h[n], and y[n] on one figure using different colors. Make sure that you label
which color corresponds to which signal. The built-in functions stem, legend
may be useful.

18

Homework 3 Solutions
(e) (2 points) Compute y[n] with MATLABs built-in function conv. How is this
function different from the function you wrote in part (c)? Which function do
you think is better? Explain your answer.
Note: You should submit a hard copy of code for part (c), (d), and (e). You
should also attach the figure printout for part (d).
Solution:
(a) (3 points) First, we should observe that
x[n] = 0, n < 10, n > 9
h[n] = 0, n < 8, n > 12
By definition,
y[n] = x[n] h[n] =

x[k]h[n k]

k=

P9
P
We thus have y[n] =
k=10 5h[n k]. The second
k= x[k]h[n k] =
equality is the result of substituting x[k] into the equation. Clearly, to keep y[n]
non-zero, we should want at least one sample of h[n k] to be non-zero in the
range 10 k 9. If we compare this range to the non-zero range of h[n], we
should see that the range [n 9, n + 10] should overlap with the range [8, 12]. The
minimum n (i.e. n0 ) occurs when n + 10 = 8, and the maximum n (i.e. n1 ) occurs
when n 9 = 12. Therefore,
n0 = 2
n1 = 21
(b) (3 points)
in part (a), we should apply the definition and get
P By the same token P
n1
y[n] =
x[k]h[n

k]
=
k=
k=n0 Ck h[n k], where Ck is non-zero constant
numbers we dont care. To keep y[n] non-zero, we should want at least one sample
of h[nk] to be non-zero in the range n0 k n1 . If we compare this range to the
non-zero range of h[n], we should see that the range [n n1 , n n0 ] should overlap
with the range [n2 , n3 ]. The minimum n (i.e. nmin ) occurs when n n0 = n2 , and
the maximum n (i.e. nmax ) occurs when n n1 = n3 . Therefore,
nmin = n0 + n2
nmax = n1 + n3
(c) (10 points)

Homework 3 Solutions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

19

function [ny,y] = convolve(nx,x,nh,h)


% CONVOLVE: Perform a convolution sum: X[n] * H[n] = Y[n]
% nx - A contiguous integer sequence representing the discrete%
time index of signal X[n]. X[n] should all be 0 outside
%
the range nx.
% x - A sequence of real numbers so that X[nx(i)] = x(i),
%
for 1 <= i <= N
% (ny,y) and (nh,h) are defined the same as the (nx,x) pair.
%
% Example: if X[n] = delta[n+1]+delta[n-2] and H[n] = delta[n-1],
% then your input to the function should be:
%
nx = [-1,0,1,2], x = [1,0,0,1], nh = [1], h = [1].
% The expected output is:
%
ny = [0,1,2,3], y = [1,0,0,1]
%

16
17
18
19
20

% Obtain non-zero index boundary


n min = nx(1) + nh(1); % this should be clear from part (b)
n max = nx(end) + nh(end);
ny = n min:n max;

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

% Implement convolution using the definition:


% y[n] = x[n] * h[n] = \sum k x[k]h[n-k]
% Note: This is not an optimal implementation in terms of speed.
% It strictly follows the definition to facilitate understanding.
y = zeros(size(ny)); % preallocate output
h = h(end:-1:1); % flip h[n-k] (where k is the running index)
nh = -nh; nh = nh(end:-1:1); % flip time axis accordingly
for i = 1:length(y), % y[n] = 0 outside this range
nh cur = nh + ny(i); % delay h by shifting nh to the left
% align h[n-k] and x[k] properly in time
n cur = min(nh cur(1),nx(1)):max(nh cur(end),nx(end));
% this is quite inefficient when x[k] and h[n-k] are far apart
x cur = zeros(size(n cur));
x cur(find(n cur==nx(1)):find(n cur==nx(end))) = x;
h cur = zeros(size(n cur));
h cur(find(n cur==nh cur(1)):find(n cur==nh cur(end))) = h;
y(i) = x cur * h cur'; % compute sum of product
end

(d) (2 points)
1
2
3
4
5
6
7

% 18-290: Signals & Systems


% Homework 3: Problem 7
% Part (d)
% Remember that:
% x[n] = 2(u[n+10]-u[n-10])
% h[n] = [3 -|n-10|](u[n-8]-u[n-13])
nx = -10:9;

20

Homework 3 Solutions

8
9
10
11

x = 2*ones(size(nx));
nh = 8:12;
h = [1,2,3,2,1];
[ny,y] = convolve(nx,x,nh,h);

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

% Plot
% extend axis to fit all plots
n = min([nx(1),nh(1),ny(1)]):max([nx(end),nh(end),ny(end)]);
% Put x[n],h[n],y[n] in parallel for plotting
xhy = zeros(length(n),3);
xhy(find(n==nx(1)):find(n==nx(end)),1) = x';
xhy(find(n==nh(1)):find(n==nh(end)),2) = h';
xhy(find(n==ny(1)):find(n==ny(end)),3) = y';
figure;
stem(n',xhy);
title('y[n] = x[n] \otimes h[n] Using convolve');
legend('x[n]','h[n]','y[n]');
% set plot limit for axis
axis([n(1),n(end),min(xhy(:)),max(xhy(:))]);

27
28
29
30
31
32
33
34

% Part (e)
% type `help conv' in the command window for detail
y mat = conv(x,h);
figure;
stem(y mat); % no time scale!
title('y[n] = x[n] \otimes h[n] Using conv');
legend('y[n]');

(e) (2 points) The code portion is listed in part (d). As expected, the numerical
values of y[n] are the same as using convolve. However, there is no explicit time
scale to plot against. In fact, conv assumes that both input start at n = 0. In
order to use this function on problems such as part (a), where non-zero values

Homework 3 Solutions

21

extend to negative n, we need to carefully handle the time indices to make it


consistent.

22

Homework 3 Solutions
8. (10 points) Plotting (MATLAB question)
In this problem, you will plot some of the Elementary signals
Include your source code and labeled graphs.
Scale the axes to display the graph clearly. Use the axis function in MATLAB
(2 points) Step Function:
(
f [n] =

1 if 2 n
0
otherwise

(2 points) Delta Function:


(
g[n] =

1 if n = 2
0
otherwise

(2 points) Ramp Function:


3
h(t) = t
4
(2 points) Rectangular Pulse:
(
1 if 2 n 4
g[n] =
0 otherwise

(2 points) Plot the following signal using the previous signals as a guide

2n
e[n] =

(10 points) Plotting (MATLAB question)


(2 points) Step Function:

if 0 n<2
2 n<5
if n<0
otherwise

Homework 3 Solutions

function [y] = step(n)


y = 0;
if n = -2
y = 1;
end

for n = -5 : 10
y = step(n);
stem(n,y)
hold on
end
axis([-5 10 -3 3])
ylabel(u[n])
xlabel(n)
title(Step Function)

(2 points) Delta Function:

23

24

Homework 3 Solutions

function [y] = delta(n)


y = 0;
if n ==2
y = 1;
end

n = -5:10;
f = size(n);
for i = 1:length(n)
f(i) = delta(n(i));
end
stem(n,f)
axis([-5 10 -3 3])
ylabel(delta[n])
xlabel(n)
title(Delta Function)

(2 points) Ramp Function:

Homework 3 Solutions

t = 0:.1:10;
y = 3/4 .* t;
plot(t,y)
axis([0 10 0 3])
ylabel(Ramp(t))
xlabel(t)
title(Ramp Function)

(2 points) Rectangular Pulse:

25

26

Homework 3 Solutions

(2 points) Plot the following signal using the previous signals

Homework 3 Solutions

27

Potrebbero piacerti anche