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

  1. function y = filter2(b,x,shape)
  2. %FILTER2 Two-dimensional filtering.
  3. %
  4. %    Y = FILTER2(B,X) filters the data in X with the 2-D FIR
  5. %    filter in the matrix B.  The result, Y, is computed 
  6. %    using 2-D convolution and is the same size as X.
  7. %
  8. %    Y = FILTER2(B,X,'shape') returns Y computed via 2-D
  9. %    convolution with size specified by 'shape':
  10. %      'same'  - (default) returns the central part of the 
  11. %                convolution that is the same size as X.
  12. %      'valid' - returns only those parts of the convolution
  13. %                that are computed without the zero-padded
  14. %                edges, size(Y) < size(X).
  15. %      'full'  - returns the full 2-D convolution, 
  16. %                size(Y) > size(X).
  17. %
  18. %    See also CONV2.
  19.  
  20. %    Clay M. Thompson 9-17-91
  21. %    L. Shure 10-21-91, modified to use conv2 mex-file
  22. %    Copyright (c) 1984-93 by The MathWorks, Inc.
  23.  
  24. error(nargchk(2,3,nargin));
  25. if nargin<3, shape = 'same'; end
  26.  
  27. code = [shape,' ']; code = code(1);
  28. if isempty(find(code=='svf')), error('Unknown shape parameter.'); end
  29.  
  30. [mx,nx] = size(x);
  31. stencil = rot90(b,2);
  32. [ms,ns] = size(stencil);
  33.  
  34. y = conv2(x,stencil,shape);
  35.