Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search


Polynomial Multiplication in Matlab

The matlab function conv (convolution) can be used to perform polynomial multiplication. For example:

B1 = [1 1];   % 1st row of Pascal's triangle
B2 = [1 2 1]; % 2nd row of Pascal's triangle
B3 = conv(B1,B2) % 3rd row
% B3 = 1  3  3  1
B4 = conv(B1,B3) % 4th row
% B4 = 1  4  6  4  1
% ...
The matlab conv(B1,B2) is identical to filter(B1,1,B2), except that conv returns the complete convolution of its two input vectors, while filter truncates the result to the length of the ``input signal'' B2.7.11 Thus, if B2 is zero-padded with length(B1)-1 zeros, it will return the complete convolution:
B1 = [1 2 3]; 
B2 = [4 5 6 7];
conv(B1,B2)
% ans = 4  13  28  34  32  21
filter(B1,1,B2)
% ans = 4  13  28  34
filter(B1,1,[B2,zeros(1,length(B1)-1)])
% ans = 4  13  28  34  32  21


Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]  [Comment on this page via email]

``Introduction to Digital Filters with Audio Applications'', by Julius O. Smith III, (September 2007 Edition)
Copyright © 2023-09-17 by Julius O. Smith III
Center for Computer Research in Music and Acoustics (CCRMA),   Stanford University
CCRMA