Lab 4 Discrete Convolution
Lab 4 Discrete Convolution
OBJECTIVES:
INTRODUCTION
x[n] y[n]
h[n]
Fig.4-1
The output y[n] will be the convolution of input x[n] and impulse response of the system will be
h[n].
TYPES OF CONVOLUTION
1. CONTINUOUS TIME
In continuous time convolution we take input, impulse response and the output in continuous
time. The output then is represented by the convolution integral given by:
∞ ∞ (4-1)
y(t) = x(t) ∗ h(t) = ∫−∞ x(τ)h(t − τ)dτ=∫−∞ h(τ)x(t − τ)dτ
Lab :4 Discrete Convolution
2. DISCRETE TIME
In discrete time convolution we take input, impulse response and the output in discrete time.
The output then is represented by the convolution sum given by:
Convolution is a step-by-step procedure. Basic points to carry out the convolution are bulleted
below:
EXAMPLE OF CONVOLUTION
Fig.4-2
Fig.4-3
And finally the output of the convolution of x[n] and y[n] is given by:
Lab :4 Discrete Convolution
Fig.4-4
Lab :4 Discrete Convolution
LAB TASK
By reading out the pre lab document most of us would have an idea about convolution. But that
was how we can perform convolution mathematically. In this lab handout we will explain how
convolution is done in MATLAB. By following the explained step by step procedure, we will
learn convolution using MATLAB.
MATLAB provides a built in function named conv(x,h) that computes the convolution of two
signals. Let us take on an example to explore this function.
EXAMPLE
>> x = [3,11,7,0,-1,4,2];
>> h = [2,3,0,-5,2,1];
>> y = conv(x,h)
y=
6 31 47 6 -51 -5 41 18 -22 -3 8 2
This convolution functions proves to be very useful but it misses one of the most important
things of convolution which is discussed below.
The conv function assumes that the two sequences begin at n = 0. Moreover, this function
neither provides nor accepts any timing information if the sequences have arbitrary starting
points. What is required is the beginning and end point of y[n]. Given finite duration x[n] and
h[n], it is easy to determine these points. Let
And
be the two finite duration sequences, then starting and end points of y[n] can be written as
Now we can define our own function in MATLAB that is slightly modified from the built in conv
function. Our modified function will use the conv function as underlying function but it will
perform convolution of arbitrary support sequences. How to define our own function?
First go to File and then click New and then M-File. Write the following code in the newly
opened editor file.
ny = [nyb : nye];
y = conv(x,h);
end
Lab :4 Discrete Convolution
This is our own defined function named myconv. Now we can use this function just as any other
function in MATLAB.
Now we will use this function for the convolution of signals having arbitrary starting and ending
points. Consider the signals in previous example
>> x = [3,11,7,0,-1,4,2];
>>nx = [-3:3];
>> h = [2,3,0,-5,2,1];
>>nh = [-1:4];
y=
6 31 47 6 -51 -5 41 18 -22 -3 8 2
ny =
-4 -3 -2 -1 0 1 2 3 4 5 6 7
Now this function also shows the starting and ending points of y[n] and values are
corresponding indices. We can plot this y[n] by the commands:
>> stem(ny,y);
>> xlabel('n');
>>ylabel('y[n]');
>> title('Convolution');
Fig.4-5
TASK4:
Both input and impulse response is taken to be the same for the sake of simplicity. We define
output as the convolution of input and impulse response.
x[n] = 1, 0 ≤ n ≤ 4
0, otherwise
h[n] = 0.5n, 0 ≤ n ≤ 6
0, otherwise
LAB ASSIGNMENTS
P.1
When the convolution of a signal is performed with itself, it is called correlation which is a very
important concept in communications. This task is related to this concept. You have to convolve
the signal with itself. The signal is given by:
x[n] = 1, -2≤n≤0
-1, 0<n≤2
Observations/Comments/Explanation of Results:
Questions:
1. What is convolution?
2. Explain types of convolution.
3. What are different steps to carry out convolution?
4. How will you find convolution in MATLAB?
5. What is the difference between plot and stem?
6. How will you apply grid on graphs?
7. How will you write x[n] in MATLAB?
x[n] = 1, 0 ≤ n ≤ 4
0, otherwise