Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Objective(s)
a) To study linear convolution without using built in function and the function
conv in MATLAB
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.
Example(s)
An example(s) to make the students understand the concepts better as discussed in the
description above.
Theory:
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:
As an alternative, the group of points from the input signal can be chosen
symmetrically around the output point:
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:
But would not it be optimal to do the division during convolution? Here comes the idea by
rearranging the equation:
Task:
1. Write MATLAB code to apply moving averaging filter on a noisy signal using
moving averaging equation
Task 1:
close all
clear all
clc
x=[1 7 1 4 4 7 1];
M=3;
y=zeros(1,5);
for i=1:5
sum=0;
for j=0:2
sum=sum + x(i+j);
end
y(i)=sum;
end
Task 2:
close all
clear all
clc
x=[1 7 1 4 4 7 1];
k=[1 1 1];
w=conv(x,k,'valid');
subplot(3,1,1),stem(w/3),xlim([1 5]),ylim([0 5])
title ('Summation Method')
Task 3:
Audio_Signal = audioread('D:/Music/file_example.wav');
Audio_Signal = Audio_Signal (:,1);
w2=conv(Audio_Signal,k,'valid');
subplot(4,1,3),stem(w2/3)
title('Sound wave with filter')
Fs=44100;
audiowrite('D:\Music\fileLowPass(4).wav',w2/3,Fs);
Output: