MatLab Codes
MatLab Codes
1 t
Z
y(t) = x( ) d .
T tT
Part (a): Let x(t) = 1(t)1(t1). Find the average signal y(t) using the above integral. Let T = 1. Carefully plot(y(t).
Verify your result by computing the convolution of x(t) and the impulse response h(t) of the averager.
[Chaparro actually asks you to compute the convolution graphically. We will not do that.]
Part (b): To see the effect of T on the averager, consider the signal to be averaged to be x(t) = cos(2t/T0 )1(t). Select
the smallest possible value of T in the averager so that the steady -state response of the systems , y(t) as t , will be
zero.
Part (c): Use matlab to compute the output in part (b). Compute the output y(t) for 0 t 2 at intervals Ts = 0.001.
Approximate the convolution integral using the function conv and multiplying by Ts .
[My class notes have some further guidance on using matlabs conv function. See 2Systems.pdf slide 26.]
Rt
t < 0 or t > 2 0, 0,
t < 0 or t > 2
t R
Part (a): Set T = 1. Then y(t) = t1 1( ) 1( 1)d = 0
1d, 0 t < 1 = t, 0t<1
R 1
1d, 1 t 2 2 t, 1 t 2
t1
Signal y(t) vs t
1
0.9
0.8
0.7
0.6
Signal (units)
0.5
0.4
0.3
0.2
0.1
0
0 0.5 1 1.5 2 2.5 3
Time (secs)
which is the same as y(t) for T = 1. Draw pictures of these unit step functions as t changes, if necessary.
2
Part (b): Let 0 = T0 . For x(t) = cos(0 t)1(t), the output is
1 t
Z
y(t) = cos(0 )1( )d
T tT
0, R
t<0
t
= T1 0 cos(0 )d, 0t<T
1 Rt
T tT cos(0 )d, t T
The term cos(0 t 02T ) is bounded lower by 1 and upper by 1. So when the steady-state response equals zero, we
have sin( 02T ) = 0. Accordingly, the smallest possible value of 02T is (T and T0 positive); therefore T = T0 .
Part (c): Set T0 = so that T = T0 = . The output in Part (b) is plotted below.
0.8
0.6
0.4
0.2
Signal (units)
0.2
0.4
0.6
0.8
1
5 0 5 10
Time (secs)
Many of you may have the graph being zero beyond a certain time, and that is not correct because the signal remains
a cosine function throughout the real line. This is because the conv syntax in matlab is not really computing the
convolution in question. It only finds the product of two polynomials originated from the sequences we give it.
For example, we now want to convolute (a, b, c) and (d, e, f ). conv will compute the product of 2 polynomials, a + bx +
cx2 , and d + ex + f x2 . The result has (bf + ce)x3 and cf x4 . These coefficients are not there when we carry out the
convolution the way it is defined. So, the result by matlab is only trustworthy up to x2 . Likewise, if we are to convolute
(a, b, c, d) and (e, f, g, h), the result by conv is only correct for coefficients of x0 , x1 , x2 and x3 .
You need to read the documentation on the matlab conv command in order to understand what it does. You also need
to rationalize your solution with matlabs in order to see what differs. The example on page 26 of the class notes works
because of the zero signal values. Note that the matlab answer is compared to the computed answer.
clear all
close all
%Part (a)
t = 0:0.001:3;
y = zeros(size(t));
figure(1)
plot(t,y)
title(Signal y(t) vs t)
xlabel(Time (secs))
ylabel(Signal (units))
%Part (c)
clear all
t = -5:0.001:10;
tt = -10:0.001:20;
T0 = pi;%Set T_0 = pi
T = T0;
%h(t) = (1/T)*[1(t)-1(t-T)]
h = [];
for i=1:length(t)
if t(i)>=0&&t(i)<1
h(i)=1;
else h(i)=0;
end
end
figure(2)
plot(tt,hcx/1000)
title(Convolution of h(t) and x(t) for T = T_0)
axis([-5 10 -1 1])
xlabel(Time (secs))
ylabel(Signal (units))
[Chaparro Question 2.17] BIBO stability assumes that the input is always bounded, i.e. limited in amplitude. If that is not
the case, even a stable system can provide an unbounded output. Consider the analog averager above. [The last time, I
promise.]
Part (a): Suppose the input to the averager is a bounded signal x(t) (i.e. there is a finite value M such that |x(t)| < M ).
Find the vale of the bound on the output y(t) to determine whether the averager is BIBO stable or not.
Part (b): Let the input to the averager be x(t) = t1(t), that is a ramp signal. Compute the output y(t) and determine if it
is bounded or not. If y(t) is not bounded, does this mean that the averager is an unstable system? Explain.
R 1
R 1
Rt
Part (a): y(t) = h(t) x(t) =
h(t )x( )d = T
[1(t ) 1(t T )] x( )d = T tT
x( )d .
Rt Rt Rt
So then |y(t)| = | T1 tT
x( )d | = 1
T tT
|x( )|d < M
T tT
d = M . So the output is bounded by M .
Rt 0,2
t<0
1 t
Part (b): y(t) = T tT
1( )d = 2T , 0t<T
2tT
2 , tT
The system however is BIBO stable because the response to a bounded input is bounded as pointed out in Part (a).
Question 3 Convolution
[That is, it is a rectangle of unit width and unit height centered on t = 0 and zero elsewhere.]
His Question 6.5 asks you to graph the following functions g(t).
[Note: the original posting of this homework had a sign reversal in Part (d). I have altered this to conform to Roberts.
Please note which version you are using in your homework.]
A matlab function for the rectangular function needs be developed. matlab code (one of many ways) for the function:
function y = rect(x)
y = double(abs(x) <= 1/2);
end
1.2
1
1
0.8
Signal (units)
Signal (units)
0.8
0.6
0.6
0.4
0.4
0.2
0.2
0 0
4 3 2 1 0 1 2 3 4 2 1.5 1 0.5 0 0.5 1 1.5 2
Time (sec) Time (sec)
clear all
Function g(t), Part (c) Function g(t), Part (d)
1 1
0.8 0.8
Signal (units)
Signal (units)
0.6 0.6
0.4 0.4
0.2 0.2
0 0
1 0.5 0 0.5 1 1.5 2 2.5 3 10 8 6 4 2 0 2 4 6 8 10
Time (sec) Time (sec)
close all
t = -2:0.001:2;
tt = -4:0.001:4;
g_a = conv(rect(t),rect(t));
figure(1)
plot(tt,g_a/1000)
title(Function g(t), Part (a))
xlabel(Time (sec))
ylabel(Signal (units))
clear all
t = -2:0.001:2;
tt = -4:0.001:4;
g_b = conv(rect(t),rect(t/2));
figure(2)
plot(tt,g_b/1000)
axis([-2 2 0 1.2])
title(Function g(t), Part (b))
xlabel(Time (sec))
ylabel(Signal (units))
clear all
t = -5:0.001:5;
tt = -10:0.001:10;
g_c = conv(rect(t-1),rect(t/2));
figure(3)
plot(tt,g_c/1000)
axis([-1 3 0 1.2])
title(Function g(t), Part (c))
xlabel(Time (sec))
ylabel(Signal (units))
clear all
t = -10:0.001:10;
tt = -20:0.001:20;
g_d = conv(rect(t-5)+rect(t+5),rect(t-4)+rect(t+4));
figure(4)
plot(tt,g_d/1000)
axis([-11 11 0 1.2])
title(Function g(t), Part (d))
xlabel(Time (sec))
ylabel(Signal (units))
[Kamen & Heck Question 3.16] Ed Kamen and Bonnie Heck ask you (politely) for each of five pairs of continuous-time
signals x(t) and v(t) in the figure below to compute the convolution x(t) v(t) for all t 0 and to plot the resulting
signal. I am not so mean.
Figure 6: Kamen and Heck figure. [Please excuse the twisted scan.]
Your task is to write down the convolutions as specific integrals over specific values of t. That is, identify how the entire
time axis needs to be broken up into pieces in each of which the convolution is given by an integral of simple functions
(polynomials in t, constants, exponentials etc) or is clearly zero. You are not obliged to compute the integrals.
R
The convolution is x(t) v(t) =
x(t )v( )d
( (
0, t < 0 or t > 3 0, < t 3 or > t
Part (a): x(t) = , therefore x(t ) =
1, 0 t 3 1, t 3 t
Imagine x(t ) is moving from left to right with t, while v(t) stays still. Draw pictures indicating the overlap of the two
functions as x(t ) moves, if needed. We have the following result:
0, t < 0 or t > 4 0, t < 0 or t > 4
t 1 2d,
R
0 t < 1
2t, 0t<1
x(t) v(t) = R01 =
1 2d, 1t<3 2, 1t<3
R01
1 2d, 3 t 4 2(4 t), 3t4
t3
Once again you are not required to compute the integrals no matter how simple they look.
( (
0, t < 0 or t > 2 0, < t 2 or > t
Part (b): x(t) = , therefore x(t ) = .
2, 0 t 2 2, t 2 t
(
0, < 0 or > 2
And v( ) = .
+ 2, 0 2
0,
t < 0 or t > 4
R t
x(t) v(t) = 0
2( + 2)d, 0t<2
2
R
t2
2( + 2)d, 2t4
( (
0, t<0 0, >t
Part (c): x(t) = , therefore x(t ) = .
et , t0 e(t )
, t
0,
t<0
R t (t ) 2
x(t) v(t) = 0
e 2e d, 0t<2
2 (t ) 2
R
0
e 2e d, t2
( (
0, t<0 0, >t
Part (d): x(t) = , therefore x(t ) = t
.
t/2, t 0 2 , t
0,
t < 1 or t > 5
Rt t
x(t) v(t) = 1 2
1d, 1t<3
R 3 t
t2 2
1d, 3t5
( (
0, t < 1 or t > 3 0, > t + 1 or < t 3
Part (d): x(t) = , therefore x(t ) = .
2, 1 t 3 2, t3 t+1
0,
t<0
R t+1 2
x(t) v(t) = 1
2 4e d, 0 t 4
t+1
2 4e2 d, t > 4
R
t3