In: Electrical Engineering
Topic: Introduction to Convolution
Software used : Matlab
Course : Signal and Systems Lab
1.
a) Make the flowchart or pseudo code for convolution.
b) Implement convolution in MATLAB.
Hint: Make a function using the format: function result = myconv (a,b)
Where a and b are input matrix and result is convolution answer.
c) Compare it with conv command.
2. Let input signal x be [1, 3, –2, 4, -1] and the system h be [-2, 3, 4, –3, 6]. Find the output of the system y using the conv command.
3. Now suppose we add another system j = [3, –1, 2, 4, 1] in series with the above system. Now find the overall response and output y of the above system using the conv command. Hint: The systems h and j should be convolved first and then the resultant should be convolved with x to get the overall response.
4. Again suppose now j is attached in parallel to h. Now find the impulse response y for the system.
5. Now suppose the two systems h and j are again in series and a third system k = [2, 3, 4, 5, 6] has also been attached with them in parallel. Find the impulse response of the overall system and hence the output y. Hint: You will have to make sure that the size of the system k be made equal to the resultant of the size of the system obtained by convolving the systems h and k that are attached in series.
Up until now we have supposed that all signals starting point is same say 0. Now suppose the system h starting point is –2, that of system j is 0 and that of system k is 3. Now handle this situation carefully and get the overall impulse response of the system and hence the output y. Also please draw stem plot of each of system including the input x, systems, h, j, k, the overall response and finally the output y.
6. Write a program without using conv command and for loop to convolve two arbitrary length signals. (Hint: Use toeplitz command)
1.
(a).
Pseudo-code for convolution:
(b).
MatLab Code:
function c = myconv(a,b)
m=length(a);
n=length(b);
P=a(1,:)*b(1);
for i= 2:m
P=[P;a(1,:).*b(i)];
end
c=zeros(1,n+m-1);
for i = 1:n
c=c+[zeros(1,i-1) P(i,:) zeros(1,m-i)] ;
end
disp('Manual Result')
c
disp('conv command result')
conv(a,b)
Testcase:
(2).
>> x=[1, 3, -2, 4, -1];
>>h=[-2, 3, 4, -3, 6];
>> myconv(x,h);
Output:
Manual Result
c =
-2 -3 17 -5 3 37 -28 27 -6
conv command result
ans =
-2 -3 17 -5 3 37 -28 27 -6
(3).
When another system is added in series the impulse responses are multiplied in the Laplace domain and convolved in the time domain to get overall impulse response.
Test case:
>> x=[1, 3, -2, 4,
-1];
>>h=[-2, 3, 4, -3, 6];
>> j = [3, -1, 2, 4,
1];
>> h1=conv(h,j);
>>conv(x,h1)
Output:
ans =
-6 -7 50 -46 34 163 -118 190 50 -15 68 3 -6
(4).
When two systems are attached parallel the impulse responses are added:
Test case:
>> x=[1, 3, -2, 4,
-1];
>>h=[-2, 3, 4, -3, 6];
>> j = [3, -1, 2, 4,
1];
>> h2=h+j;
>>conv(x,h2)
Output:
ans =
1 5 10 19 5 41 -16 27 -7