ELEG 320L β Signals & Systems Laboratory /Dr. Jibran Khan Yousafzai Lab 4
1
LAB 4: CONVOLUTION
Background & Concepts
Convolution is denoted by:
π¦[π] = π₯[π] β β[π]
Your book has described the "flip and shift" method for performing convolution. First, we
set up two signals π₯[π] and β[π]:
Flip one of the signals, say β[π], to form β[βπ]:
ELEG 320L β Signals & Systems Laboratory /Dr. Jibran Khan Yousafzai Lab 4
2
Shift β[βπ] by n to form β[π β π]. For each value of π, form π¦[π] by multiplying and
summing all the element of the product ofπ₯[π]β[π β π], ββ < π < β. The figure
below shows an example of the calculation ofπ¦[1]. The top panel showsπ₯[π]. The
middle panel showsβ[1 β π]. The lower panel showsπ₯[π]π¦[1 β π]. Note that this is a
sequence on a π axis. The sum of the lower sequence over all k gives π¦[1] = 2.
We repeat this shifting, multiplication and summing for all values of π to get the
complete sequence π¦[π]:
ELEG 320L β Signals & Systems Laboratory /Dr. Jibran Khan Yousafzai Lab 4
3
The conv Command
conv(x,h) performs a 1-D convolution of vectors π₯ and β. The resulting vector π¦
has length length(π¦) = length(π₯) + length(β) β 1. Imagine vector π₯ as being
stationary and the flipped version of β is slid from left to right. Note that conv(x,h) =
conv(h,x). An example of the convolution of two signals and plotting the result is
below:
>> x = [0.5 0.5 0.5]; %define input signal x[n]
>> h = [3.0 2.0 1.0]; %unit-pulse response h[n]
>> y = conv(x,h); %compute output y[n] via convolution
>> n = 0:(length(y)-1); %for plotting y[n]
>> stem(n,y) % plot y[n]
>> grid;
>> xlabel('n');
>> ylabel('y[n]');
>> title('Output of System via Convolution');
ELEG 320L β Signals & Systems Laboratory /Dr. Jibran Khan Yousafzai Lab 4
4
Deconvolution
The command [q,r] = deconv(v,u), deconvolves vector u out of vector v, using long
division. The quotient is returned in vector q and the remainder in vector r such that
v = conv(u,q)+r. If u and v are vectors of polynomial coefficients, convolving them is
equivalent to multiplying the two polynomials, and deconvolution is polynomial
division. The result of dividing v by u is quotient q and remainder r. An examples is
below:
If
>> u = [1 2 3 4];
>> v = [10 20 30];
The convolution is:
>> c = conv(u,v)
c =
10 40 100 160 170 120
Use deconvolution to recover v.
>> [q,r] = deconv(c,u)
q =
10 20 30
r =
0 0 0 0 0 0
This gives a quotient equal to v and a zero remainder.
Structures
Structures in Matlab are just like structures in C. They are basically containers that
allow one to group together more than one type of data under the umbrella of one
variable name. As we mentioned previously, Matlab always assumes that the index
of the first element of an array is 1. So, when we just say:
>> x = [1 2 3 4 5];
ELEG 320L β Signals & Systems Laboratory /Dr. Jibran Khan Yousafzai Lab 4
5
This means that π₯[1] = 1, π₯[2] = 2, and so on. But, what if we want to express a
sequence π₯[β1] = 1, π₯[0] = 2, . ..? We obviously need to provide the user with some
additional information in addition to the array data, namely an offset. An offset of -1
tells the user that "we want you to interpret the first point in the Matlab array as
corresponding to π₯[β1]. We can use structures for this purpose. The form of a
structure is variable Name.field. For example:
>> x.data = [1 2 3 4 5];
>> x.offset = -1;
>> x
x =
data: [1 2 3 4 5]
offset: -1
We have declared a variable x, with two fields. The data field contains an array; the
offset field contains another number. Structures of this type can be useful for us in
expressing sequences in Matlab.
ELEG 320L β Signals & Systems Laboratory /Dr. Jibran Khan Yousafzai Lab 4
6
EXERCISES
Exercise 1:
Let
π[π] = π’[π] β π’[π β 4]
π[π] = π. π’[π] β 2(π β 4). π’[π β 4] + (π β 8). π’[π β 8]
Make stem plots of the following convolutions using MATLAB.
1. π[π] β π[π]
2. π[π] β π[π] β π[π]
3. π[π] β π[π]
4. π[π] β πΏ[π]
5. π[π] β π[π]
Exercise 2:
Consider the interconnection of the LTI systems depicted in the following figure:
Generate the impulse response of the overall system when:
β1[π] = 2π {π’[π] β π’[π β 4]}, 0 β€ π β€ 4
β2[π] = πΏ[π] β 4πΏ[π β 4], 0 β€ π β€ 5
β3[π] = β4[π] = πΏ[π β 5], 0 β€ π β€ 6
Exercise 3:
Using structures & conv command, find out the convolution of two sequences with
arbitrary starting points.