Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
99 views

Lab Manual # 04 Linear Convolution Objective: Description:: College of Electrical & Mechanical Engineering, NUST

This document describes linear convolution and moving average filtering. It provides an example to illustrate the steps of linear convolution, including reflecting, shifting and overlapping the input and impulse response signals to calculate the output. It also explains that moving average filtering can be performed using convolution by defining the kernel as [1/M 1/M ... 1/M] where M is the filter length. The lab tasks involve writing MATLAB functions to perform linear convolution and moving average filtering using both direct calculation and convolution functions.

Uploaded by

Ahsan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
99 views

Lab Manual # 04 Linear Convolution Objective: Description:: College of Electrical & Mechanical Engineering, NUST

This document describes linear convolution and moving average filtering. It provides an example to illustrate the steps of linear convolution, including reflecting, shifting and overlapping the input and impulse response signals to calculate the output. It also explains that moving average filtering can be performed using convolution by defining the kernel as [1/M 1/M ... 1/M] where M is the filter length. The lab tasks involve writing MATLAB functions to perform linear convolution and moving average filtering using both direct calculation and convolution functions.

Uploaded by

Ahsan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

College of Electrical & Mechanical Engineering, NUST

Department of Computer Engineering

Lab Manual # 04
Linear Convolution
Objective:
To study linear convolution with and without using built in function.
Description:
The MATLAB Signal Processing Toolbox is required.
This section will contain material to help students successfully conduct the experiment. It
may contain the list of experimental steps that the students will have to go through for
successful experimentation. It can guide students on common pitfalls and points to note.
Linear Convolution:
Convolution is an operation between the input signal to a system, and its impulse response,
resulting in the output signal.
In discrete time, convolution of two signals involves summing the product of the two signals,
where one of the signals is “flipped and shifted”. It doesn't matter which signal is flipped and
shifted. Have to take care to get limits of sum correct. Convolution Sum is given by:

Let’s try to understand the concept of convolution sum through an example.


Suppose we have a Linear Time Invariant (LTI) System having an impulse response h[n] and
an input signal x[n] is applied to the system. We will have a look at each step involved in the
convolution of these signals.
The input signal x[n] is given by:

Impulse response h[n] is given by:

Step I:-

Digital Signal Processing DE-40 (CE)


College of Electrical & Mechanical Engineering, NUST
Department of Computer Engineering

Graph x[n] and h[n] as function of k.

Step II:-
Determine h[n-k] with the smallest n that prevents any overlap between x[k] and h[n-k].
First we reflect h[k] about k=0 to obtain h[-k].

Note that x-axis has been extended on the left to include a few additional points. These will
be useful later.
Second we shift h[-k] by –n. This result in h[n-k] and is equivalent to shifting h[-k] towards
the left side by n. We begin with large and negative value of n such that there is no overlap
between the non-zero values of the two signals.

Step III A:-


Increase n until x[k] and h[n-k] overlaps. We choose the smallest value on n such that x[k]
and
h[n-k] start overlapping. In this case the overlap starts at n=-5. The output y[n] is zero for n<-
5.

Digital Signal Processing DE-40 (CE)


College of Electrical & Mechanical Engineering, NUST
Department of Computer Engineering

Step III B:-


Calculate output y[n] from the overlapping region. We multiply the overlapping values of
x[k] and h[n-k] and add the results. In this case there is only one overlap occurring at k=-2.
The product is therefore 8(1)=8.
The output y[n] is 8 for n=-5 and is shown in figure below.

Increment n by 1. Repeat Step 3B until h[n-k] slides past x[k].


Step IV:-
In step 4 we increment n by 1. This is equivalent to shifting h[n-k] toward the right-hand side
by 1.

Still h[n-k] is overlapping with x[n] we repeat step III B.


We multiply the overlapping values of x[k] and h[n-k] and add the results. In this case there
are 2 overlaps occurring at k=-2 and k=-1. The sum of product is therefore 4(1)+8(1)=12.
The output y[n] is 12 for n=-4 and is shown in the figure below.

Shift h[n-k] by 1.

Digital Signal Processing DE-40 (CE)


College of Electrical & Mechanical Engineering, NUST
Department of Computer Engineering

The sum of product is 2(1)+4(1)+8(1)=14. Output y[n] is 14 for n-3 and is shown in figure
below.

And so on….
Since h[n-k] do not overlap with x[n] then the convolution sum is now 0 for n>3.
Final Result

Moving Average:
Moving average is a simple operation used usually to suppress noise of a signal: As the name
implies, the moving average filter operates by averaging a number of points from the input
signal to produce each point in the output signal. In equation form, this is written:

Where x[ ] is the input signal, y[ ] is the output signal, and M is the number of points in the
average. For example, in a 5-point moving average filter, point 80 in the output signal is
given by:

Digital Signal Processing DE-40 (CE)


College of Electrical & Mechanical Engineering, NUST
Department of Computer Engineering

As an alternative, the group of points from the input signal can be chosen symmetrically
around the output point:

Moving average by convolution


As you may have recognized, calculating the simple moving average is similar to the
convolution: in both cases a window is slid along the signal and the elements in the window
are summarized. So, give it a try to do the same thing by using convolution. Use the
following parameters:

The desired output is:

As first approach, let us try what we get by convolving the x signal by the following k kernel:

>> x = [1 7 1 4 4 7 1];
>> k = [1 1 1];
>> y = conv(x, k, 'same')
y=
8 9 12 9 15 12 8

The output is exactly three times larger than the expected. It can be also seen, that the output
values are the summary of the three elements in the window. It is because during convolution
the window is slid along, all of the elements in it are multiplied by one and then summarized:

To get the desired values of y, the output shall be divided by 3:


>> x = [1 7 1 4 4 7 1];
>> k = [1 1 1];
>> y = conv(x, k, 'same');
>> y = y / 3
y=
2.6667 3.0000 4.0000 3.0000 5.0000 4.0000 2.6667

By a formula including the division:

Digital Signal Processing DE-40 (CE)


College of Electrical & Mechanical Engineering, NUST
Department of Computer Engineering

But would not it be optimal to do the division during convolution? Here comes the idea by
rearranging the equation:

So, we shall use the following k kernel:

In this way we will get the desired output.

LAB TASK # 01:


a) Write a MATLAB function which takes two signals x[n] and h[n] as parameters and
perform the convolution sum of the two signals.
b) Using MATLAB built-in function of convolution to perform the convolution sum of two
same signals and compare the results to the result of Lab Task # 01. The result of
convolution should be same. MATLAB function for convolution is conv.

LAB TASK # 02:


a) Write MATLAB code to apply moving averaging filter on a noisy signal using moving
averaging equation

b) Apply Moving Averaging on the same signal using convolution.

Q1 Q2
a b a b
4 1 4 1

Digital Signal Processing DE-40 (CE)

You might also like