Mercurial > hg > octave-nkf
diff scripts/signal/sinc.m @ 3486:9493fe321888
[project @ 2000-01-28 05:05:41 by jwe]
author | jwe |
---|---|
date | Fri, 28 Jan 2000 05:05:42 +0000 |
parents | 0748b03c3510 |
children | 15e923b54eff |
line wrap: on
line diff
--- a/scripts/signal/sinc.m +++ b/scripts/signal/sinc.m @@ -34,27 +34,13 @@ function result = sinc (x) - ## We either need to set the do_fortran_indexing variable to "true" - ## or use reshape to convert the input matrix to a vector, so that - ## we can use find to determine the elements of x that equal zero. - ## I prefer reshaping. + result = ones (size (x)); - [nr, nc] = size(x); - - nels = nr*nc; + i = (x != 0); - x = reshape(x,nels,1); - - ## Set result to all ones initially. - result = ones(nels,1); - - ## Find non-zero elements in the input matrix. - i = find(x); - - if (!isempty(i)) - result(i) = sin(pi*x(i))./(pi*x(i)); + if (any (i)) + t = pi * x(i); + result(i) = sin (t) ./ t; endif - result = reshape(result,nr,nc); - endfunction