]> Creatis software - CreaPhase.git/blob - octave_packages/m/signal/sinc.m
update packages
[CreaPhase.git] / octave_packages / m / signal / sinc.m
1 ## Copyright (C) 1994-2012 John W. Eaton
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} sinc (@var{x})
21 ## Return
22 ## @tex
23 ## $ \sin (\pi x)/(\pi x)$.
24 ## @end tex
25 ## @ifnottex
26 ##  sin(pi*x)/(pi*x).
27 ## @end ifnottex
28 ## @end deftypefn
29
30 ## Author: jwe ???
31
32 function result = sinc (x)
33
34   if (nargin != 1)
35     print_usage ();
36   endif
37
38   result = ones (size (x));
39
40   i = (x != 0);
41
42   if (any (i(:)))
43     t = pi * x(i);
44     result(i) = sin (t) ./ t;
45   endif
46
47 endfunction
48
49
50 %!assert (sinc (0), 1);
51 %!assert (sinc (1), 0,1e-6);
52 %!assert (sinc (1/2), 2/pi, 1e-6)
53
54 %!error sinc()