view scripts/signal/sinc.m @ 1267:69501f98669d

[project @ 1995-04-20 19:10:05 by jwe] Initial revision
author jwe
date Thu, 20 Apr 1995 19:10:05 +0000
parents 3470f1e25a79
children 5cffc4b8de57
line wrap: on
line source

function result = sinc (x)

# usage: sinc(x)
#
#        Returns sin(pi*x)/(pi*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.

  [nr, nc] = size(x);

  nels = nr*nc;

  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));
  endif

  result = reshape(result,nr,nc);

endfunction