Code covered by the BSD License  

Highlights from
masconv

4.57143

4.6 | 7 ratings Rate this file 1 Download (last 30 days) File Size: 1.52 KB File ID: #11137

masconv

by Mahmood Sheikh

 

20 May 2006 (Updated 23 May 2006)

The most easily understood program of convolution

| Watch this File

File Information
Description

This program to perform convolution has been written keeping the ordinary polynomial multiplication in mind and in my opinion is the most easily understood program among the ones I have seen on the web or written by other fellow workers although it may not be the best program in its design. The user may get help upon usage by typing help masconv at the command prompt.

When the user gives the program two vectors (sequences) to be convolved, the program first initialize a temporary matrix of size having number of rows according to the length of the first vector and number of columns one less than the length of both the vectors (as it is required for the convolution sum to have this much length) using the zeroscammand. The program then make use of two for loops to replace the zero values in the temporary matrix at desirable places by simple multiplication of the members of the two vectors. Once the temporary matrix is completed, the program then use the sum command of Matlab to find the final convolution sum and displays the result.

The user can compare the results of this program with the built-in function conv. Any suggestions or criticisms are welcome.

MATLAB release MATLAB 6.5 (R13)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (7)
26 May 2006 Imran Zaka  
29 May 2006 Rashid Saleem

Excellent!

30 May 2006 Muhammad Saeed  
30 May 2006 John D'Errico

This code is purely for expository purposes, as conv will be preferred always. As a conv tutorial, this does show nicely the basic idea of how one might write a convolution, except one should not (in practice) generate the entire table first, and THEN do the sum. This will be an inefficient and unnecessary use of memory. I can forgive inefficiency for expository purposes, as long as the reader is made aware of the difference. As such, a few comments to that effect would possibly increase my rating.

It might also be of interest to show the reader a more
efficient version. In some quick tests, with length(a) = 1000 and length(b) = 100, the version below is 8x faster, but with comments it should be as understandable as the doubly looped version.

na = length(a);
nb = length(b);
b=b(:);
result = zeros(na+nb-1,1);
for m = 1:na
  result(m:(m+nb-1)) = result(m:(m+nb-1)) + a(m)*b;
end

09 Feb 2007 Ashar Ahmad  
15 Feb 2007 salman rashid

 This code is purely for expository purposes, as conv will be preferred always. As a conv tutorial, this does show nicely the basic idea of how one might write a convolution, except one should not (in practice) generate the entire table first, and THEN do the sum. This will be an inefficient and unnecessary use of memory. I can forgive inefficiency for expository purposes, as long as the reader is made aware of the difference. As such, a few comments to that effect would possibly increase my rating.

14 Jun 2007 sreenivas Puthiya Veettil  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
dsp Mahmood Sheikh 22 Oct 2008 08:26:21
convolution Mahmood Sheikh 22 Oct 2008 08:26:21
easy Mahmood Sheikh 22 Oct 2008 08:26:21
polynomial multiplication Mahmood Sheikh 22 Oct 2008 08:26:21
signal processing Mahmood Sheikh 22 Oct 2008 08:26:21

Contact us at files@mathworks.com