Elce203l Lab05
Elce203l Lab05
Lab Manual
1
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Objective:
Important Notes:
1. You MUST Study this manual before joining the LAB session.
2. The completed lab Tasks & Report MUST be submitted by midnight after the Lab
Session. (Link will be provided on Moodle)
3. Please write your own interpretation in your own words.
Good Luck!!
_______________________________________________________________________________
The convolution between two discrete time signals is computed by using the MATLAB
command conv.
In MATLAB, the command conv allows the direct computation of the convolution between two
signals. In order to illustrate the conv command. There are three rules that have to be applied for
successful computation of the convolution between two continuous-time signals.
2
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
First rule: Two signals (input and impulse response) should be defined in the same time
interval. Hence, both signals are defined in the time interval a n b .
Second rule: When a signal consists of multiple parts, the time intervals in which each
part is defined must not overlap. For example,
1 n 0 n 1
h[ n] (5.2)
0 1 n 2
Having defined the input and impulse response signals, the response of the system can be
computed by convoluting the two signals. The convolution is implemented by the command
y=conv(x,h). The response of the system is now computed and the only thing left to do is to plot
it. However, the number of elements of the output vector y is not equal to the number of elements
of vectors x or h .
The precise relationship is length( y )=length( x )+length( h )-1. To overcome this, the third rule
must be applied.
Third rule: The output of the system is plotted in the double time interval of the one in
which the output and impulse response signals are defined.
In this section, the impulse response of a discrete time system is discussed in detail. More
specifically, it is established that if the unit impulse sequence [n] is the input to a system, the
output of the system is the impulse response h[ n] of the system.
Example:
1 n 0
x[n] [n] (5.3)
0 n 0
The response of the system is computed by convoluting the impulse response h[ n] with the input
signal [n] . Recall that [n] must be defined in the same time interval to h[ n] ; that is, 0 n 3 .
For illustration purposes both signals are plotted.
3
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
The number of elements of the output vector y[n] compared to the number of elements of the
input and impulse response vectors. The exact relationship is length( y )=length( x )+length( h )-1.
Therefore the output of the system is plotted in the double time interval from input and impulse
response signals.
The output and impulse response signals are the same; thus the identity property
h[n]* [n] h[n] clearly stands. The system under consideration is a linear shift invariant
system. If at a linear and shift invariant system, with impulse response h[ n] , the input signal
[n k ] , i.e., a shifted unit impulse sequence is applied, then the response of the system is also
shifted by k units.
4
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
As expected, the response y[n] of the system to the input signal [n 1] is h[n 1] . More
generally, the response of a linear shift invariant system to a shifted unit impulse sequence
[n k ] shifted by k units version of impulse response, i.e., the output of the system is h[n k ] .
The process that has to be followed to analytically derive the convolution sum (equation 5.1) is
as follows. First, the input and impulse response signals are plotted in the k -axis. One of the two
signals is reversed about the amplitude axis and its reflection is shifted from to by
changing appropriately the value of n . The output of the system is computed from the
overlapping values of x[ n] and h[n k ] according to the convolution sum
y[n] x[n]* h[n] x[k ]h[n k ]
k
(5.4)
The convolution procedure for two discrete time signals is demonstrated by using the signals
x[n] [1 2], 0 n 1 and h[n] [2 1 1 1], 0 n 3 .
5
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Step 3: The signal h[n k ] is shifted from to by changing appropriately the value of n .
The output if the system is computed at each shift through equation 5.1, in which only the values
of overlapping parts of x[ n] and h[n k ] are considered. In discrete time case we will compute
the sum of x[ n] and h[n k ] . There are three stages, first there is zero overlap, next there is
overlap and finally there is no overlap.
6
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Obviously the two signals do not overlap. Thus the output is y[n] 0, n 1 .
In order to compute the output, the two signals are plotted for n 0,1,..., 4. The output is
computed through the convolution sum by taking into account only the overlapping samples.
For n 0,
Commands Results
stem(kx,x,'fill','linewidth',2),grid on
axis([-5.1 3.1 -0.1 2.1])
legend('x[k]')
n=0;
stem(-kh+n,h,'fill','linewidth',2),grid on
axis([-5.2 3.1 -0.1 2.1])
legend('h[n-k]=h[0-k]')
7
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
For n 0, the signals x[ k ] and h[n k ] h[0 k ] have one overlapping sample at k 0. The
output of the system for n 0 ; that is, y[0] (1)(2) , where 1 is the value of x[ k ] and 2 is the value
of h[n k ] at the overlapping sample. In order to understand better the output calculation,
notice that according to the definition of the convolution sum y[n] x[n]* h[n] x[k ]h[n k ] ,
k
the overlapping samples of x[ k ] and h[n k ] are multiplied. The sum is applied when more than
one samples overlap. This is the case for n 1 .
Commands Results
stem(kx,x,'fill','linewidth',2),grid on
axis([-5.1 3.1 -0.1 2.1])
legend('x[k]')
n=1;
stem(-kh+n,h,'fill','linewidth',2),grid on
axis([-5.2 3.1 -0.1 2.1])
legend('h[n-k]=h[0-k]')
For n 1 , the signals x[ k ] and h[n k ] h[1 k ] overlap with two samples, namely, at k 0 and
at k 1 . The output for n 1 , that is, y[n] y[1] is computed as y[1] (2)(2) (1)(1) , where 2 is
the value of x[ k ] and h[n k ] at k 1 , while 1 is the value of x[ k ] and h[n k ] at k 0 . Hence
y[1] 5 .
For n 2 , we have
Commands Results
stem(kx,x,'fill','linewidth',2),grid on
axis([-5.1 3.1 -0.1 2.1])
legend('x[k]')
8
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
n=2;
stem(-kh+n,h,'fill','linewidth',2),grid on
axis([-5.2 3.1 -0.1 2.1])
legend('h[n-k]=h[2-k]')
For n 2 , the signals x[ k ] and h[n k ] h[2 k ] overlap at two points, at k 0 and at k 1 . The
output for n 2 , that is, y[n] y[2] is computed as y[2] (2)(1) (1)(1) , where 2 is the value of
x[ k ] and 1 is the value of h[n k ] at k 1 , while 1 is the value of x[ k ] and h[n k ] at k 0 .
Hence y[2] 3.
For n 3 , we have
Commands Results
stem(kx,x,'fill','linewidth',2),grid on
axis([-5.1 3.1 -0.1 2.1])
legend('x[k]')
n=3;
stem(-kh+n,h,'fill','linewidth',2),grid on
axis([-5.2 3.1 -0.1 2.1])
legend('h[n-k]=h[3-k]')
The output for n 3 , i.e., y[n] y[3] is computed as y[3] (2)(1) (1)(1) 3.
For n 4 ,
Commands Results
stem(kx,x,'fill','linewidth',2),grid on
axis([-2.1 6.1 -0.1 2.1])
legend('x[k]')
9
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
n=4;
stem(-kh+n,h,'fill','linewidth',2),grid on
axis([-2.1 6.1 -0.1 2.1])
legend('h[n-k]=h[4-k]')
For n 4 , there is only one overlap at k 1 . Thus the output for n 4 is y[4] (2)(1) 2.
Third Stage: Zero Overlap. For n 5 , the input and impulse response signals do not
overlap, hence y[n] 0, n 5 .
For n 5 , we have
Commands Results
stem(kx,x,'fill','linewidth',2),grid on
axis([-2.1 6.1 -0.1 2.1])
legend('x[k]')
n=5;
stem(-kh+n,h,'fill','linewidth',2),grid on
axis([-2.1 6.1 -0.1 2.1])
legend('h[n-k]=h[5-k]')
10
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Combining the derived results we conclude that the response of the system with impulse
response h[n] [2 1 1 1], 0 n 3 to the input signal x[n] [1 2], 0 n 1 is
y[n] [2 5 3 3 2], 0 n 4 . The output signal is plotted in figure below.
Commands Results
n=0:4;
y=[2 5 3 3 2];
stem(n,y,'fill','linewidth',2),grid on
axis([-0.1 4.1 -0.1 5.1])
legend('y[n]')
There are two basic principles that should be considered while computing the convolution
between two discrete time signals x[ n] and h[ n] using conv command.
1. Suppose that the length of vector x is N and the length of vector of h is M . The outcome of
command y=conv(x,h) is a vector y of length M N 1 . In other words,
length( y )=length( x )+length( h )-1.
2. If non zeros values of x[ n] are in the interval [ax , bx ] and non-zero values of h[ n] are in the
interval [ah , bh ] , then the non-zero values of the output y[n] are in the interval
[ax ah , bx bh ] .
11
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
The response (or output) of a system to any input signal is computed by the convolution of the
input signal with the impulse response of the system.
Suppose that y (t ) denotes the output of the system, x(t ) is the input signal, and h(t ) is the impulse
response of the system. The mathematical expression of the convolution relationship is
In order to calculate the convolution between two signals, a specific (and not exactly trivial)
computational procedure has to be followed. The convolution computational procedure is
introduced through an example.
Example
In order to compute the convolution between x(t ) and h(t ) , the computational procedure is
implemented in the following steps.
12
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Step 1: Time impulse response signals are plotted in the -axis; that is, t is replaced with , or
in other words the signals
1 0 1 1 0 2
h( ) and x( )
0 elsewhere 0 elsewhere (5.9)
Step 2: The second step is known as reflection. One of the two signals is selected (in this
example h( ) is chosen, but x( ) could have been also selected) and its symmetric with respect
to the vertical axis, i.e., h( ) is plotted.
13
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Commands Results
plot(tx,x,-th,h,':*')
ylim([-0.1 1.1])
legend('x(\tau)','h(-\tau)')
grid
Step 3: The third step is shifting. The signal h( ) is shifted by t ; that is, the signal h(t ) is
plotted. Note that t is constant, as the variable of the defined signals is variable .
A very useful (for future computations) observation is the point in the -axis where the right end
of h(t ) is. The right end h(t ) for t 2 ; that is, the right end of h(2 ) is at the point
2 . In the previous graph, it has been observed that the right end of h( ) , that is, the right
end of h(0 ) is at 0 . Hence, we conclude that in general case the right end of h(t ) is the
point t . On the other hand, the left end of h(t ) is at t T , where T is the duration of
h(t ) . In this example we have T 1 .
Step 4: The fourth step is sliding step. The value of the output signal y (t ) at time t , that is, the
value of convolution between the input signal and impulse response signal at time t depends on
overlap between x( ) and h(t ) at time t . In order to compute the convolution for all t , we have
14
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
to slide the signal h(t ) from to and to derive the kind (or stage) of overlap in
reference to the value of t . Note that x(t ) remains still.
15
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
16
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Step 5: Specification of limits and calculation of the convolution integral. Having derived the
time intervals for various stages of overlap, the convolution integral is computed separately for
each stage. Before computing the integrals the integration limits have to be specified. Recall that
the right end of h(t ) is at point t , while the left end of h(t ) is at point t T t 1 .
1. For t 0 , the two signals do not overlap (zero-overlap stage). Thus the response of the
system is y (t ) 0 .
2. For 0 t 1 , the two signals start to overlap (entry stage-partial overlap). The limits of
the integral are the limits that specified the shadowed area.
The input signal x( ) is given by x( ) 1 , while the impulse response signal h(t ) is
given by h(t ) 1 (t ) 1 t . The expression of h(t ) is derived by substituting
t with t in h(t ) . Thus the integral that has to be calculated is
t t
y (t ) 0 1(1t )d 0 (1t )d (5.10)
3. For 1 t 2 , the two signals overlap completely (complete overlap stage). The only
difference to the previous calculation is the integral limits. In this case, the output is
given by
t
y (t ) t 1 (1t )d (5.11)
4. For 2 t 3 , the two signals overlap partially (exit stage). Thus, the output is given by
2
y (t ) t 1 (1t )d (5.12)
17
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
y (t ) (3 t ) 2 2, 2 t 3.
Combining all the derived results, we conclude that the response of the system with impulse
response h(t ) 1 t , 0 t 1to the input signal x(t ) 1, 0 t 2 is
t t2 2 0 t 1
12 1 t 2
y (t ) (5.13)
(3 t ) 2
2
2t 3
0 t 0 and t 3
Finally, the output y (t ) is plotted in MATLAB according to the technique of plotting multipart
function.
Commands Results
t1=0:0.1:1;
t2=1:0.1:2;
t3=2:0.1:3;
y1=t1-(t1.^2)/2;
y2=0.5*ones(size(t2));
y3=0.5*((3-t3).^2);
plot(t1,y1,t2,y2,'.',t3,y3,':'),grid on
ylim([0 0.6])
title('Output Signal y(t)')
The computational process followed in the previous subsection is the analytical way of deriving
the convolution between two signals. In MATLAB, the command conv allows the direct
computation of the convolution between two signals. In order to illustrate the conv command we
consider the previously used example, namely the impulse response signal is given by
h(t ) 1 t , 0 t 1 and an input signal given by x(t ) 1, 0 t 2 . There are four rules that have
to be applied for successful computation of the convolution between two continuous-time
signals.
First rule: Two signals (input and impulse response) should be defined in the same time
interval. Hence both the signals are defined in the time interval a t b , where t a is
the first time instance that at least one of the signals x(t ) or h(t ) is not zero and t b is the
last time instance that at least one of the two signals is not zero. In our example, the time
18
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
interval is 0 t 2 . Thus the input signal x(t ) 1, 0 t 2 and the impulse response
signal is expressed as
1 t 0 t 1
h(t ) (5.14)
0 0t 2
Second rule: When a signal consists of multiple parts, the time intervals in which each
part is defined must not overlap. Therefore, the impulse response signal is defined as
1 t 0 t 1
h(t ) (5.15)
0 1 t 2
Note that the equality at t 1 is placed only in the upper part.
Commands Comments
step=0.01; The time step has to be quite small in order to
approximate accurately the continuous time signal.
t=0:step:2; The input signal x(t ) 1, 0 t 2 is defined.
x=ones(size(t));
t1=0:step:1; The intervals of two parts of h(t ) are defined in
t2=1+step:step:2;
such a way that they do not overlap. More
specifically, vector t 2 is defined from the instance
1+step, i.e., is defined from the time instance 1.01
(second rule). Also notice that the time step is used
at the definition of the two signals must be same.
h1=1-t1; The impulse response h(t ) is defined in the wider
h2=zeros(size(t2));
time interval, namely, in the same interval where
h=[h1 h2];
the input x(t ) is defined (first rule).
Having defined the input and impulse response signals the response of the system can be
computed by convoluting the two signals. The convolution is implemented by the command
y=conv(x,h). However, there is still one detail that needs to be addressed and is described at the
next rule.
Third rule: The output of the conv command has to be multiplied with time step used in
the definition of the input and impulse response signals, in order to correctly compute the
output of the system. The rule emerges from the fact that the convolution integral is
approximated by sum in MATLAB.
Commands Comments
y=conv(x,h)*step; The response y (t ) of the system is computed by
convoluting the input signal x(t ) with the impulse
response signal h(t ) and multiplying the result
with the time step (third rule).
19
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
The response of the system is now computed and the only thing left to do is to plot it. However,
the number of elements of the output vector y is not equal to the number of elements of vectors x
or h .
Fourth rule: The output of the system is plotted in the double time interval of the one in
which the output and impulse response signals are defined.
The output signal that was obtained through the MATLAB implementation (by using the
command conv) is the same as the one derived with the analytical approach in Section 5.2.2. In
this point the necessity for applying the fourth rule must be already clear. In case if first and
second rule was not followed it would not be possible to apply the fourth rule hardening the
proper plotting of the output of the system.
5.2.4 Deconvolution:
20
ELCE 203L: Signals & Systems Laboratory – Lab 05: Convolution (Discrete and Continuous)
Suppose that the impulse response of the system h(t ) and output of the system is y (t ) are
available and we want to compute the input signal x(t ) that was applied to the system in order to
generate the output y (t ) . The process called deconvolution and is implemented in MATLAB by
using the command deconv. The syntax is x=deconv(y,h), where x is the input vector, h is the
impulse response vector, and y is the system response vector.
The deconvolution process is also useful for determining the impulse response of a system if the
input and output signals are known. In this case the command is h=deconv(y,x).
Remark
The commutativity property is not valid for deconv command; hence, the output signal must be
the first input argument of the command deconv.
Example:
We will use the same signals used in the previous example. Therefore, the problem is to compute
the impulse response h(t ) of a system when the response of the system to the input
x(t ) 1, 0 t 2 is the signal y (t ) , which is depicted in the previous figure.
The signals x(t ) and y (t ) and the time t are already defined in the previous example, so we can
directly use them to compute the impulse response h(t ) .
__________________________
21