Sei sulla pagina 1di 11

ENT 281

SIGNALS & SYSTEMS, ENT 281

Semestre I (2014/2015)

LAB. MODULE
EXPERIMENT 2
CONVOLUTION

LECTURER
PLV
TECHNICIAN

: Mr. Mohd Nor Fakhzan Mohd Kazim

: Mrs. Sharifah Nurul Husna Binti Syed Hanapi
: Mrs. Siti Khalijah Bt Hassan@Yusuf

Students Particular:
Name
Matric. No
Date
Signature

14

ENT 281

SIGNAL AND SYSTEMS

EXPERIMENT 2
CONVOLUTION
1.0

OBJECTIVES:
After completing this section you will be able to :

2.0

1.1

1.2

Compute the response of a system.

TOOLS
The MATLAB Signal Processing Toolbox.

3.0

INTRODUCTION
3.1

Convolution

The convolution sum describes the relationship between the input and output of
discrete-time system, and is easily evaluated to a compute as a sum of products of
numbers.
Conv evaluates the convolution of finite duration discrete time signals,
commands covered:
conv
deconv
To perform discrete time convolution, x[n]*h[n], define the vectors x and h with
elements in the sequences x[n] and h[n]. Then use the command
y = conv(x,h)
This command assumes that the first element in x and the first element in h
correspond to n = 0, so that the first element in the resulting output vector
corresponds to n = 0 . If this is not the case, then the output vector will be computed
correctly, but the index will have to be adjusted.
Example 3.1.1
>> x = [1 1 1 1 1];
>> h = [0 1 2 3];
>> y = conv(x,h)

15

ENT 281

Yields y = [0 1 3 6 6 6 5 3]. If x is indexed as described above, then y[0] = 0,

y[1] =

1, .... In general, total up the index of the first element in h and the index of the first
element in x, this is the index of the first element in y.
For example, if the first element in h corresponds to n = -2 and the first element in x
corresponds to n = -3, then the first element in y corresponds to n = -5.
Care must be taken when computing the convolution of infinite duration signals. If the
vector x has length q and the vector h has length r, then you must truncate the vector
y to have length min(q,r).
Command conv can also be used to multiply polynomials: suppose that the
coefficients of a(s) are given in the vector a and the coefficients of b(s) are given in
the vector b, then the coefficients of the polynomial a(s) b(s) can be found as the
elements of the vector defined by ab = conv(a,b).Command deconv is the inverse
procedure to the convolution. In this text, it is used as a means of dividing
polynomials. Given a(s) and b(s) with coefficients stored in a and b, then the
coefficients of c(s) = b(s)/a(s) are found by using the command c = deconv(b,a).
3.2

Transfer Function Representation

For a discrete-time transfer function, the coefficients are stored in descending powers
1
of z or ascending powers of z . For example,

then define the vectors as

num = [2 3 4];
den = [1 5 6];

3.3

Time Simulations

Commands Covered:
conv
dstep
dimpulse
filter
There are two methods to compute the response of a system described by the
following recursive relationship
16

ENT 281

SIGNAL AND SYSTEMS

Recursive relationship

The first method to compute the response uses convolution and is useful when the
initial conditions on y are zero. This method involves first finding the impulse
response of the system, h[n], and then convolving h[n] with x[n] as discussed in
Section 3.1. For example, consider the system described above with zero initial
conditions, that is, y[-1]=y[-2]=0. The impulse response for this system is

h[n] 5[(0.4) n (0.2) n ]u[n]. The commands to compute y[n] are

>> n = 0:10;

% times starts at n = 0 to n = 10

>> x = ones(1,11);

>> h = 5*(0.4).^n - 5*(0.2).^n;

% impulse response

>> y = conv(x,h)
>> y = y(1:length(n))
>> stem(n,h)
The vector y contains the values of y[n] for n = 0,1,...,10. Note that the vector was
truncated to length(n) because both x[n] and h[n] are infinite duration signals.
The second method of solving for the response requires that the transfer function of
the system be known. The commands dstep and dimpulse compute the unit step
response and the unit impulse response, respectively while the command filter
computes the response to initial conditions and to arbitrary inputs. The denominator
coefficients are stored as den = [a0 a1 a2 aN] and the numerator coefficients are
stored as num = [b0 b1 bM 0] where there are N-M zeros padded on the end of
the coefficients.
y[n] 0.6y[n-1] + 0.08y[n-2] = x[n-1]
where x[n] = u[n] and initial conditions y[-1] = y[-2] = 0
For example, consider the system given above with initial conditions
y[-1] = y[-2]= 0. To compute the step response for n=0 to n=10

Type the commands:

>> n = 0:10;
>> num = [0 1 0]; den = [1 -0.6 0.08];
>> y = dstep(num,den,length(n))
17

ENT 281

SIGNAL AND SYSTEMS

The response can then be plotted using the stem plot. To compute the impulse
response, simply replace dstep with dimpulse in the above commands.To compute
the response to an arbitrary input, store the input sequence in the vector x. The
command
y = filter(num,den,x);
is used to compute the system response. If the system has nonzero initial conditions,
the initial conditions can be stored in a vector v0. For a first order system where N =
M = 1, define

z [b x[1] b x[2] a y[1] a y[2]] [b x[1] a y[1]]

1
2
1
2
1
2
define i
To compute the response with nonzero initial conditions, type

y = filter(num,den,x,zi);
Zi=filtic(num,den,[initial condition]);
For example, consider the previous system with the initial conditions y[-1] = 2 and y[2] = 1 and input x[n] = u[n]. Type the following commands to compute y[n].
>> num = [0 1 0];
>> den = [1 -0.6 0.08];
>> n = 0:10;
>> x = ones(1,11);
>> Zi=filtic(num,den,[2,1])
>> y = filter(num,den,x,Zi)
Example 3.3.1
Consider the discrete-time LTI System model representing a two-path propagation
channel, the strength of the indirect path is a = , then,
y [n] = x [n] + ax [n - 1]
y [n] = x [n] + ()x [n - 1]
letting x [n] = [n], the impulse response is
1, n = 0
h [n] =

, n = 1
0, otherwise

2, n = 0
x [n] =

4, n = 1
-2, n = 1
0, otherwise

18

ENT 281

SIGNAL AND SYSTEMS

Solution 3.3.1
The first Nonzero value in the impulse response and input occur at time
n = kh = kx = 0. The last element of the impulse response and input occur at times n
= lh = 1 and n = lx = 2. Thus the convolution y starts at time n = k y = kx + kh = 0, end
at time n = ly = lx + lh = 3 and has length Ly = ly - ky + 1 = 4
(i) Convert the equation into differential equation form
h [n] = [n] + 1/2 [n-1]
x [n] = 2 [n] + 4 [n-1] - 2 [n-2]
(ii) We evaluate the convolution in MATLAB as follow
>> h = [ 1 , 0.5 ];
>> x = [ 2 , 4 , -2 ];
>> y = conv (x,h)
>> n = [0:length (y)-1];
>> stem (n,y)
>> xlabel(Time)
>> ylabel(Impulse Response)
y=
2

-1

Interpretation,
0,n<0
2,n=0
5 , n =1
y[n] =

0,n=2
-1 , n = 3
0,n4

Example 3.3.2
Determine the output of a system for impulse response given by

1
h [n] = ( 4 ) (u [n] - u [n - 4] )

_________________

(i)

19

ENT 281

SIGNAL AND SYSTEMS

and input
x [n] = u [n] - u [n-10]

_________________

(ii)

signal (i) & (ii) may be defined in MATLAB following this command:
>> h = 0.25*ones(1,4);
>> x = ones (1,10);
>> n = 0:12; y starts at time n = Ky = 0, ends at time n = Ly = 12
>> y = conv ( x, h);
>> n = [0:length(y)-1];
>> stem(n,y); xlabel(n); ylabel(y[n])
Problem 3.3.1
Evaluate the following discrete-time convolution sums using MATLAB.
y [n] = {u [n - 2] - u [n - 13] } * 2{u [n + 2] - u [n - 12] }
for = 0.9,
i.e, find the output of the system of input
x [n] = 2 {u [n + 2] - u [n -12] } and impulse response
h [n] = 0.9 {u [n - 2] - u [n -13] }.
3.4

STEP RESPONSE

The step response is the output of a system in response to a step input and is infinite
in duration, in general.
Example 3.4.1
Find the first 50 values of the step response of the first order recursive system with
impulse response.
h [n] = pn u [n],
assuming that | p | < 1

Solution 3.4.1
Try this command;
We may determine the 1st 50 values of the step response of the system
with p = - 0.9,
20

ENT 281

SIGNAL AND SYSTEMS

>> h = (-0.9).^[0:49];
>> u = ones (1,50);
>> y = conv (u,h);
>> stem ( [ 0:49] , y (1:50)); @

n = [ 0:length(y)-1]; stem (n,y)

Exercise 3.4.2
Evaluate the first 20 values of the step response for the LTI system represented by
the following impulse response.
h [n] =

3/4,

0n5

0,

otherwise

% declare variable for step function.

>> h = [ 1 1 1 1 1] *0.75

% 1st. element at n = 0.

>> y = conv(h,stepfn);
>> y = y (1:20);
>> n = [0:length(y)-1];
>> stem (n,y)
>> xlabel(Time), ylabel(Step response of h)
3.5

FREQUENCY RESPONSE OF LTI SYSTEMS FROM IMPULSE

RESPONSE

The Impulse Response of the system is the output signal of the system when the
input signal is an impulse function applied at time t = 0.

x(t ) (t t 0 )
Suppose the system is modeled by a convolution integral. Then the output to the

y i (t )
system is ;

h(t ) ( t

) d

h(t t 0 )

impulse input signal at time t 0.

The frequency response of a system is a continuous function of frequency. Let us
consider a LTI continuous-time system with impulse response h [n]. The system
output is:
y[n] = h[n] * v [n]

21

ENT 281

Suppose h [n] = 0 for n< Kh and n > Lh,

v [n] = ejn (u[n] - u[n-1v] ) finite duration sinusoidal input system.
Then,

y [n] = h [n] * v [n]

Lh

h[ K ]e

j ( n 1)

K kh

Lh n < Kh + Lv

= h [n] * ejn ,
Lh n < Kh + Lv
= H (ej ) ejn ,
Lh n < Kh + Lv
Hence, the system output in response to a finite-duration sinusoidal input
corresponds to the output in response to an infinite-duration sinusoidal input on the
interval Lh n < Kh + Lv. The magnitude and phase response of the system maybe
determined from y[n], Lh n < Kh + Lv , by no trigger that ,
y[n] = |H (ej )| ej(n + arg {H ( e

)})

Lh n < Kh + Lv

we take the magnitude and phase of y[n] to obtain

| y[n] | = |H (ej )| ,

Lh n < Kh + Lv

and
arg { y[n] } = - n = arg { H(ej) },

Lh n < Kh + Lv

Example 3.5.1
Consider the system with impulse response,
h2 [n] =

1
2

[n]

1
2

[n-1]

Find the frequency response of the system and plot 50 values of the steady-state

3
4 .

Solution 3.5.1
Here, Kh = 0

; Lh = 1, so, to obtain 50 values of the sinusoidal steady-state

response, we require Lv 51, the output signal are obtained by MATLAB commands :

22

ENT 281

>> omega1 = pi/4 ; omega2 = 3*pi/4;

>> Y = exp ( j * omega1*[0:50]);
>> X = exp ( j * omega2*[0:50]);
>> h = [0.5, -0.5];
>> y1 = conv (Y, h) ; y2 = conv (X, h) ;
>> subplot ( 2, 1, 1);
>> stem ( [ 0:51] , real (y1));
>> xlabel (Time) ;
ylabel (Amplitude);
>> title (Real (y1))
>> subplot ( 2, 1, 2);
>> stem ( [ 0:51] , imag (y1));
>> xlabel (Time) ;
ylabel (Amplitude);
>> title (Imag (y1))
The steady-state outputs are represented by the values at time indices 1 through 50.
(observe the graph).
We may now obtain the magnitude and phase responses from any elements of the
vectors y1 and y2, but not for the first one or the last one. Let us use the fifth element
and the commands are:
>> H1mag = abs (y1(5))
H1mag =
0.3287
>> H1phs = angle (y1(5)) omega1*5
H1phs =
- 5.8905
Try yourself for H2 mag and H2 phs.

Q 2.1 Use MATLAB to evaluate the first 20 values of the step response for the
LTI Systems represented by the following impulse responses.
(a) h [n] = (-1/2)nu [n],

23

ENT 281

(b) h [n] = (-1)n {u [n + 2] - u [n - 3]}

Q 2.2 Evaluate the convolution, y [n] = x [n]*h [n]
(a) x [n] = [n] - 2 [n - 1] + [n - 2]
h [n] = u [n] - u [n - 3]
Q 2.3 Compute the convolution sum y [n] = x [n] * h [n] of the following pairs of
sequences, set = - 0.9:
(a) x [n] = u [n] u [n-N],

h [n] = n u [-n]

h [n] = [n] - 1/2 [n-1]

0 < < 1, N = 5

Use MATLAB command conv to plot the first 20 values of the responses.
Q 2.4 Evaluate the frequency response at the frequency = /3 and 50 values of
the steady-state output in response to a complex sinusoidal input of frequency =
/3 for the moving-average system with impulse response
1
4
0n1
h [n] =
0 otherwise
translate to h[n] = [n] + [n-1]

24