home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l460 / 2.ddi / DATAFUN.DI$ / CONV.M < prev    next >
Encoding:
Text File  |  1993-03-07  |  993 b   |  35 lines

  1. function c = conv(a, b)
  2. %CONV    Convolution and polynomial multiplication.
  3. %    C = CONV(A, B) convolves vectors A and B.  The resulting
  4. %    vector is length LENGTH(A)+LENGTH(B)-1.
  5. %    If A and B are vectors of polynomial coefficients, convolving
  6. %    them is equivalent to multiplying the two polynomials.
  7. %
  8. %    See also XCORR, DECONV, CONV2.
  9.  
  10. %    J.N. Little 4-21-85
  11. %    Revised 9-3-87 JNL
  12. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  13.  
  14. na = max(size(a));
  15. nb = max(size(b));
  16.  
  17. % Convolution, polynomial multiplication, and FIR digital
  18. % filtering are all the same operations.  Since FILTER
  19. % is a fast built-in primitive, we'll use it for CONV.
  20.  
  21. % CONV(A,B) is the same as CONV(B,A), but we can make it go
  22. % substantially faster if we swap arguments to make the first
  23. % argument to filter the shorter of the two.
  24. if na > nb
  25.     if nb > 1
  26.         a(na+nb-1) = 0;
  27.     end
  28.     c = filter(b, 1, a);
  29. else
  30.     if na > 1
  31.         b(na+nb-1) = 0;
  32.     end
  33.     c = filter(a, 1, b);
  34. end
  35.