DSPRelated.com
Free Books

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.10 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 Section:
Polynomial Division in Matlab
Previous Section:
Example 2