view scripts/signal/sinc.m @ 559:4e826edfbc56

[project @ 1994-07-25 22:18:28 by jwe] Initial revision
author jwe
date Mon, 25 Jul 1994 22:19:05 +0000
parents
children 3470f1e25a79
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