home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / r / rlab / CTB / conv < prev    next >
Encoding:
Text File  |  1995-11-15  |  625 b   |  29 lines

  1. //---------------------------------------------------------------------
  2. //
  3. // conv
  4. //
  5. // Syntax: c=conv(a,b)
  6. //
  7. // This routine convolves the vectors a and b into c. It is used for
  8. // polynomial multiplication (algebraically they are the same
  9. // operation).
  10. //
  11. // Note: Currently no error checking.
  12. //
  13. // Written by: Ian Searle
  14. //---------------------------------------------------------------------
  15.  
  16. conv = function( x , y )
  17. {
  18.   local( X , Y , n, tmp );
  19.  
  20.   n = x.n + y.n - 1;
  21.   X = fft( x, n );
  22.   Y = fft( y, n );
  23.  
  24.   tmp = ifft( X .* Y );
  25.   if( type(x) == "real" && type(y) == "real") { tmp = real(tmp); }
  26.  
  27.   return tmp;
  28. };
  29.