1########################################################################
2##
3## Copyright (C) 1995-2021 The Octave Project Developers
4##
5## See the file COPYRIGHT.md in the top-level directory of this
6## distribution or <https://octave.org/copyright/>.
7##
8## This file is part of Octave.
9##
10## Octave is free software: you can redistribute it and/or modify it
11## under the terms of the GNU General Public License as published by
12## the Free Software Foundation, either version 3 of the License, or
13## (at your option) any later version.
14##
15## Octave is distributed in the hope that it will be useful, but
16## WITHOUT ANY WARRANTY; without even the implied warranty of
17## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18## GNU General Public License for more details.
19##
20## You should have received a copy of the GNU General Public License
21## along with Octave; see the file COPYING.  If not, see
22## <https://www.gnu.org/licenses/>.
23##
24########################################################################
25
26## -*- texinfo -*-
27## @deftypefn {} {} sinewave (@var{m}, @var{n}, @var{d})
28## Return an @var{m}-element vector with @var{i}-th element given by
29## @code{sin (2 * pi * (@var{i}+@var{d}-1) / @var{n})}.
30##
31## The default value for @var{d} is 0 and the default value for @var{n} is
32## @var{m}.
33## @seealso{sinetone}
34## @end deftypefn
35
36function x = sinewave (m, n, d)
37
38  if (nargin > 0 && nargin < 4)
39    if (nargin < 3)
40      d = 0;
41    endif
42    if (nargin < 2)
43      n = m;
44    endif
45    x = sin (((1 : m) + d - 1) * 2 * pi / n);
46  else
47    print_usage ();
48  endif
49
50endfunction
51
52
53%!assert (sinewave (1), 0)
54%!assert (sinewave (1, 4, 1), 1)
55%!assert (sinewave (1, 12, 1), 1/2, 1e-6)
56%!assert (sinewave (1, 12, 2), sqrt (3)/2, 1e-6)
57%!assert (sinewave (1, 20, 1), (sqrt (5)-1)/4, 1e-6)
58%!assert (sinewave (1), sinewave (1, 1,0))
59%!assert (sinewave (3, 4), sinewave (3, 4, 0))
60
61%!error sinewave ()
62